add checkLine/portals

This commit is contained in:
ABelliqueux 2021-04-01 13:12:57 +02:00
parent 0d083c9580
commit 75dc59a0c0

View File

@ -48,13 +48,6 @@
#define FOV CENTERX // With a FOV of 1/2, camera focal length is ~= 16 mm / 90°
// Lower values mean wider angle
// Camera frustum : 4:3 aspect ratio
// normalized to 0-4096
#define HH 3072 // half height == tan(90/2) == 1
#define HW 4096 // half width == HH * (4/3) ~= 1.333
// pixel > cm : used in physics calculations
#define SCALE 4
@ -338,7 +331,7 @@ void callback();
int main() {
VECTOR sp = {0,0,0};
VECTOR sp = {CENTERX,CENTERY,0};
VECTOR wp = {0,0,0};
// FIXME : Poly subdiv
@ -420,6 +413,17 @@ int main() {
setCameraPos(camPtr->campos->pos, camPtr->campos->rot);
// Find curCamAngle if using pre-calculated BGs
if (camMode == 2) {
if (camPtr->tim_data){
curCamAngle = 1;
}
}
// Main loop
//~ while (1) {
@ -576,20 +580,27 @@ int main() {
// Fixed Camera angle
if (camMode == 2) {
// If BG images exist
if (camPtr->tim_data){
//~ drawBG();
if ( camAngles[ curCamAngle ]->fw.v0.vx ) {
//~ }
//~ FntPrint("v3 : %d, v2 : %d\n", camAngles[ curCamAngle ]->fw.v3.vx, camAngles[ curCamAngle ]->fw.v2.vx);
//~ FntPrint("v1 : %d, v2 : %d\n", camAngles[ curCamAngle ]->fw.v1.vy, camAngles[ curCamAngle ]->fw.v2.vy);
if ( actorPtr->pos2D.vx + actorPtr->body->max.vx / 2 > SCREENXRES ) {
// If actor in camAngle->fw area of screen
if ( actorPtr->pos2D.vx + CENTERX > camAngles[ curCamAngle ]->fw.v3.vx &&
//~ if (curCamAngle > 4) {
actorPtr->pos2D.vx + CENTERX < camAngles[ curCamAngle ]->fw.v2.vx &&
//~ curCamAngle = 0;
actorPtr->pos2D.vy + CENTERY > camAngles[ curCamAngle ]->fw.v3.vy &&
//~ }
actorPtr->pos2D.vy + CENTERY < camAngles[ curCamAngle ]->fw.v2.vy
) {
if (curCamAngle < 5) {
@ -605,6 +616,39 @@ int main() {
}
if ( camAngles[ curCamAngle ]->bw.v0.vx ) {
FntPrint("v3 : %d, v3 : %d\n", camAngles[ curCamAngle ]->bw.v3.vx, camAngles[ curCamAngle ]->bw.v3.vy);
FntPrint("v2 : %d, v2 : %d\n", camAngles[ curCamAngle ]->bw.v2.vx, camAngles[ curCamAngle ]->bw.v2.vy);
// If actor in camAngle->bw area of screen
if ( actorPtr->pos2D.vx + CENTERX < camAngles[ curCamAngle ]->bw.v3.vx &&
actorPtr->pos2D.vx + CENTERX > camAngles[ curCamAngle ]->bw.v2.vx &&
actorPtr->pos2D.vy + CENTERY < camAngles[ curCamAngle ]->bw.v3.vy &&
actorPtr->pos2D.vy + CENTERY > camAngles[ curCamAngle ]->bw.v2.vy
) {
if (curCamAngle > 0) {
curCamAngle--;
camPtr = camAngles[ curCamAngle ];
LoadTexture(camPtr->tim_data, camPtr->BGtim);
}
}
}
}
setCameraPos(camPtr->campos->pos, camPtr->campos->rot);
}
@ -732,7 +776,7 @@ int main() {
//~ FntPrint("Cam %d, %d, %d\n", camera.pos.vx, camera.pos.vy, camera.pos.vz);
//~ FntPrint("Pos: %d Cur: %d\nTheta y: %d x: %d\n", camPath.pos, camPath.cursor, theta.vy, theta.vx);
FntPrint("%d", camAngleToAct.vy);
//~ FntPrint("%d", camAngleToAct.vy);
if ( camAngleToAct.vy < -50 ) {
@ -805,7 +849,7 @@ int main() {
}
//~ // Moveable prop
// FIXME ! //~ // Moveable prop
//~ if ( !getIntCollision( *propPtr->body , *curNode->siblings->list[msh]->plane->body).vx &&
//~ !getIntCollision( *propPtr->body , *curNode->siblings->list[msh]->plane->body).vz ) {
@ -901,8 +945,13 @@ int main() {
// }
}
if ( (camMode == 2) && (camPtr->tim_data ) ) {
worldToScreen(actorPtr->pos, &actorPtr->pos2D);
}
// Camera setup
// position of cam relative to actor
@ -923,7 +972,7 @@ int main() {
drawBG();
//~ // Loop on camAngles
// Loop on camAngles
for ( int mesh = 0 ; mesh < camAngles[ curCamAngle ]->index; mesh ++ ) {
@ -933,6 +982,8 @@ int main() {
}
// Get screen coordinates of actor
//~ }
}
@ -1006,17 +1057,14 @@ int main() {
//~ FntPrint("CurNode : %x\nIndex: %d", curNode, curNode->siblings->index);
screenToWorld(&sp, &wp);
FntPrint("Time : %d dt :%d\n", VSync(-1) / 60, dt);
FntPrint("%d\n", curCamAngle );
//~ FntPrint("Actor : %d %d\n", actorPtr->pos->vx, actorPtr->pos->vy);
FntPrint("Actor : %d %d\n", actorPtr->pos2D.vx + actorPtr->body->max.vx / 2, actorPtr->pos2D.vy);
FntPrint("%d %d\n", actorPtr->pos->vx, actorPtr->pos->vy);
FntPrint("%d %d\n", actorPtr->pos2D.vx + CENTERX, actorPtr->pos2D.vy + CENTERY);
//~ FntPrint("%d %d\n", actorPtr->pos->vx, actorPtr->pos2D.vx);
//~ FntPrint("%d %d\n", actorPtr->pos->vy, actorPtr->pos2D.vy);
//~ FntPrint("%d %d\n", actorPtr->pos->vz, actorPtr->pos2D.vz);
FntPrint("%d - %d %d %d\n", sp.vx , wp.vx, wp.vy, wp.vz);
//~ FntPrint(" %d %d %d\n", wp.vx, wp.vy, wp.vz);
FntFlush(-1);
@ -1091,7 +1139,7 @@ void init() {
FntLoad(FNT_POS_X, FNT_POS_Y);
FntOpen(16, 180, 240, 96, 0, 512);
FntOpen(16, 90, 240, 180, 0, 512);
// Lighting setup
@ -1113,8 +1161,8 @@ void display(void){
ResetGraph(1);
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[db]);
SetDispMask(1);
@ -1122,9 +1170,6 @@ void display(void){
// Main OT
DrawOTag(otdisc[db] + OT2LEN - 1);
// Secondary OT
//~ DrawOTag(ot[db] + OTLEN - 1);
db = !db;
nextpri = primbuff[db];
@ -1977,21 +2022,21 @@ void worldToScreen( VECTOR * worldPos, VECTOR * screenPos ) {
// Get Rotation, Translation coordinates, apply perspective correction
// Muliply world coordinates vector by current rotation matrix, store in s
// Muliply world coordinates vector by current rotation matrix, store in screenPos
ApplyMatrixLV(&curRot, worldPos, screenPos);
// Get world translation vectors from rot and add to s.vx, vy, vz
// Get world translation vectors from rot and add to screenPos vx, vy, vz
applyVector(screenPos, curRot.t[0], curRot.t[1], curRot.t[2], +=);
// Correct perspective
screenPos -> vz = distToScreen; // Start with vz to avoid division by 0 below
screenPos -> vx = screenPos -> vx * distToScreen / ( screenPos -> vz + 1 ) ; // Add 1 to avoid division by 0
screenPos -> vx = screenPos -> vx * distToScreen / ( screenPos -> vz );
screenPos -> vy = screenPos -> vy * distToScreen / ( screenPos -> vz + 1 ) ;
screenPos -> vy = screenPos -> vy * distToScreen / ( screenPos -> vz );
screenPos -> vz = distToScreen ;
};
@ -1999,31 +2044,46 @@ void screenToWorld( VECTOR * screenPos, VECTOR * worldPos ) {
int distToScreen; // corresponds to FOV
MATRIX curRot, rotT; // current rotation matrix
MATRIX curRot, invRot; // current rotation matrix, transpose matrix
VECTOR curTrans;
VECTOR Trans; // working translation vector
// Get current matrix and projection */
// Get current matrix and projection
distToScreen = ReadGeomScreen();
ReadRotMatrix( &curRot );
PushMatrix();
PushMatrix(); // Store matrix on the stack (slow!)
// Get current translation
//// worldTrans = invRot * (screenPos - Rot.t)
curTrans.vx = screenPos->vx - curRot.t[0];
// Get world translation
curTrans.vy = screenPos->vy - curRot.t[1];
Trans.vx = screenPos->vx - curRot.t[0]; // Substract world translation from screenpos
curTrans.vz = screenPos->vz - curRot.t[2];
Trans.vy = screenPos->vy - curRot.t[1];
TransposeMatrix(&curRot, &rotT);
Trans.vz = screenPos->vz - curRot.t[2];
// We want the inverse of the current rotation matrix.
//
// Inverse matrix : M^-1 = 1 / detM * T(M)
// We know that the determinant of a rotation matrix is 1, thus:
// M^-1 = T(M)
//
// Get transpose of current rotation matrix
// > The transpose of a matrix is a new matrix whose rows are the columns of the original.
// https://www.quora.com/What-is-the-geometric-interpretation-of-the-transpose-of-a-matrix
ApplyMatrixLV(&rotT, &curTrans, worldPos);
TransposeMatrix( &curRot, &invRot );
// Multiply the transpose of current rotation matrix by the current translation vector
ApplyMatrixLV( &invRot, &Trans, worldPos );
// Get original rotation matrix back
PopMatrix();