Move camAngletoAct to scratchpad, use dz for dualshock

This commit is contained in:
ABelliqueux 2021-07-13 13:23:02 +02:00
parent dbe5a8e465
commit 9447dabd21
7 changed files with 75 additions and 68 deletions

View File

@ -29,4 +29,4 @@ void getCameraZY( int * z, int * y, int actorZ, int actorY, int angleX, int dist
void applyCamera(CAMERA * cam); void applyCamera(CAMERA * cam);
void setCameraPos(CAMERA * camera, SVECTOR * pos, SVECTOR * rot); void setCameraPos(CAMERA * camera, SVECTOR * pos, SVECTOR * rot);
void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECTOR * posToActor, VECTOR * angle, VECTOR * angleCam, short curCamAngle, int camMode, int * lerping); void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * posToActor, VECTOR * angle, VECTOR * angleCam, short curCamAngle, int camMode, int * lerping);

View File

@ -1,5 +1,5 @@
#define VMODE 0 // 0 == NTSC, 1 == PAL #define VMODE 0 // 0 == NTSC, 1 == PAL
#define VSYNC 1 #define VSYNC 0
#define SCREENXRES 320 #define SCREENXRES 320
#define SCREENYRES 240 #define SCREENYRES 240
#define CENTERX SCREENXRES/2 #define CENTERX SCREENXRES/2
@ -45,7 +45,8 @@ asm(\
#define dc_wrklvector ((VECTOR*) getScratchAddr(34)) #define dc_wrklvector ((VECTOR*) getScratchAddr(34))
#define dc_camMat ((MATRIX*) getScratchAddr(38)) #define dc_camMat ((MATRIX*) getScratchAddr(38))
#define dc_camRot ((SVECTOR*) getScratchAddr(46)) #define dc_camRot ((SVECTOR*) getScratchAddr(46))
#define dc_camPos ((SVECTOR*) getScratchAddr(54)) #define dc_camPos ((SVECTOR*) getScratchAddr(48))
#define dc_actorRot ((VECTOR*) getScratchAddr(50))
//~ #define dc_sxytbl ((DVECTOR*) getScratchAddr(15)) // 6 DVEC == 12 //~ #define dc_sxytbl ((DVECTOR*) getScratchAddr(15)) // 6 DVEC == 12
//~ #define dc_verts ((SVECTOR*) getScratchAddr(27)) // store verts here //~ #define dc_verts ((SVECTOR*) getScratchAddr(27)) // store verts here

View File

@ -15,4 +15,4 @@ void checkBodyCol(BODY * one, BODY * two);
void applyAngMom(LEVEL curLvl ); void applyAngMom(LEVEL curLvl );
void ResolveCollision( BODY * one, BODY * two ); void ResolveCollision( BODY * one, BODY * two );
VECTOR angularMom(BODY body); VECTOR angularMom(BODY body);
void applyAcceleration(BODY * actor, ulong oldTime); void applyAcceleration(BODY * actor);

View File

@ -31,14 +31,14 @@ void applyCamera( CAMERA * cam ) {
gte_SetTransMatrix(dc_camMat); // Set Transform matrix gte_SetTransMatrix(dc_camMat); // Set Transform matrix
}; };
void setCameraPos( CAMERA * camera, SVECTOR * pos, SVECTOR * rot ) { void setCameraPos( CAMERA * camera, SVECTOR * pos, SVECTOR * rot ) {
copyVector(camera->pos, pos); copyVector(dc_camPos, pos);
copyVector(camera->rot, rot); copyVector(dc_camRot, rot);
}; };
void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECTOR * posToActor, VECTOR * angle, VECTOR * angleCam, short curCamAngle, int camMode, int * lerping){ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * posToActor, VECTOR * angle, VECTOR * angleCam, short curCamAngle, int camMode, int * lerping){
int dist = 0; int dist = 0;
short cameraSpeed = 40; short cameraSpeed = 40;
//~ if(camMode != 2) { //~ if(camMode != 2) {
//~ camera->rot->vy = camAngleToAct->vy; //~ camera->rot->vy = camAngleToAct->vy;
//~ // using csin/ccos, no need for theta //~ // using csin/ccos, no need for theta
//~ camera->rot->vx = camAngleToAct->vx; //~ camera->rot->vx = camAngleToAct->vx;
@ -50,7 +50,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
// Camera follows actor // Camera follows actor
case 0 : case 0 :
dist = 200; dist = 200;
setVector(camera->pos, -(camera->x/ONE), -(camera->y/ONE), -(camera->z/ONE)); setVector(dc_camPos, -(camera->x/ONE), -(camera->y/ONE), -(camera->z/ONE));
angle->vy = -(curLvl->actorPtr->rot.vy / 2) + angleCam->vy; angle->vy = -(curLvl->actorPtr->rot.vy / 2) + angleCam->vy;
// Camera horizontal and vertical position // Camera horizontal and vertical position
getCameraZY(&camera->z, &camera->y, curLvl->actorPtr->pos.vz, curLvl->actorPtr->pos.vy, angle->vx, dist); getCameraZY(&camera->z, &camera->y, curLvl->actorPtr->pos.vz, curLvl->actorPtr->pos.vy, angle->vx, dist);
@ -62,7 +62,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
// Set distance between cam and actor // Set distance between cam and actor
dist = 150; dist = 150;
// Set camera position // Set camera position
setVector(camera->pos, -(camera->x/ONE), 100, -(camera->z/ONE)); setVector(dc_camPos, -(camera->x/ONE), 100, -(camera->z/ONE));
// Find new camera position // Find new camera position
getCameraXZ(&camera->x, &camera->z, curLvl->actorPtr->pos.vx, curLvl->actorPtr->pos.vz, angle->vy, dist); getCameraXZ(&camera->x, &camera->z, curLvl->actorPtr->pos.vx, curLvl->actorPtr->pos.vz, angle->vy, dist);
// Set rotation amount // Set rotation amount
@ -70,7 +70,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
break; break;
// Fixed Camera angle // Fixed Camera angle
case 2 : case 2 :
// If BG images exist // If BG images exist
if (curLvl->camPtr->tim_data){ if (curLvl->camPtr->tim_data){
checkLineW( &curLvl->camAngles[ curCamAngle ]->fw.v3, &curLvl->camAngles[ curCamAngle ]->fw.v2, curLvl->actorPtr); checkLineW( &curLvl->camAngles[ curCamAngle ]->fw.v3, &curLvl->camAngles[ curCamAngle ]->fw.v2, curLvl->actorPtr);
@ -109,7 +109,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
// Using precalc sqrt // Using precalc sqrt
dist = psqrt( (posToActor->vx * posToActor->vx ) + (posToActor->vz * posToActor->vz) ); dist = psqrt( (posToActor->vx * posToActor->vx ) + (posToActor->vz * posToActor->vz) );
// Set camera position // Set camera position
setVector(camera->pos, 190, 100, 180); setVector(dc_camPos, 190, 100, 180);
break; break;
// Flyby mode with LERP from camStart to camEnd // Flyby mode with LERP from camStart to camEnd
case 4 : case 4 :
@ -158,7 +158,7 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
// Lerping sequence has not begun // Lerping sequence has not begun
if (!lerping){ if (!lerping){
// Set cam start position ( first key pos ) // Set cam start position ( first key pos )
copyVector(camera->pos, &curLvl->camPath->points[curLvl->camPath->cursor]); copyVector(dc_camPos, &curLvl->camPath->points[curLvl->camPath->cursor]);
// Lerping sequence is starting // Lerping sequence is starting
*lerping = 1; *lerping = 1;
// Set cam pos index to 0 // Set cam pos index to 0
@ -174,11 +174,11 @@ void setCameraMode(LEVEL * curLvl, CAMERA * camera, VECTOR * camAngleToAct, VECT
lerpD(curLvl->camPath->points[curLvl->camPath->cursor].vz << precision, curLvl->camPath->points[curLvl->camPath->cursor+1].vz << precision, curLvl->camPath->pos << precision) >> precision lerpD(curLvl->camPath->points[curLvl->camPath->cursor].vz << precision, curLvl->camPath->points[curLvl->camPath->cursor+1].vz << precision, curLvl->camPath->pos << precision) >> precision
); );
// Ony move cam if position is between first curLvl->camPath->vx and last curLvl->camPath->vx // Ony move cam if position is between first curLvl->camPath->vx and last curLvl->camPath->vx
if ( camAngleToAct->vy < -50 && camera->pos->vx > curLvl->camPath->points[curLvl->camPath->len - 1].vx ) { if ( dc_actorRot->vy < -50 && dc_camPos->vx > curLvl->camPath->points[curLvl->camPath->len - 1].vx ) {
// Clamp curLvl->camPath position to cameraSpeed // Clamp curLvl->camPath position to cameraSpeed
curLvl->camPath->pos += dist < cameraSpeed ? 0 : cameraSpeed ; curLvl->camPath->pos += dist < cameraSpeed ? 0 : cameraSpeed ;
} }
if ( camAngleToAct->vy > 50 && camera->pos->vx > curLvl->camPath->points[curLvl->camPath->cursor].vx ) { if ( dc_actorRot->vy > 50 && dc_camPos->vx > curLvl->camPath->points[curLvl->camPath->cursor].vx ) {
curLvl->camPath->pos -= dist < cameraSpeed ? 0 : cameraSpeed; curLvl->camPath->pos -= dist < cameraSpeed ? 0 : cameraSpeed;
} }
// If camera has reached next key pos, reset pos index, move cursor to next key pos // If camera has reached next key pos, reset pos index, move cursor to next key pos

View File

@ -163,23 +163,22 @@ void set3Prism(POLY_GT3 * poly, MESH * mesh, DRAWENV * draw, char * db, int i){
//~ if (fixed_BGS){ //~ if (fixed_BGS){
//~ ( (POLY_GT3 *) poly )->tpage = getTPage( 0, 0, 320, 0 ); //~ ( (POLY_GT3 *) poly )->tpage = getTPage( 0, 0, 320, 0 );
//~ } //~ }
( (POLY_GT3 *) poly )->tpage = getTPage( 2, 0, setTPage( poly, 2, 0, 0, !(*db)<<8);
draw[*db].clip.x, //~ SetShadeTex( poly, 1 );
draw[*db].clip.y
);
// Use projected coordinates (results from RotAverage...) as UV coords and clamp them to 0-255,0-224 -> 240 - 16 // Use projected coordinates (results from RotAverage...) as UV coords and clamp them to 0-255,0-224 -> 240 - 16
setUV3( poly, setUV3( poly,
(poly->x0 < 0 ? 0 : poly->x0 > 255 ? 255 : poly->x0), (poly->x0 < 0 ? 0 : (poly->x0 + 4) > 255 ? 255 : (poly->x0 + 4) ),
(poly->y0 < 0 ? 0 : poly->y0 > 224 ? 224 : poly->y0), (poly->y0 < 0 ? 0 : (poly->y0 + 4) > 224 ? 224 : (poly->y0 + 4) ),
(poly->x1 < 0 ? 0 : poly->x1 > 255 ? 255 : poly->x1), (poly->x1 < 0 ? 0 : (poly->x1 + 4) > 255 ? 255 : (poly->x1 + 4) ),
(poly->y1 < 0 ? 0 : poly->y1 > 224 ? 224 : poly->y1), (poly->y1 < 0 ? 0 : (poly->y1 + 4) > 224 ? 224 : (poly->y1 + 4) ),
(poly->x2 < 0 ? 0 : poly->x2 > 255 ? 255 : poly->x2), (poly->x2 < 0 ? 0 : (poly->x2 + 4) > 255 ? 255 :( poly->x2 + 4) ),
(poly->y2 < 0 ? 0 : poly->y2 > 224 ? 224 : poly->y2) (poly->y2 < 0 ? 0 :( poly->y2 + 4) > 224 ? 224 : (poly->y2 + 4) )
); );
setRGB0(poly, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b); //~ setRGB0(poly, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b);
setRGB1(poly, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b); //~ setRGB1(poly, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b);
setRGB2(poly, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b); //~ setRGB2(poly, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b);
}; };
void set4Prism(POLY_GT4 * poly4, MESH * mesh, DRAWENV * draw, char * db, int i){ void set4Prism(POLY_GT4 * poly4, MESH * mesh, DRAWENV * draw, char * db, int i){
( (POLY_GT4 *) poly4)->tpage = getTPage( 2, 0, ( (POLY_GT4 *) poly4)->tpage = getTPage( 2, 0,

View File

@ -25,7 +25,7 @@
#include "../include/graphics.h" #include "../include/graphics.h"
#include "../include/space.h" #include "../include/space.h"
//~ #define USECD #define USECD
// START OVERLAY // START OVERLAY
extern u_long load_all_overlays_here; extern u_long load_all_overlays_here;
@ -74,7 +74,7 @@ int camMode = ACTOR; // Cam mode, see defines.h, l.6
VECTOR angle = {250,0,0,0}; VECTOR angle = {250,0,0,0};
VECTOR angleCam = {0,0,0,0}; VECTOR angleCam = {0,0,0,0};
VECTOR posToActor = {0, 0, 0, 0}; // position of camera relative to actor VECTOR posToActor = {0, 0, 0, 0}; // position of camera relative to actor
VECTOR camAngleToAct = {0, 0, 0, 0}; // rotation angles for the camera to point at actor VECTOR * camAngleToAct; // rotation angles for the camera to point at actor
int dist = 150; int dist = 150;
int lerping = 0; int lerping = 0;
short curCamAngle = 0; short curCamAngle = 0;
@ -93,6 +93,7 @@ short forceApplied = 0;
void callback(); void callback();
// variable FPS // variable FPS
ulong oldTime = 0; ulong oldTime = 0;
int dt = 0;
// Physics/collisions // Physics/collisions
short physics = 1; short physics = 1;
VECTOR col = {0}; VECTOR col = {0};
@ -107,6 +108,7 @@ int main() {
camera.mat = dc_camMat; camera.mat = dc_camMat;
camera.pos = dc_camPos; camera.pos = dc_camPos;
camera.rot = dc_camRot; camera.rot = dc_camRot;
camAngleToAct = dc_actorRot;
// Load level file according to level, l.39 // Load level file according to level, l.39
if ( level == 0 ){ if ( level == 0 ){
overlayFile = "\\level0.bin;1"; overlayFile = "\\level0.bin;1";
@ -164,10 +166,13 @@ int main() {
curCamAngle = 1; curCamAngle = 1;
} }
} }
oldTime = GetRCnt(RCntCNT1);
// Main loop // Main loop
while ( VSync(VSYNC) ) { while ( VSync(VSYNC) ) {
oldTime = VSync(-1);
//~ timeS = VSync(-1) / 60; dt = GetRCnt(RCntCNT1) - oldTime;
oldTime = GetRCnt(RCntCNT1);
// Check if level has changed // Check if level has changed
// TODO : Proper level system / loader // TODO : Proper level system / loader
if ( levelWas != level ){ if ( levelWas != level ){
@ -198,14 +203,14 @@ int main() {
setLightEnv(draw, curLvl.BGc, curLvl.BKc); setLightEnv(draw, curLvl.BGc, curLvl.BKc);
levelWas = level; levelWas = level;
} }
FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl); //~ FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
// atime is used for animations timing // atime is used for animations timing
timediv = 1; timediv = 1;
// If timediv is > 1, animation time will be slower // If timediv is > 1, animation time will be slower
if (time % timediv == 0){ if (time % timediv == 0){
atime ++; atime ++;
} }
// Spatial partitioning // Spatial partitioning
if (curLvl.curNode){ if (curLvl.curNode){
for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) { for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) {
// Actor // Actor
@ -228,7 +233,7 @@ int main() {
// if(time%1 == 0){ // if(time%1 == 0){
for ( int k = 0; k < *curLvl.meshes_length; k ++ ) { for ( int k = 0; k < *curLvl.meshes_length; k ++ ) {
if ( curLvl.meshes[k]->isRigidBody == 1 ) { if ( curLvl.meshes[k]->isRigidBody == 1 ) {
applyAcceleration( curLvl.meshes[k]->body , oldTime); applyAcceleration( curLvl.meshes[k]->body);
// Get col between actor and level // Get col between actor and level
if ( curLvl.meshes[k]->isActor ){ if ( curLvl.meshes[k]->isActor ){
checkBodyCol( curLvl.meshes[k]->body , curLvl.levelPtr->body ); checkBodyCol( curLvl.meshes[k]->body , curLvl.levelPtr->body );
@ -264,19 +269,22 @@ int main() {
// Clear Secondary OT // Clear Secondary OT
ClearOTagR(ot[db], OTLEN); ClearOTagR(ot[db], OTLEN);
// Set camera according to mode // Set camera according to mode
setCameraMode(&curLvl, &camera, &camAngleToAct, &posToActor, &angle, &angleCam, curCamAngle, camMode, &lerping); setCameraMode(&curLvl, &camera, &posToActor, &angle, &angleCam, curCamAngle, camMode, &lerping);
// Render scene // Render scene
renderScene(&curLvl, &camera, &camMode, &nextpri, ot[db], otdisc[db], &db, &draw[db], curCamAngle, atime); renderScene(&curLvl, &camera, &camMode, &nextpri, ot[db], otdisc[db], &db, &draw[db], curCamAngle, atime);
// Set camera // Set camera
// Get position of cam relative to actor // Get position of cam relative to actor
addVector2(&curLvl.actorPtr->pos, camera.pos, &posToActor); addVector2(&curLvl.actorPtr->pos, camera.pos, &posToActor);
// Angle between camera and actor // Angle between camera and actor
// using atantable (faster) applyVector( dc_actorRot,
camAngleToAct.vy = (patan(-posToActor.vx, -posToActor.vz) / 16) - 3076 ; (patan(dist, posToActor.vy) >> 4 ) - 256,
camAngleToAct.vx = (patan(dist, posToActor.vy) >> 4 ) - 256; (patan(-posToActor.vx, -posToActor.vz) / 16) - 3076,
camera.rot->vy = camAngleToAct.vy; 0,
// using csin/ccos, no need for theta =
camera.rot->vx = camAngleToAct.vx; );
// Point camera at actor unless camMode == FIXED
if (camMode!=2){ copyVector(dc_camRot, dc_actorRot); }
//
applyCamera(&camera); applyCamera(&camera);
// Find Actor's forward vector // Find Actor's forward vector
@ -290,9 +298,8 @@ int main() {
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]); AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
FntPrint("\nTime : %d\n", time); FntPrint("\nTime : %d\n", time);
//~ FntPrint("Ticks : %d %d \n", oldTime, VSync(-1)-oldTime);
FntPrint("cam : %d \n", camMode);
FntPrint("#Tri : %d\n", triCount); FntPrint("#Tri : %d\n", triCount);
FntPrint("#RCnt : %d %d\n", oldTime, dt);
FntFlush(-1); FntFlush(-1);
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db); display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
} }
@ -390,29 +397,29 @@ void callback() {
} }
if (theControllers[0].type == 0x73){ if (theControllers[0].type == 0x73){
// Analog stick L up // Analog stick L up
if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < 108 ) { if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < (128 - DS_DZ/2)) {
curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * (128 - theControllers[0].analog3 ) >> 14 ; curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * (128 - theControllers[0].analog3 ) >> 14 ;
curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * (128 - theControllers[0].analog3 ) >> 14 ; curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * (128 - theControllers[0].analog3 ) >> 14 ;
lastPad = PADL; lastPad = PADL;
} }
// Analog stick L down // Analog stick L down
if ( theControllers[0].analog3 > 168 && theControllers[0].analog3 <= 255 ) { if ( theControllers[0].analog3 > (128 + DS_DZ/2) && theControllers[0].analog3 <= 255 ) {
curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * ( theControllers[0].analog3 - 128 ) >> 14 ; curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * ( theControllers[0].analog3 - 128 ) >> 14 ;
curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * ( theControllers[0].analog3 - 128 ) >> 14 ; curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * ( theControllers[0].analog3 - 128 ) >> 14 ;
lastPad = PADL; lastPad = PADL;
} }
// Analog stick L dead zone // Analog stick L dead zone
if ( theControllers[0].analog3 > 108 && theControllers[0].analog3 < 148 ) { if ( theControllers[0].analog3 > (128 - DS_DZ/2) && theControllers[0].analog3 < (128 + DS_DZ/2) ) {
curLvl.actorPtr->body->gForce.vz = 0; curLvl.actorPtr->body->gForce.vz = 0;
curLvl.actorPtr->body->gForce.vx = 0; curLvl.actorPtr->body->gForce.vx = 0;
} }
// Analog stick L left // Analog stick L left
if ( theControllers[0].analog2 >= 0 && theControllers[0].analog2 < 108 ) { if ( theControllers[0].analog2 >= 0 && theControllers[0].analog2 < (128 - DS_DZ/2) ) {
curLvl.actorPtr->rot.vy -= ( 40 * ( 128 - theControllers[0].analog2 ) ) >> 7 ; curLvl.actorPtr->rot.vy -= ( 64 * ( 128 - theControllers[0].analog2 ) ) >> 7 ;
} }
// Analog stick L right // Analog stick L right
if ( theControllers[0].analog2 > 148 && theControllers[0].analog2 <= 255 ) { if ( theControllers[0].analog2 > (128 + DS_DZ/2) && theControllers[0].analog2 <= 255 ) {
curLvl.actorPtr->rot.vy += ( 40 * ( theControllers[0].analog2 - 128 ) ) >> 7 ; curLvl.actorPtr->rot.vy += ( 64 * ( theControllers[0].analog2 - 128 ) ) >> 7 ;
} }
} }
if ( PADL & PadUp ) { if ( PADL & PadUp ) {
@ -436,11 +443,11 @@ void callback() {
lastPad = PADL; lastPad = PADL;
} }
if ( PADL & PadLeft ) { if ( PADL & PadLeft ) {
curLvl.actorPtr->rot.vy -= 32; curLvl.actorPtr->rot.vy -= 64;
lastPad = PADL; lastPad = PADL;
} }
if ( PADL & PadRight ) { if ( PADL & PadRight ) {
curLvl.actorPtr->rot.vy += 32; curLvl.actorPtr->rot.vy += 64;
lastPad = PADL; lastPad = PADL;
} }
if ( PADL & PadSelect && !timer ) { if ( PADL & PadSelect && !timer ) {
@ -460,19 +467,19 @@ void callback() {
if( theControllers[0].type == 0x73 && camMode == 0){ if( theControllers[0].type == 0x73 && camMode == 0){
// Cam control - horizontal // Cam control - horizontal
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < (128 - DS_DZ/2) ) { if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < (128 - DS_DZ/2) ) {
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ; angleCam.vy += ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
angleCamTimer = 120; angleCamTimer = 120;
} }
if ( theControllers[0].analog0 > (128 + DS_DZ/2) && theControllers[0].analog0 <= 255 ) { if ( theControllers[0].analog0 > (128 + DS_DZ/2) && theControllers[0].analog0 <= 255 ) {
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ; angleCam.vy -= ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
angleCamTimer = 120; angleCamTimer = 120;
} }
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < (128 - DS_DZ/2) ) { if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < (128 - DS_DZ/2) ) {
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ; angleCam.vy += ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
angleCamTimer = 120; angleCamTimer = 120;
} }
if ( theControllers[0].analog0 > (128 + DS_DZ/2) && theControllers[0].analog0 <= 255) { if ( theControllers[0].analog0 > (128 + DS_DZ/2) && theControllers[0].analog0 <= 255) {
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ; angleCam.vy -= ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
angleCamTimer = 120; angleCamTimer = 120;
} }
// Timer to lerp cam back behind actor // Timer to lerp cam back behind actor

View File

@ -126,19 +126,19 @@ void applyAngMom(LEVEL curLvl ){
} }
} }
}; };
void applyAcceleration(BODY * actor, ulong oldTime){ void applyAcceleration(BODY * actor){
short dt = VSync(-1) - oldTime ; //~ short dt = VSync(-1) - oldTime ;
//~ short dt = 3; short dt = 1;
if (dt < 1) { dt = 1; } //~ if (dt < 1) { dt = 1; }
VECTOR acceleration = {actor->invMass * actor->gForce.vx , (actor->invMass * actor->gForce.vy) + (GRAVITY * ONE), actor->invMass * actor->gForce.vz}; VECTOR acceleration = {actor->invMass * actor->gForce.vx , (actor->invMass * actor->gForce.vy) + (GRAVITY * ONE), actor->invMass * actor->gForce.vz};
//~ FntPrint("acc: %d %d %d\n", acceleration.vx, acceleration.vy, acceleration.vz ); //~ FntPrint("acc: %d %d %d\n", acceleration.vx, acceleration.vy, acceleration.vz );
actor->velocity.vx += (acceleration.vx * (ONE / dt) ) >> 24; actor->velocity.vx += (acceleration.vx * dt) >> 12;
actor->velocity.vy += (acceleration.vy * (ONE / dt) ) >> 24; actor->velocity.vy += (acceleration.vy * dt) >> 12;
actor->velocity.vz += (acceleration.vz * (ONE / dt) ) >> 24; actor->velocity.vz += (acceleration.vz * dt) >> 12;
//~ FntPrint("acc: %d %d %d\n", acceleration.vx / ONE, acceleration.vy / ONE, acceleration.vz / ONE ); //~ FntPrint("acc: %d %d %d\n", acceleration.vx / ONE, acceleration.vy / ONE, acceleration.vz / ONE );
actor->position.vx += (actor->velocity.vx * (ONE / dt) ) >> 12; actor->position.vx += (actor->velocity.vx * dt);
actor->position.vy += (actor->velocity.vy * (ONE / dt) ) >> 12; actor->position.vy += (actor->velocity.vy * dt);
actor->position.vz += (actor->velocity.vz * (ONE / dt) ) >> 12; actor->position.vz += (actor->velocity.vz * dt);
//~ FntPrint("vel: %d %d %d\n", actor->velocity.vx, actor->velocity.vy, actor->velocity.vz ); //~ FntPrint("vel: %d %d %d\n", actor->velocity.vx, actor->velocity.vy, actor->velocity.vz );
}; };
//~ // https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331 //~ // https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331