Fixes #2: Light matrix is now updated on moving meshes
This commit is contained in:
parent
85cab5c47e
commit
495816dc8f
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
// Drawing
|
// Drawing
|
||||||
void transformMesh(CAMERA * camera, MESH * meshes);
|
void transformMesh(CAMERA * camera, MESH * meshes);
|
||||||
|
void enlightMesh(LEVEL * curLvl, MESH * actorPtr, SVECTOR * lgtang);
|
||||||
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
|
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
|
||||||
// Tri drawing
|
// Tri drawing
|
||||||
void set3VertexLerPos(MESH * mesh, long t);
|
void set3VertexLerPos(MESH * mesh, long t);
|
||||||
|
@ -1,27 +1,38 @@
|
|||||||
#include "../include/graphics.h"
|
#include "../include/graphics.h"
|
||||||
#include "../include/math.h"
|
#include "../include/math.h"
|
||||||
|
void enlightMesh(LEVEL * curLvl, MESH * mesh, SVECTOR * lgtang){
|
||||||
|
// Update light rotation on actor
|
||||||
|
MATRIX rotlgt, rotmesh, light;
|
||||||
|
// Find rotmat from actor angle
|
||||||
|
RotMatrix_gte(&mesh->rot, &rotmesh);
|
||||||
|
RotMatrix_gte(lgtang, &rotlgt);
|
||||||
|
MulMatrix0(&rotmesh, &rotlgt, &rotlgt);
|
||||||
|
MulMatrix0(curLvl->lgtmat, &rotlgt, &light);
|
||||||
|
SetLightMatrix(&light);
|
||||||
|
};
|
||||||
void transformMesh(CAMERA * camera, MESH * mesh){
|
void transformMesh(CAMERA * camera, MESH * mesh){
|
||||||
MATRIX mat;
|
MATRIX mat;
|
||||||
// Apply rotation matrix
|
// Apply rotation matrix
|
||||||
RotMatrix_gte(&mesh->rot, &mat);
|
RotMatrix_gte(&mesh->rot, &mat);
|
||||||
// Apply translation matrix
|
// Apply translation matrix
|
||||||
TransMatrix(&mat, &mesh->pos);
|
TransMatrix(&mat, &mesh->pos);
|
||||||
// Compose matrix with cam
|
// Compose matrix with cam
|
||||||
CompMatrix(&camera->mat, &mat, &mat);
|
CompMatrix(&camera->mat, &mat, &mat);
|
||||||
// Set default rotation and translation matrices
|
// Set default rotation and translation matrices
|
||||||
SetRotMatrix(&mat);
|
SetRotMatrix(&mat);
|
||||||
SetTransMatrix(&mat);
|
SetTransMatrix(&mat);
|
||||||
//~ }
|
//~ }
|
||||||
};
|
};
|
||||||
//TODO : Break this monster in tiny bits ?
|
//TODO : Break this monster in tiny bits ?
|
||||||
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
|
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
|
||||||
long nclip, t = 0;
|
long nclip, t = 0;
|
||||||
|
// FIXME : t is not incremented, thus always 0. It works if the mesh only has tris or quads, but won't work with mixed meshes.
|
||||||
// mesh is POLY_GT3 ( triangle )
|
// mesh is POLY_GT3 ( triangle )
|
||||||
if (mesh->index[t].code == 4) {
|
if (mesh->index[0].code == 4) {
|
||||||
drawTri(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
|
drawTri(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
|
||||||
}
|
}
|
||||||
// If mesh is quad
|
// If mesh is quad
|
||||||
if (mesh->index[t].code == 8) {
|
if (mesh->index[0].code == 8) {
|
||||||
drawQuad(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
|
drawQuad(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
20
src/main.c
20
src/main.c
@ -36,7 +36,7 @@ u_long overlaySize = 0;
|
|||||||
#include "../levels/level0.h"
|
#include "../levels/level0.h"
|
||||||
#include "../levels/level1.h"
|
#include "../levels/level1.h"
|
||||||
|
|
||||||
volatile u_char level = 0;
|
volatile u_char level = 1;
|
||||||
// level 1 : 8003F05C -2147225508
|
// level 1 : 8003F05C -2147225508
|
||||||
// level 0 : 800AF744 -2146764988
|
// level 0 : 800AF744 -2146764988
|
||||||
// 80010000 -2147418112 -> -2147483648
|
// 80010000 -2147418112 -> -2147483648
|
||||||
@ -57,12 +57,8 @@ char * nextpri = primbuff[0]; // Primitive counter
|
|||||||
char db = 0; // Current buffer counter
|
char db = 0; // Current buffer counter
|
||||||
CVECTOR BGc = {128, 128, 128, 0}; // Default Far color - This can be set in each level.
|
CVECTOR BGc = {128, 128, 128, 0}; // Default Far color - This can be set in each level.
|
||||||
VECTOR BKc = {128, 128, 128, 0}; // Back color
|
VECTOR BKc = {128, 128, 128, 0}; // Back color
|
||||||
MATRIX rotlgt;
|
|
||||||
MATRIX rotactor;
|
|
||||||
SVECTOR lgtang = {0, 0, 0};
|
SVECTOR lgtang = {0, 0, 0};
|
||||||
SVECTOR invang = {0, 0, 0};
|
MATRIX rotlgt, light;
|
||||||
SVECTOR actorang = {0, 0, 0};
|
|
||||||
MATRIX light;
|
|
||||||
short vs;
|
short vs;
|
||||||
CAMERA camera = {0};
|
CAMERA camera = {0};
|
||||||
// physics
|
// physics
|
||||||
@ -529,12 +525,14 @@ int main() {
|
|||||||
drawBG(curLvl.camPtr, &nextpri, otdisc[db], &db);
|
drawBG(curLvl.camPtr, &nextpri, otdisc[db], &db);
|
||||||
// Loop on camAngles
|
// Loop on camAngles
|
||||||
for ( int mesh = 0 ; mesh < curLvl.camAngles[ curCamAngle ]->index; mesh ++ ) {
|
for ( int mesh = 0 ; mesh < curLvl.camAngles[ curCamAngle ]->index; mesh ++ ) {
|
||||||
|
enlightMesh(&curLvl, curLvl.camAngles[curCamAngle]->objects[mesh], &lgtang);
|
||||||
transformMesh(&camera, curLvl.camAngles[curCamAngle]->objects[mesh]);
|
transformMesh(&camera, curLvl.camAngles[curCamAngle]->objects[mesh]);
|
||||||
drawPoly(curLvl.camAngles[curCamAngle]->objects[mesh], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
drawPoly(curLvl.camAngles[curCamAngle]->objects[mesh], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
||||||
// int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw)
|
// int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
//FIXME : Light is not applied to planes
|
||||||
// Draw current node's plane
|
// Draw current node's plane
|
||||||
drawPoly( curLvl.curNode->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
drawPoly( curLvl.curNode->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
||||||
// Draw surrounding planes
|
// Draw surrounding planes
|
||||||
@ -545,17 +543,20 @@ int main() {
|
|||||||
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
|
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
|
||||||
for ( int object = 0; object < curLvl.curNode->siblings->list[ sibling ]->objects->index; object++ ) {
|
for ( int object = 0; object < curLvl.curNode->siblings->list[ sibling ]->objects->index; object++ ) {
|
||||||
long t = 0;
|
long t = 0;
|
||||||
|
enlightMesh(&curLvl, curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ], &lgtang);
|
||||||
transformMesh(&camera, curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ]);
|
transformMesh(&camera, curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ]);
|
||||||
drawPoly( curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
drawPoly( curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Draw current plane children
|
// Draw current plane children
|
||||||
for ( int object = 0; object < curLvl.curNode->objects->index; object++ ) {
|
for ( int object = 0; object < curLvl.curNode->objects->index; object++ ) {
|
||||||
|
enlightMesh(&curLvl, curLvl.curNode->objects->list[ object ], &lgtang);
|
||||||
transformMesh(&camera, curLvl.curNode->objects->list[ object ]);
|
transformMesh(&camera, curLvl.curNode->objects->list[ object ]);
|
||||||
drawPoly( curLvl.curNode->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
drawPoly( curLvl.curNode->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
||||||
}
|
}
|
||||||
// Draw rigidbodies
|
// Draw rigidbodies
|
||||||
for ( int object = 0; object < curLvl.curNode->rigidbodies->index; object++ ) {
|
for ( int object = 0; object < curLvl.curNode->rigidbodies->index; object++ ) {
|
||||||
|
enlightMesh(&curLvl, curLvl.curNode->rigidbodies->list[ object ], &lgtang);
|
||||||
transformMesh(&camera, curLvl.curNode->rigidbodies->list[ object ]);
|
transformMesh(&camera, curLvl.curNode->rigidbodies->list[ object ]);
|
||||||
drawPoly( curLvl.curNode->rigidbodies->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
drawPoly( curLvl.curNode->rigidbodies->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
||||||
}
|
}
|
||||||
@ -563,15 +564,14 @@ int main() {
|
|||||||
}
|
}
|
||||||
// Find and apply light rotation matrix
|
// Find and apply light rotation matrix
|
||||||
|
|
||||||
// Update light rotation on actor
|
// Update global light matrix
|
||||||
// Find rotmat from actor angle
|
|
||||||
RotMatrix_gte(&curLvl.actorPtr->rot, &rotactor);
|
|
||||||
RotMatrix_gte(&lgtang, &rotlgt);
|
RotMatrix_gte(&lgtang, &rotlgt);
|
||||||
MulMatrix0(&rotactor, &rotlgt, &rotlgt);
|
|
||||||
MulMatrix0(curLvl.lgtmat, &rotlgt, &light);
|
MulMatrix0(curLvl.lgtmat, &rotlgt, &light);
|
||||||
SetLightMatrix(&light);
|
SetLightMatrix(&light);
|
||||||
|
|
||||||
// Set camera
|
// Set camera
|
||||||
applyCamera(&camera);
|
applyCamera(&camera);
|
||||||
|
|
||||||
// Add secondary OT to main OT
|
// Add secondary OT to main OT
|
||||||
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
|
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
|
||||||
//~ FntPrint("curLvl.curNode : %x\nIndex: %d", curLvl.curNode, curLvl.curNode->siblings->index);
|
//~ FntPrint("curLvl.curNode : %x\nIndex: %d", curLvl.curNode, curLvl.curNode->siblings->index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user