Code: Select all
const auto x1y1 = perlin.noise2d(x1, y1),
x0y0 = perlin.noise2d(x0, y0),
...;
mesh[meshIdx] = {X+1 , x1y1, Z+1, 0};
mesh[meshIdx+1] = {X , x0y0, Z , 0};
mesh[meshIdx+2] = {X , x0y1, Z+1, 0};
//calculate side2 - side1 for cross
const SVECTOR side1 = {mesh[meshIdx+1].vx - mesh[meshIdx].vx, mesh[meshIdx+1].vy - mesh[meshIdx].vy, mesh[meshIdx+1].vz - mesh[meshIdx].vz };
const SVECTOR side2 = {mesh[meshIdx+1].vx - mesh[meshIdx+2].vx, mesh[meshIdx+1].vy - mesh[meshIdx+2].vy, mesh[meshIdx+1].vz - mesh[meshIdx+2].vz };
normals[0] = MathUtils::cross(side1, side2);
mesh[meshIdx+3] = {X , x0y0, Z, 0};
mesh[meshIdx+4] = {X+1, x1y1, Z+1, 0};
mesh[meshIdx+5] = {X+1, x1y0, Z, 0};
//calculate side4 - side3 for cross
const SVECTOR side3 = {mesh[meshIdx+4].vx - mesh[meshIdx+3].vx, mesh[meshIdx+4].vy - mesh[meshIdx+3].vy, mesh[meshIdx+4].vz - mesh[meshIdx+3].vz };
const SVECTOR side4 = {mesh[meshIdx+4].vx - mesh[meshIdx+5].vx, mesh[meshIdx+4].vy - mesh[meshIdx+5].vy, mesh[meshIdx+4].vz - mesh[meshIdx+5].vz };
normals[1] = MathUtils::cross(side3, side4);
and the code for cross:
Code: Select all
static constexpr SVECTOR cross(const SVECTOR& left, const SVECTOR& right)
{
return {((left.vy*right.vz)-(left.vz*right.vy))>>12,
((left.vz*right.vx)-(left.vx*right.vz))>>12,
((left.vx*right.vy)-(left.vy*right.vx))>>12
};
}
I'm using psn00bsdk + gcc 10.2
Thanks for the help.