Removed old C-api for Vector3

This commit is contained in:
Michaël Lemaire 2013-12-11 11:32:10 +01:00 committed by Michael Lemaire
parent 88517af86f
commit 879f88fd20
22 changed files with 170 additions and 229 deletions

View file

@ -228,9 +228,9 @@ Matrix4 Matrix4::newRotateTripleAxis(const Vector3 &x, const Vector3 &y, const V
Matrix4 Matrix4::newLookAt(const Vector3 &eye, const Vector3 &at, const Vector3 &up)
{
Vector3 z = v3Normalize(v3Sub(at, eye));
Vector3 x = v3Normalize(v3Cross(up, z));
Vector3 y = v3Cross(z, x);
Vector3 z = at.sub(eye).normalize();
Vector3 x = up.crossProduct(z).normalize();
Vector3 y = z.crossProduct(x);
Matrix4 result = Matrix4::newRotateTripleAxis(x, y, z);
result.d = eye.x;
result.h = eye.y;

View file

@ -88,63 +88,4 @@ BASICSSHARED_EXPORT extern const Vector3 VECTOR_WEST;
#endif
#endif
// Compat API
static inline Vector3 v3(double x, double y, double z)
{
return Vector3(x, y, z);
}
static inline void v3Save(PackStream* stream, Vector3* v)
{
v->save(stream);
}
static inline void v3Load(PackStream* stream, Vector3* v)
{
v->load(stream);
}
static inline Vector3 v3Translate(const Vector3 &v1, double x, double y, double z)
{
return v1.add(x, y, z);
}
static inline Vector3 v3Add(const Vector3 &v1, const Vector3 &v2)
{
return v1.add(v2);
}
static inline Vector3 v3Sub(const Vector3 &v1, const Vector3 &v2)
{
return v1.sub(v2);
}
static inline Vector3 v3Neg(const Vector3 &v)
{
return v.inverse();
}
static inline Vector3 v3Scale(const Vector3 &v, double scale)
{
return v.scale(scale);
}
static inline double v3Norm(const Vector3 &v)
{
return v.getNorm();
}
static inline Vector3 v3Normalize(const Vector3 &v)
{
return v.normalize();
}
static inline double v3Dot(const Vector3 &v1, const Vector3 &v2)
{
return v1.dotProduct(v2);
}
static inline Vector3 v3Cross(const Vector3 &v1, const Vector3 &v2)
{
return v1.crossProduct(v2);
}
static inline VectorSpherical v3ToSpherical(const Vector3 &v)
{
return v.toSpherical();
}
static inline Vector3 v3FromSpherical(const VectorSpherical &v)
{
return Vector3(v);
}
#endif // VECTOR3_H

View file

@ -222,8 +222,8 @@ bool CameraDefinition::isBoxInView(const Vector3 &center, double xsize, double y
{
BoundingBox box;
box.pushPoint(v3Add(center, v3(-xsize, -ysize, -zsize)));
box.pushPoint(v3Add(center, v3(xsize, ysize, zsize)));
box.pushPoint(center.add(Vector3(-xsize, -ysize, -zsize)));
box.pushPoint(center.add(Vector3(xsize, ysize, zsize)));
return isUnprojectedBoxInView(box);
}

View file

@ -20,7 +20,7 @@ MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material)
_light->direction.x = -0.5;
_light->direction.y = -0.5;
_light->direction.z = -0.5;
_light->direction = v3Normalize(_light->direction);
_light->direction = _light->direction.normalize();
_light->altered = 0;
_light->reflection = 1.0;
@ -66,7 +66,7 @@ Color MaterialPreviewRenderer::getColor2D(double x, double y, double)
point.z = fabs(acos(dist));
}
point = v3Normalize(point);
point = point.normalize();
color = getLightingManager()->applyFinalComponent(*_light, getCameraLocation(point), point, point, *_material);
if (dist > 0.95)
{

View file

@ -564,10 +564,10 @@ void WidgetHeightMap::updateVertexInfo()
{
Vector3 dx, dz;
dx = v3Sub((vertex + 1)->point, vertex->point);
dz = v3Sub((vertex + rx)->point, vertex->point);
dx = (vertex + 1)->point.sub(vertex->point);
dz = (vertex + rx)->point.sub(vertex->point);
vertex->normal = v3Cross(v3Normalize(dz), v3Normalize(dx));
vertex->normal = dz.normalize().crossProduct(dx.normalize());
}
}
}

View file

@ -139,7 +139,7 @@ Color ExplorerChunkSky::getTextureColor(double x, double y)
location.z = y;
break;
}
location = v3Normalize(location);
location = location.normalize();
if (location.y < 0.0)
{
location.y = 0.0;

View file

@ -111,7 +111,7 @@ void ExplorerChunkTerrain::onCameraEvent(CameraDefinition* camera)
askReset();
}
_distance_to_camera = v3Norm(v3Sub(getCenter(), camera_location));
_distance_to_camera = getCenter().sub(camera_location).getNorm();
_lock_data.unlock();
}

View file

@ -64,11 +64,11 @@ static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vecto
Vector3 e1, e2, h, s, q;
double a, f, u, v, t;
e1 = v3Sub(v1, v0);
e2 = v3Sub(v2, v0);
e1 = v1.sub(v0);
e2 = v2.sub(v0);
h = v3Cross(d, e2);
a = v3Dot(e1, h);
h = d.crossProduct(e2);
a = e1.dotProduct(h);
if (a > -0.00001 && a < 0.00001)
{
@ -76,27 +76,27 @@ static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vecto
}
f = 1.0 / a;
s = v3Sub(p, v0);
u = f * v3Dot(s, h);
s = p.sub(v0);
u = f * s.dotProduct(h);
if (u < 0.0 || u > 1.0)
{
return 0;
}
q = v3Cross(s, e1);
v = f * v3Dot(d, q);
q = s.crossProduct(e1);
v = f * d.dotProduct(q);
if (v < 0.0 || u + v > 1.0)
{
return 0;
}
t = f * v3Dot(e2, q);
t = f * e2.dotProduct(q);
if (t > 0.00001)
{
*hit = v3Add(p, v3Scale(d, t));
*hit = p.add(d.scale(t));
return 1;
}
else

View file

@ -580,8 +580,8 @@ static Color _inscatterS(double r, double mu, double muS, double nu, int first,
double dw = dtheta * dphi * sin(theta);
Vector3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), ctheta);
double nu1 = v3Dot(s, w);
double nu2 = v3Dot(v, w);
double nu1 = s.dotProduct(w);
double nu2 = v.dotProduct(w);
double pr2 = _phaseFunctionR(nu2);
double pm2 = _phaseFunctionM(nu2);
@ -590,7 +590,7 @@ static Color _inscatterS(double r, double mu, double muS, double nu, int first,
gnormal.x = dground * w.x / Rg;
gnormal.y = dground * w.y / Rg;
gnormal.z = (r + dground * w.z) / Rg;
Color girradiance = _irradiance(deltaE, Rg, v3Dot(gnormal, s));
Color girradiance = _irradiance(deltaE, Rg, gnormal.dotProduct(s));
Color raymie1; /* light arriving at x from direction w */
@ -695,7 +695,7 @@ void _irradianceNProg(Texture2D* destination, Texture4D* deltaSR, Texture4D* del
double theta = ((double)(itheta) + 0.5) * dtheta;
double dw = dtheta * dphi * sin(theta);
Vector3 w = vec3(cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta));
double nu = v3Dot(s, w);
double nu = s.dotProduct(w);
if (first)
{
/* first iteration is special because Rayleigh and Mie were stored separately,
@ -840,8 +840,8 @@ static inline Color _applyInscatter(Color inscatter, Color attmod, Color samp)
static Color _getInscatterColor(Vector3* _x, double* _t, Vector3 v, Vector3 s, double* _r, double* _mu, Vector3* attenuation)
{
Color result;
double r = v3Norm(*_x);
double mu = v3Dot(*_x, v) / r;
double r = _x->getNorm();
double mu = _x->dotProduct(v) / r;
double d = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rt * Rt);
attenuation->x = attenuation->y = attenuation->z = 0.0;
if (d > 0.0)
@ -860,18 +860,18 @@ static Color _getInscatterColor(Vector3* _x, double* _t, Vector3 v, Vector3 s, d
if (r <= Rt)
{
/* if ray intersects atmosphere */
double nu = v3Dot(v, s);
double muS = v3Dot(x, s) / r;
double nu = v.dotProduct(s);
double muS = x.dotProduct(s) / r;
double phaseR = _phaseFunctionR(nu);
double phaseM = _phaseFunctionM(nu);
Color inscatter = vec4max(_texture4D(_inscatterTexture, r, mu, muS, nu), 0.0);
if (t > 0.0)
{
Vector3 x0 = v3Add(x, v3Scale(v, t));
double r0 = v3Norm(x0);
double rMu0 = v3Dot(x0, v);
Vector3 x0 = x.add(v.scale(t));
double r0 = x0.getNorm();
double rMu0 = x0.dotProduct(v);
double mu0 = rMu0 / r0;
double muS0 = v3Dot(x0, s) / r0;
double muS0 = x0.dotProduct(s) / r0;
/* avoids imprecision problems in transmittance computations based on textures */
*attenuation = _analyticTransmittance(r, mu, t);
if (r0 > Rg + 0.001)
@ -935,7 +935,7 @@ static Color _sunColor(Vector3 v, Vector3 s, double r, double mu, double radius)
Color transmittance = r <= Rt ? _transmittanceWithShadow(r, mu) : COLOR_WHITE; /* T(x,xo) */
double d = _limit(r, mu);
radius *= (1.0 + 10.0 * d / Rt); /* Inflating due to lens effect near horizon */
double isun = step(cos(radius * M_PI / 180.0), v3Dot(v, s)) * ISun; /* Lsun */
double isun = step(cos(radius * M_PI / 180.0), v.dotProduct(s)) * ISun; /* Lsun */
transmittance.r *= isun;
transmittance.g *= isun;
transmittance.b *= isun;
@ -1163,11 +1163,11 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3
eye.y = 0.0;
}
Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0};
Vector3 v = v3Normalize(direction);
Vector3 s = v3Normalize(v3Sub(sun_position, x));
Vector3 v = direction.normalize();
Vector3 s = sun_position.sub(x).normalize();
double r = v3Norm(x);
double mu = v3Dot(x, v) / r;
double r = x.getNorm();
double mu = x.dotProduct(v) / r;
double t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rg * Rg);
AtmosphereResult result;
@ -1190,7 +1190,7 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3
AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 location, const Color &base)
{
Vector3 eye = parent->getCameraLocation(location);
Vector3 sun_position = v3Scale(parent->getAtmosphereRenderer()->getSunDirection(), SUN_DISTANCE);
Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE);
double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height;
eye.y += yoffset;
@ -1203,20 +1203,20 @@ AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 locatio
{
location.y = 0.0;
}
Vector3 direction = v3Scale(v3Sub(location, eye), WORLD_SCALING);
Vector3 direction = location.sub(eye).scale(WORLD_SCALING);
Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0};
Vector3 v = v3Normalize(direction);
Vector3 s = v3Normalize(v3Sub(sun_position, x));
Vector3 v = direction.normalize();
Vector3 s = sun_position.sub(x).normalize();
if (v.y == 0.0)
{
v.y = -0.000001;
}
double r = v3Norm(x);
double mu = v3Dot(x, v) / r;
double t = v3Norm(direction);
double r = x.getNorm();
double mu = x.dotProduct(v) / r;
double t = direction.getNorm();
AtmosphereResult result;
Vector3 attenuation;
@ -1249,13 +1249,13 @@ void AtmosphereModelBruneton::fillLightingStatus(LightStatus *status, const Vect
double r0 = Rg + altitude * WORLD_SCALING;
Vector3 up = {0.0, 1.0, 0.0};
Vector3 sun_position = v3Scale(parent->getAtmosphereRenderer()->getSunDirection(), SUN_DISTANCE);
Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE);
Vector3 x = {0.0, r0, 0.0};
Vector3 s = v3Normalize(v3Sub(sun_position, x));
Vector3 s = sun_position.sub(x).normalize();
muS = v3Dot(up, s);
muS = up.dotProduct(s);
sun.color = _transmittanceWithShadow(r0, muS);
sun.direction = v3Scale(s, -1.0);
sun.direction = s.scale(-1.0);
sun.reflection = ISun;
sun.altered = 1;

View file

@ -173,8 +173,8 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi
camera_location = parent->getCameraLocation(VECTOR_ZERO);
sun_direction = getSunDirection();
direction = v3Normalize(direction);
sun_position = v3Scale(sun_direction, SUN_DISTANCE_SCALED);
direction = direction.normalize();
sun_position = sun_direction.scale(SUN_DISTANCE_SCALED);
/* Get sun shape */
base = COLOR_BLACK;
@ -206,7 +206,7 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi
/* Get scattering */
AtmosphereResult result;
Vector3 location = v3Add(camera_location, v3Scale(direction, 6421.0));
Vector3 location = camera_location.add(direction.scale(6421.0));
switch (definition->model)
{
case AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON:

View file

@ -38,11 +38,11 @@ bool BaseCloudLayerRenderer::optimizeSearchLimits(BaseCloudsModel *model, Vector
}
else
{
diff = v3Sub(*end, *start);
*start = v3Add(*start, v3Scale(diff, (max_altitude - start->y) / diff.y));
diff = end->sub(*start);
*start = start->add(diff.scale((max_altitude - start->y) / diff.y));
if (end->y < min_altitude)
{
*end = v3Add(*end, v3Scale(diff, (min_altitude - end->y) / diff.y));
*end = end->add(diff.scale((min_altitude - end->y) / diff.y));
}
}
}
@ -54,24 +54,24 @@ bool BaseCloudLayerRenderer::optimizeSearchLimits(BaseCloudsModel *model, Vector
}
else
{
diff = v3Sub(*end, *start);
*start = v3Add(*start, v3Scale(diff, (min_altitude - start->y) / diff.y));
diff = end->sub(*start);
*start = start->add(diff.scale((min_altitude - start->y) / diff.y));
if (end->y >= max_altitude)
{
*end = v3Add(*end, v3Scale(diff, (max_altitude - end->y) / diff.y));
*end = end->add(diff.scale((max_altitude - end->y) / diff.y));
}
}
}
else /* start is inside layer */
{
diff = v3Sub(*end, *start);
diff = end->sub(*start);
if (end->y > max_altitude)
{
*end = v3Add(*start, v3Scale(diff, (max_altitude - start->y) / diff.y));
*end = start->add(diff.scale((max_altitude - start->y) / diff.y));
}
else if (end->y < min_altitude)
{
*end = v3Add(*start, v3Scale(diff, (min_altitude - start->y) / diff.y));
*end = start->add(diff.scale((min_altitude - start->y) / diff.y));
}
}

View file

@ -76,12 +76,12 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
walker = start;
noise_distance = _getDistanceToBorder(model, start) * render_precision;
inside = (noise_distance > 0.0) ? 1 : 0;
step = v3Scale(direction, render_precision);
step = direction.scale(render_precision);
do
{
walker = v3Add(walker, step);
step_length = v3Norm(step);
walker = walker.add(step);
step_length = step.getNorm();
last_noise_distance = noise_distance;
noise_distance = _getDistanceToBorder(model, walker) * render_precision;
current_total_length += step_length;
@ -93,16 +93,16 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
// inside the cloud
segment_length += step_length;
current_inside_length += step_length;
step = v3Scale(direction, (noise_distance < render_precision) ? render_precision : noise_distance);
step = direction.scale((noise_distance < render_precision) ? render_precision : noise_distance);
}
else
{
// entering the cloud
inside = 1;
segment_length = step_length * noise_distance / (noise_distance - last_noise_distance);
segment_start = v3Add(walker, v3Scale(direction, -segment_length));
segment_start = walker.add(direction.scale(-segment_length));
current_inside_length += segment_length;
step = v3Scale(direction, render_precision);
step = direction.scale(render_precision);
}
}
else
@ -115,7 +115,7 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
current_inside_length += remaining_length;
out_segments->start = segment_start;
out_segments->end = v3Add(walker, v3Scale(direction, remaining_length - step_length));
out_segments->end = walker.add(direction.scale(remaining_length - step_length));
out_segments->length = segment_length;
out_segments++;
if (++segment_count >= max_segments)
@ -124,12 +124,12 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec
}
inside = 0;
step = v3Scale(direction, render_precision);
step = direction.scale(render_precision);
}
else
{
// searching for a cloud
step = v3Scale(direction, (noise_distance > -render_precision) ? render_precision : -noise_distance);
step = direction.scale((noise_distance > -render_precision) ? render_precision : -noise_distance);
}
}
} while (inside || (walker.y >= layer->altitude - 0.001 && walker.y <= (layer->altitude + layer->scaling) + 0.001 && current_total_length < max_total_length && current_inside_length < max_inside_length));

View file

@ -48,9 +48,9 @@ Color LightingManager::applyFinalComponent(const LightComponent &component, cons
Vector3 direction_inv;
light_color = component.color;
direction_inv = v3Scale(v3Normalize(component.direction), -1.0);
direction_inv = component.direction.normalize().scale(-1.0);
normal_norm = v3Norm(normal);
normal_norm = normal.getNorm();
if (normal_norm > 1.0)
{
normal_norm = 1.0;
@ -59,7 +59,7 @@ Color LightingManager::applyFinalComponent(const LightComponent &component, cons
result = COLOR_BLACK;
/* diffused light */
double diffuse = v3Dot(direction_inv, normal.normalize());
double diffuse = direction_inv.dotProduct(normal.normalize());
diffuse = (diffuse + (1.0 - normal_norm)) / (1.0 + (1.0 - normal_norm));
if (diffuse > 0.0)
{
@ -71,9 +71,9 @@ Color LightingManager::applyFinalComponent(const LightComponent &component, cons
/* specular reflection */
if (material.reflection > 0.0 && component.reflection > 0.0)
{
Vector3 view = v3Normalize(v3Sub(location, eye));
Vector3 reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
double specular = v3Dot(reflect, view);
Vector3 view = location.sub(eye).normalize();
Vector3 reflect = direction_inv.sub(normal.scale(2.0 * direction_inv.dotProduct(normal)));
double specular = reflect.dotProduct(view);
if (specular > 0.0)
{
specular = pow(specular, material.shininess) * material.reflection * component.reflection * normal_norm;

View file

@ -20,11 +20,11 @@ static Color _postProcessFragment(SoftwareRenderer* renderer, Vector3 location,
Color result;
camera_location = renderer->getCameraLocation(location);
direction = v3Sub(location, camera_location);
direction = location.sub(camera_location);
/* TODO Don't compute result->color if it's fully covered by clouds */
result = renderer->getAtmosphereRenderer()->getSkyColor(v3Normalize(direction)).final;
result = renderer->getCloudsRenderer()->getColor(camera_location, v3Add(camera_location, v3Scale(direction, 10.0)), result);
result = renderer->getAtmosphereRenderer()->getSkyColor(direction.normalize()).final;
result = renderer->getCloudsRenderer()->getColor(camera_location, camera_location.add(direction.scale(10.0)), result);
return result;
}
@ -61,22 +61,22 @@ void SkyRasterizer::rasterize()
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j);
vertex1 = v3Add(camera_location, direction);
vertex1 = camera_location.add(direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j);
direction.y = SPHERE_SIZE * sin(current_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j);
vertex2 = v3Add(camera_location, direction);
vertex2 = camera_location.add(direction);
direction.x = SPHERE_SIZE * cos(current_i + step_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i + step_i) * cos(current_j + step_j);
vertex3 = v3Add(camera_location, direction);
vertex3 = camera_location.add(direction);
direction.x = SPHERE_SIZE * cos(current_i) * cos(current_j + step_j);
direction.y = SPHERE_SIZE * sin(current_j + step_j);
direction.z = SPHERE_SIZE * sin(current_i) * cos(current_j + step_j);
vertex4 = v3Add(camera_location, direction);
vertex4 = camera_location.add(direction);
/* TODO Triangles at poles */
renderer->pushQuad(vertex1, vertex4, vertex3, vertex2, _postProcessFragment, NULL);

View file

@ -209,7 +209,7 @@ RayCastingResult SoftwareRenderer::rayWalking(const Vector3 &location, const Vec
sky_color = atmosphere_renderer->getSkyColor(direction).final;
result.hit = 1;
result.hit_location = v3Add(location, v3Scale(direction, 1000.0));
result.hit_location = location.add(direction.scale(1000.0));
result.hit_color = clouds_renderer->getColor(location, result.hit_location, sky_color);
}
@ -239,7 +239,7 @@ double SoftwareRenderer::getPrecision(Vector3 location)
projected.x += 1.0;
//projected.y += 1.0;
return v3Norm(v3Sub(render_camera->unproject(projected), location)); // / (double)render_quality;
return render_camera->unproject(projected).sub(location).getNorm(); // / (double)render_quality;
}
Vector3 SoftwareRenderer::projectPoint(Vector3 point)

View file

@ -107,14 +107,14 @@ static void _getChunk(SoftwareRenderer* renderer, TerrainRasterizer::TerrainChun
BoundingBox box;
if (displacement_power > 0.0)
{
box.pushPoint(v3Add(chunk->point_nw, v3(-displacement_power, displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_nw, v3(-displacement_power, -displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_sw, v3(-displacement_power, displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_sw, v3(-displacement_power, -displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_se, v3(displacement_power, displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_se, v3(displacement_power, -displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_ne, v3(displacement_power, displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_ne, v3(displacement_power, -displacement_power, -displacement_power)));
box.pushPoint(chunk->point_nw.add(Vector3(-displacement_power, displacement_power, -displacement_power)));
box.pushPoint(chunk->point_nw.add(Vector3(-displacement_power, -displacement_power, -displacement_power)));
box.pushPoint(chunk->point_sw.add(Vector3(-displacement_power, displacement_power, displacement_power)));
box.pushPoint(chunk->point_sw.add(Vector3(-displacement_power, -displacement_power, displacement_power)));
box.pushPoint(chunk->point_se.add(Vector3(displacement_power, displacement_power, displacement_power)));
box.pushPoint(chunk->point_se.add(Vector3(displacement_power, -displacement_power, displacement_power)));
box.pushPoint(chunk->point_ne.add(Vector3(displacement_power, displacement_power, -displacement_power)));
box.pushPoint(chunk->point_ne.add(Vector3(displacement_power, -displacement_power, -displacement_power)));
}
else
{

View file

@ -24,22 +24,22 @@ static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, V
{
Vector3 dnorth, deast, dsouth, dwest, normal;
dnorth = v3Sub(north, center);
deast = v3Sub(east, center);
dsouth = v3Sub(south, center);
dwest = v3Sub(west, center);
dnorth = north.sub(center);
deast = east.sub(center);
dsouth = south.sub(center);
dwest = west.sub(center);
normal = v3Cross(deast, dnorth);
normal = v3Add(normal, v3Cross(dsouth, deast));
normal = v3Add(normal, v3Cross(dwest, dsouth));
normal = v3Add(normal, v3Cross(dnorth, dwest));
normal = deast.crossProduct(dnorth);
normal = normal.add(dsouth.crossProduct(deast));
normal = normal.add(dwest.crossProduct(dsouth));
normal = normal.add(dnorth.crossProduct(dwest));
return v3Normalize(normal);
return normal.normalize();
}
static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
{
return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center)));
return south.sub(center).crossProduct(east.sub(center)).normalize();
}
TerrainRenderer::TerrainResult TerrainRenderer::getResult(double x, double z, int with_painting, int with_textures)
@ -140,16 +140,16 @@ RayCastingResult TerrainRenderer::castRay(const Vector3 &start, const Vector3 &d
length = 0.0;
do
{
inc_vector = v3Scale(direction_norm, inc_value);
length += v3Norm(inc_vector);
cursor = v3Add(cursor, inc_vector);
inc_vector = direction_norm.scale(inc_value);
length += inc_vector.getNorm();
cursor = cursor.add(inc_vector);
height = getHeight(cursor.x, cursor.z, 1);
diff = cursor.y - height;
if (diff < 0.0)
{
if (fabs(diff - lastdiff) > 0.00001)
{
cursor = v3Add(cursor, v3Scale(inc_vector, -diff / (diff - lastdiff)));
cursor = cursor.add(inc_vector.scale(-diff / (diff - lastdiff)));
cursor.y = getHeight(cursor.x, cursor.z, 1);
}
else
@ -188,7 +188,7 @@ int TerrainRenderer::alterLight(LightComponent *light, const Vector3 &location)
Vector3 inc_vector, direction_to_light, cursor;
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
direction_to_light = v3Scale(light->direction, -1.0);
direction_to_light = light->direction.scale(-1.0);
if (direction_to_light.y < -0.05)
{
light->color = COLOR_BLACK;
@ -212,16 +212,16 @@ int TerrainRenderer::alterLight(LightComponent *light, const Vector3 &location)
diff = 0.0;
do
{
inc_vector = v3Scale(direction_to_light, inc_value);
length += v3Norm(inc_vector);
cursor = v3Add(cursor, inc_vector);
inc_vector = direction_to_light.scale(inc_value);
length += inc_vector.getNorm();
cursor = cursor.add(inc_vector);
height = parent->getTerrainRenderer()->getResult(location.x, location.z, 1, 1).location.y;
diff = location.y - height;
if (diff < 0.0)
{
if (length * smoothing > 0.000001)
{
light_factor += diff * v3Norm(inc_vector) / (length * smoothing);
light_factor += diff * inc_vector.getNorm() / (length * smoothing);
}
else
{

View file

@ -66,23 +66,23 @@ static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, V
/* TODO This is duplicated in terrain/main.c */
Vector3 dnorth, deast, dsouth, dwest, normal;
dnorth = v3Sub(north, center);
deast = v3Sub(east, center);
dsouth = v3Sub(south, center);
dwest = v3Sub(west, center);
dnorth = north.sub(center);
deast = east.sub(center);
dsouth = south.sub(center);
dwest = west.sub(center);
normal = v3Cross(deast, dnorth);
normal = v3Add(normal, v3Cross(dsouth, deast));
normal = v3Add(normal, v3Cross(dwest, dsouth));
normal = v3Add(normal, v3Cross(dnorth, dwest));
normal = deast.crossProduct(dnorth);
normal = normal.add(dsouth.crossProduct(deast));
normal = normal.add(dwest.crossProduct(dsouth));
normal = normal.add(dnorth.crossProduct(dwest));
return v3Normalize(normal);
return normal.normalize();
}
static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
{
/* TODO This is duplicated in terrain/main.c */
return v3Normalize(v3Cross(v3Sub(south, center), v3Sub(east, center)));
return south.sub(center).crossProduct(east.sub(center)).normalize();
}
static Vector3 _getDetailNormal(SoftwareRenderer* renderer, Vector3 base_location, Vector3 base_normal, TextureLayerDefinition* layer)
@ -102,27 +102,27 @@ static Vector3 _getDetailNormal(SoftwareRenderer* renderer, Vector3 base_locatio
{
pivot = VECTOR_UP;
}
dx = v3Normalize(v3Cross(base_normal, pivot));
dy = v3Cross(base_normal, dx);
dx = base_normal.crossProduct(pivot).normalize();
dy = base_normal.crossProduct(dx);
/* Apply detail noise locally */
Vector3 center, north, east, south, west;
center = v3Add(base_location, v3Scale(base_normal, textures->getTriplanarNoise(layer->_detail_noise, base_location, base_normal)));
center = base_location.add(base_normal.scale(textures->getTriplanarNoise(layer->_detail_noise, base_location, base_normal)));
east = v3Add(base_location, v3Scale(dx, offset));
east = v3Add(east, v3Scale(base_normal, textures->getTriplanarNoise(layer->_detail_noise, east, base_normal)));
east = base_location.add(dx.scale(offset));
east = east.add(base_normal.scale(textures->getTriplanarNoise(layer->_detail_noise, east, base_normal)));
south = v3Add(base_location, v3Scale(dy, offset));
south = v3Add(south, v3Scale(base_normal, textures->getTriplanarNoise(layer->_detail_noise, south, base_normal)));
south = base_location.add(dy.scale(offset));
south = south.add(base_normal.scale(textures->getTriplanarNoise(layer->_detail_noise, south, base_normal)));
if (renderer->render_quality > 6)
{
west = v3Add(base_location, v3Scale(dx, -offset));
west = v3Add(west, v3Scale(base_normal, textures->getTriplanarNoise(layer->_detail_noise, west, base_normal)));
west = base_location.add(dx.scale(-offset));
west = west.add(base_normal.scale(textures->getTriplanarNoise(layer->_detail_noise, west, base_normal)));
north = v3Add(base_location, v3Scale(dy, -offset));
north = v3Add(north, v3Scale(base_normal, textures->getTriplanarNoise(layer->_detail_noise, north, base_normal)));
north = base_location.add(dy.scale(-offset));
north = north.add(base_normal.scale(textures->getTriplanarNoise(layer->_detail_noise, north, base_normal)));
result = _getNormal4(center, north, east, south, west);
}
@ -131,9 +131,9 @@ static Vector3 _getDetailNormal(SoftwareRenderer* renderer, Vector3 base_locatio
result = _getNormal2(center, east, south);
}
if (v3Dot(result, base_normal) < 0.0)
if (result.dotProduct(base_normal) < 0.0)
{
result = v3Scale(result, -1.0);
result = result.scale(-1.0);
}
return result;
}
@ -157,7 +157,7 @@ Vector3 TexturesRenderer::displaceTerrain(const TerrainRenderer::TerrainResult &
}
}
return v3Add(terrain.location, v3Scale(v3Normalize(terrain.normal), offset));
return terrain.location.add(terrain.normal.normalize().scale(offset));
}
double TexturesRenderer::getBasePresence(int layer, const TerrainRenderer::TerrainResult &terrain)

View file

@ -33,22 +33,22 @@ static inline Vector3 _getNormal(WaterDefinition* definition, double base_height
back.x = x;
back.y = _getHeight(definition, base_height, x, z + detail);
back.z = z + detail;
back = v3Sub(back, base);
back = back.sub(base);
right.x = x + detail;
right.y = _getHeight(definition, base_height, x + detail, z);
right.z = z;
right = v3Sub(right, base);
right = right.sub(base);
return v3Normalize(v3Cross(back, right));
return back.crossProduct(right).normalize();
}
static inline Vector3 _reflectRay(Vector3 incoming, Vector3 normal)
{
double c;
c = v3Dot(normal, v3Scale(incoming, -1.0));
return v3Add(incoming, v3Scale(normal, 2.0 * c));
c = normal.dotProduct(incoming.scale(-1.0));
return incoming.add(normal.scale(2.0 * c));
}
static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
@ -56,15 +56,15 @@ static inline Vector3 _refractRay(Vector3 incoming, Vector3 normal)
double c1, c2, f;
f = 1.0 / 1.33;
c1 = v3Dot(normal, v3Scale(incoming, -1.0));
c1 = normal.dotProduct(incoming.scale(-1.0));
c2 = sqrt(1.0 - pow(f, 2.0) * (1.0 - pow(c1, 2.0)));
if (c1 >= 0.0)
{
return v3Add(v3Scale(incoming, f), v3Scale(normal, f * c1 - c2));
return incoming.scale(f).add(normal.scale(f * c1 - c2));
}
else
{
return v3Add(v3Scale(incoming, f), v3Scale(normal, c2 - f * c1));
return incoming.scale(f).add(normal.scale(c2 - f * c1));
}
}
@ -79,26 +79,26 @@ static inline Color _getFoamMask(SoftwareRenderer* renderer, WaterDefinition* de
foam_factor = 0.0;
location.x += location_offset;
normal_diff = 1.0 - v3Dot(normal, _getNormal(definition, base_height, location, detail));
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
if (normal_diff > foam_factor)
{
foam_factor = normal_diff;
}
location.x -= location_offset * 2.0;
normal_diff = 1.0 - v3Dot(normal, _getNormal(definition, base_height, location, detail));
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
if (normal_diff > foam_factor)
{
foam_factor = normal_diff;
}
location.x += location_offset;
location.z -= location_offset;
normal_diff = 1.0 - v3Dot(normal, _getNormal(definition, base_height, location, detail));
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
if (normal_diff > foam_factor)
{
foam_factor = normal_diff;
}
location.z += location_offset * 2.0;
normal_diff = 1.0 - v3Dot(normal, _getNormal(definition, base_height, location, detail));
normal_diff = 1.0 - normal.dotProduct(_getNormal(definition, base_height, location, detail));
if (normal_diff > foam_factor)
{
foam_factor = normal_diff;
@ -214,7 +214,7 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
}
normal = _getNormal(definition, base_height, location, detail);
look_direction = v3Normalize(v3Sub(location, parent->getCameraLocation(location)));
look_direction = location.sub(parent->getCameraLocation(location)).normalize();
/* Reflection */
if (definition->reflection == 0.0)
@ -235,7 +235,7 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
{
Color depth_color = *definition->depth_color;
refracted = parent->rayWalking(location, _refractRay(look_direction, normal), 1, 0, 1, 1);
depth = v3Norm(v3Sub(location, refracted.hit_location));
depth = location.sub(refracted.hit_location).getNorm();
depth_color.limitPower(refracted.hit_color.getPower());
if (depth > definition->transparency_depth)
{

View file

@ -33,11 +33,11 @@ TEST(Bruneton, AerialPerspective1)
renderer.render_area->setBackgroundColor(COLOR_BLACK);
renderer.render_area->clear();
renderer.pushQuad(v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(50.0, -10.0, -50.0), Vector3(1.0, -10.0, -50.0), Vector3(1.0, -10.0, 50.0), Vector3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(10.0, -10.0, -10.0), Vector3(10.0, -10.0, -5.0), Vector3(10.0, 50.0, -5.0), Vector3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(15.0, -10.0, -5.0), Vector3(15.0, -10.0, 0.0), Vector3(15.0, 50.0, 0.0), Vector3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(20.0, -10.0, 5.0), Vector3(20.0, -10.0, 10.0), Vector3(20.0, 50.0, 10.0), Vector3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(30.0, -10.0, 25.0), Vector3(30.0, -10.0, 30.0), Vector3(30.0, 50.0, 30.0), Vector3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
renderer.render_area->saveToFile("./output/test_bruneton_perspective.png");
@ -66,11 +66,11 @@ TEST(Bruneton, AerialPerspective2)
renderer.render_area->setBackgroundColor(COLOR_BLACK);
renderer.render_area->clear();
renderer.pushQuad(v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(10.0, -10.0, -10.0), v3(10.0, -10.0, -5.0), v3(10.0, 50.0, -5.0), v3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(15.0, -10.0, -5.0), v3(15.0, -10.0, 0.0), v3(15.0, 50.0, 0.0), v3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(20.0, -10.0, 5.0), v3(20.0, -10.0, 10.0), v3(20.0, 50.0, 10.0), v3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(v3(30.0, -10.0, 25.0), v3(30.0, -10.0, 30.0), v3(30.0, 50.0, 30.0), v3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(50.0, -10.0, -50.0), Vector3(1.0, -10.0, -50.0), Vector3(1.0, -10.0, 50.0), Vector3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(10.0, -10.0, -10.0), Vector3(10.0, -10.0, -5.0), Vector3(10.0, 50.0, -5.0), Vector3(10.0, 50.0, -10.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(15.0, -10.0, -5.0), Vector3(15.0, -10.0, 0.0), Vector3(15.0, 50.0, 0.0), Vector3(15.0, 50.0, -5.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(20.0, -10.0, 5.0), Vector3(20.0, -10.0, 10.0), Vector3(20.0, 50.0, 10.0), Vector3(20.0, 50.0, 5.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(30.0, -10.0, 25.0), Vector3(30.0, -10.0, 30.0), Vector3(30.0, 50.0, 30.0), Vector3(30.0, 50.0, 25.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
renderer.render_area->saveToFile("./output/test_bruneton_perspective1.png");

View file

@ -68,7 +68,7 @@ TEST(Euclid, VectorSpherical)
v1.x = 0.0;
v1.y = 0.0;
v1.z = 0.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 0.0);
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
@ -76,7 +76,7 @@ TEST(Euclid, VectorSpherical)
v1.x = 1.0;
v1.y = 0.0;
v1.z = 0.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
@ -84,7 +84,7 @@ TEST(Euclid, VectorSpherical)
v1.x = -1.0;
v1.y = 0.0;
v1.z = 0.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, M_PI);
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
@ -92,7 +92,7 @@ TEST(Euclid, VectorSpherical)
v1.x = 0.0;
v1.y = 1.0;
v1.z = 0.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
EXPECT_DOUBLE_EQ(v2.theta, M_PI_2);
@ -100,7 +100,7 @@ TEST(Euclid, VectorSpherical)
v1.x = 0.0;
v1.y = -1.0;
v1.z = 0.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, 0.0);
EXPECT_DOUBLE_EQ(v2.theta, -M_PI_2);
@ -108,7 +108,7 @@ TEST(Euclid, VectorSpherical)
v1.x = 0.0;
v1.y = 0.0;
v1.z = 1.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, 3.0 * M_PI_2);
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
@ -116,13 +116,13 @@ TEST(Euclid, VectorSpherical)
v1.x = 0.0;
v1.y = 0.0;
v1.z = -1.0;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, 1.0);
EXPECT_DOUBLE_EQ(v2.phi, M_PI_2);
EXPECT_DOUBLE_EQ(v2.theta, 0.0);
v1.x = v1.y = v1.z = 0.5;
v2 = v3ToSpherical(v1);
v2 = v1.toSpherical();
EXPECT_DOUBLE_EQ(v2.r, sqrt(0.5 * 0.5 + 0.5 * 0.5 + 0.5 * 0.5));
EXPECT_DOUBLE_EQ(v2.phi, 7.0 * M_PI_4);
EXPECT_DOUBLE_EQ(v2.theta, M_PI_2 - 0.955316618125);

View file

@ -49,7 +49,7 @@ TEST(Render, quad)
renderer.render_area->setBackgroundColor(COLOR_BLUE);
renderer.render_area->clear();
renderer.pushQuad(v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
renderer.pushQuad(Vector3(-1.0, 0.0, 1.0), Vector3(-1.0, 0.0, -1.0), Vector3(1.0, 0.0, -1.0), Vector3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
renderer.render_area->postProcess(System::getCoreCount());
col = renderer.render_area->getPixel(399, 599 - 435);