Few bug fixes and we're working\!

This commit is contained in:
Scott Duensing 2019-09-07 21:19:56 -05:00
parent b9557cd3a3
commit 081e669a8a
2 changed files with 167 additions and 177 deletions

View file

@ -578,11 +578,6 @@ void _j3ObjectUpdate(j3ObjectT *o) {
// === ROTATION === // === ROTATION ===
if (o->rotationDirty) {
// Rotation being dirty means we also need to update position later
o->positionDirty = true;
x = (jint16)o->rotation.x; x = (jint16)o->rotation.x;
y = (jint16)o->rotation.y; y = (jint16)o->rotation.y;
z = (jint16)o->rotation.z; z = (jint16)o->rotation.z;
@ -707,7 +702,7 @@ void _j3ObjectUpdate(j3ObjectT *o) {
rotateZ[1][0] = -sin_table[z]; rotateZ[1][0] = -sin_table[z];
rotateZ[1][1] = cos_table[z]; rotateZ[1][1] = cos_table[z];
j3MathMatrix4x4Mult(rotateX, rotateZ, temp); j3MathMatrix4x4Mult(rotateX, rotateY, temp);
j3MathMatrix4x4Mult(temp, rotateZ, final); j3MathMatrix4x4Mult(temp, rotateZ, final);
for (i=0; i<o->vertexCount; i++) { for (i=0; i<o->vertexCount; i++) {
@ -720,22 +715,18 @@ void _j3ObjectUpdate(j3ObjectT *o) {
default: default:
break; break;
} }
}
// === SCALE & TRANSLATION === // === SCALE & TRANSLATION ===
if (o->positionDirty || o->scaleDirty) {
for (i=0; i<o->vertexCount; i++) { for (i=0; i<o->vertexCount; i++) {
o->verticies[i].world.x = o->verticies[i].world.x * o->scale.x + o->position.x; o->verticies[i].world.x = o->verticies[i].world.x * o->scale.x + o->position.x;
o->verticies[i].world.y = o->verticies[i].world.y * o->scale.y + o->position.y; o->verticies[i].world.y = o->verticies[i].world.y * o->scale.y + o->position.y;
o->verticies[i].world.z = o->verticies[i].world.z * o->scale.z + o->position.z; o->verticies[i].world.z = o->verticies[i].world.z * o->scale.z + o->position.z;
} }
}
// === CAMERA SPACE === // === CAMERA SPACE ===
//***TODO*** Move this when we add multiple object stuff and re-do this function //***TODO*** Move this when we add multiple object stuff and re-do this function
if (_j3VarCameraLocationDirty || _j3VarCameraAngleDirty) {
// Create the global inverse transformation matrix used to transform world coordinate to camera coordinates // Create the global inverse transformation matrix used to transform world coordinate to camera coordinates
j3MathMatrix4x4Identity(translate); j3MathMatrix4x4Identity(translate);
j3MathMatrix4x4Identity(rotateX); j3MathMatrix4x4Identity(rotateX);
@ -746,7 +737,7 @@ void _j3ObjectUpdate(j3ObjectT *o) {
translate[3][1] = -_j3VarCameraLocation.y; translate[3][1] = -_j3VarCameraLocation.y;
translate[3][2] = -_j3VarCameraLocation.z; translate[3][2] = -_j3VarCameraLocation.z;
// Z matrix // X matrix
rotateX[1][1] = ( cos_table[_j3VarCameraAngle.x]); rotateX[1][1] = ( cos_table[_j3VarCameraAngle.x]);
rotateX[1][2] = -( sin_table[_j3VarCameraAngle.x]); rotateX[1][2] = -( sin_table[_j3VarCameraAngle.x]);
rotateX[2][1] = -(-sin_table[_j3VarCameraAngle.x]); rotateX[2][1] = -(-sin_table[_j3VarCameraAngle.x]);
@ -770,23 +761,23 @@ void _j3ObjectUpdate(j3ObjectT *o) {
_j3VarCameraLocationDirty = false; _j3VarCameraLocationDirty = false;
_j3VarCameraAngleDirty = false; _j3VarCameraAngleDirty = false;
}
if (o->positionDirty || o->rotationDirty) {
for (i=0; i<o->vertexCount; i++) { for (i=0; i<o->vertexCount; i++) {
o->verticies[i].camera.x = o->verticies[i].camera.x =
o->verticies[i].world.x * _j3VarCameraMatrix[0][0] + o->verticies[i].world.x * _j3VarCameraMatrix[0][0] +
o->verticies[i].world.y * _j3VarCameraMatrix[1][0] + o->verticies[i].world.y * _j3VarCameraMatrix[1][0] +
o->verticies[i].world.z * _j3VarCameraMatrix[2][0] + _j3VarCameraMatrix[3][0]; o->verticies[i].world.z * _j3VarCameraMatrix[2][0] +
_j3VarCameraMatrix[3][0];
o->verticies[i].camera.y = o->verticies[i].camera.y =
o->verticies[i].world.x * _j3VarCameraMatrix[0][1] + o->verticies[i].world.x * _j3VarCameraMatrix[0][1] +
o->verticies[i].world.y * _j3VarCameraMatrix[1][1] + o->verticies[i].world.y * _j3VarCameraMatrix[1][1] +
o->verticies[i].world.z * _j3VarCameraMatrix[2][1] + _j3VarCameraMatrix[3][1]; o->verticies[i].world.z * _j3VarCameraMatrix[2][1] +
_j3VarCameraMatrix[3][1];
o->verticies[i].camera.z = o->verticies[i].camera.z =
o->verticies[i].world.x * _j3VarCameraMatrix[0][2] + o->verticies[i].world.x * _j3VarCameraMatrix[0][2] +
o->verticies[i].world.y * _j3VarCameraMatrix[1][2] + o->verticies[i].world.y * _j3VarCameraMatrix[1][2] +
o->verticies[i].world.z * _j3VarCameraMatrix[2][2] + _j3VarCameraMatrix[3][2]; o->verticies[i].world.z * _j3VarCameraMatrix[2][2] +
} _j3VarCameraMatrix[3][2];
} }
// === REMOVE BACKFACES & LIGHT === // === REMOVE BACKFACES & LIGHT ===
@ -889,7 +880,8 @@ void _j3ObjectUpdate(j3ObjectT *o) {
} }
// Did this triangle survive culling? // Did this triangle survive culling?
if (o->triangles[i].visible) { //***TODO*** Our visible flag is backwards for some reason. Not sure why yet.
if (!o->triangles[i].visible) {
// Find average z depth in camera space // Find average z depth in camera space
vertex0 = o->triangles[i].index[0]; vertex0 = o->triangles[i].index[0];
vertex1 = o->triangles[i].index[1]; vertex1 = o->triangles[i].index[1];
@ -933,8 +925,6 @@ void _j3ObjectUpdateNormalLength(j3ObjectT *object, juint16 triangle) {
// 15, this will change the shading calculation of 15*dp/normal into // 15, this will change the shading calculation of 15*dp/normal into
// dp*normal_length, removing one division // dp*normal_length, removing one division
object->triangles[triangle].normalLength = (float)15.0 / j3MathVectorMagnatude3D((j3Vector3DT *)&normal); object->triangles[triangle].normalLength = (float)15.0 / j3MathVectorMagnatude3D((j3Vector3DT *)&normal);
} }

View file

@ -74,7 +74,7 @@ int main(void) {
printAt(font, 1, 1, "Loading object... "); printAt(font, 1, 1, "Loading object... ");
jlDisplayPresent(); jlDisplayPresent();
r = j3WorldLoad(world, "pyramid"); r = j3WorldLoad(world, "cube");
if (!r) { if (!r) {
printAt(font, 1, 1, "Object loading: Failed."); printAt(font, 1, 1, "Object loading: Failed.");
jlDisplayPresent(); jlDisplayPresent();