2021-04-10 14:22:48 +02:00
|
|
|
// 3dcam
|
|
|
|
// With huge help from :
|
|
|
|
// @NicolasNoble : https://discord.com/channels/642647820683444236/646765703143227394/796876392670429204
|
|
|
|
// @Lameguy64
|
|
|
|
// @Impiaa
|
|
|
|
// @paul
|
|
|
|
|
|
|
|
|
|
|
|
/* PSX screen coordinate system
|
|
|
|
*
|
|
|
|
* Z+
|
|
|
|
* /
|
|
|
|
* /
|
|
|
|
* +------X+
|
|
|
|
* /|
|
|
|
|
* / |
|
|
|
|
* / Y+
|
|
|
|
* eye */
|
|
|
|
|
|
|
|
// Blender debug mode
|
|
|
|
// bpy. app. debug = True
|
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
#define _WCHAR_T
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
#include "psx.h"
|
2021-04-18 23:41:28 +02:00
|
|
|
#include "pad.h"
|
2021-04-10 14:22:48 +02:00
|
|
|
#include "math.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "physics.h"
|
|
|
|
#include "graphics.h"
|
|
|
|
#include "space.h"
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
//~ #define USECD
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-13 16:52:48 +02:00
|
|
|
// START OVERLAY
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
extern u_long load_all_overlays_here;
|
2021-04-26 12:08:34 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
extern u_long __lvl0_end;
|
2021-04-26 12:08:34 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
extern u_long __lvl1_end;
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
u_long overlaySize = 0;
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ #define LLEVEL 0
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-14 15:56:14 +02:00
|
|
|
//#define USE_POINTER
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ #if LLEVEL == 0
|
2021-04-15 18:18:39 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ static const char*const overlayFile = "\\level0.bin;1";
|
2021-04-15 18:18:39 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ #else
|
2021-04-15 18:18:39 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ static const char*const overlayFile = "\\level1.bin;1";
|
2021-04-15 18:18:39 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ #endif
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-13 16:52:48 +02:00
|
|
|
//~ #ifdef USE_POINTER
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-14 15:56:14 +02:00
|
|
|
//~ #if LEVEL == 0
|
2021-04-13 16:52:48 +02:00
|
|
|
//~ #include "levels/level.h"
|
|
|
|
//~ #else
|
|
|
|
//~ #include "levels/level1.h"
|
|
|
|
//~ #endif
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-13 16:52:48 +02:00
|
|
|
//~ #else
|
2021-04-14 15:56:14 +02:00
|
|
|
//~ #define str (char*)(&__load_start_ovly0)
|
2021-04-13 16:52:48 +02:00
|
|
|
//~ #endif
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-14 15:56:14 +02:00
|
|
|
// END OVERLAY
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
#include "levels/level0.h"
|
|
|
|
|
2021-04-14 15:56:14 +02:00
|
|
|
#include "levels/level1.h"
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
uint8_t level = 1;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
uint16_t levelHasChanged = 0;
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
static char* overlayFile;
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
// Display and draw environments, double buffered
|
|
|
|
|
|
|
|
DISPENV disp[2];
|
|
|
|
|
|
|
|
DRAWENV draw[2];
|
|
|
|
|
|
|
|
//~ // OT for BG/FG discrimination
|
|
|
|
|
|
|
|
u_long otdisc[2][OT2LEN] = {0};
|
|
|
|
|
|
|
|
// Main OT
|
|
|
|
|
|
|
|
u_long ot[2][OTLEN] = {0}; // Ordering table (contains addresses to primitives)
|
|
|
|
|
|
|
|
char primbuff[2][PRIMBUFFLEN] = {0}; // Primitive list // That's our prim buffer
|
|
|
|
|
|
|
|
int primcnt=0; // Primitive counter
|
|
|
|
|
|
|
|
char * nextpri = primbuff[0]; // Primitive counter
|
|
|
|
|
|
|
|
char db = 0; // Current buffer counter
|
|
|
|
|
|
|
|
|
|
|
|
CVECTOR BGc = {50, 50, 75, 0}; // Far color
|
|
|
|
|
2021-04-13 16:52:48 +02:00
|
|
|
VECTOR BKc = {128, 128, 128, 0}; // Back color
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
MATRIX rotlgt;
|
|
|
|
|
|
|
|
SVECTOR lgtang = {0, 0, 0};
|
|
|
|
|
|
|
|
MATRIX light;
|
|
|
|
|
|
|
|
short vs;
|
|
|
|
|
|
|
|
CAMERA camera = {0};
|
|
|
|
|
|
|
|
// physics
|
|
|
|
|
|
|
|
long time = 0;
|
|
|
|
|
|
|
|
//Pad
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
Controller_Buffer controllers[2]; // Buffers for reading controllers
|
|
|
|
|
|
|
|
Controller_Data theControllers[8]; // Processed controller data
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
int pressed = 0;
|
|
|
|
|
|
|
|
u_short timer = 0;
|
|
|
|
|
|
|
|
// Cam stuff
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
int camMode = 0;
|
|
|
|
|
|
|
|
VECTOR angle = {250,0,0,0};
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
VECTOR angleCam = {0,0,0,0};
|
|
|
|
|
|
|
|
int dist = 150;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
int lerping = 0;
|
|
|
|
|
|
|
|
short curCamAngle = 0;
|
|
|
|
|
|
|
|
// Inverted Cam coordinates for Forward Vector calc
|
|
|
|
|
|
|
|
VECTOR InvCamPos = {0,0,0,0};
|
|
|
|
|
|
|
|
VECTOR fVecActor = {0,0,0,0};
|
|
|
|
|
|
|
|
u_long triCount = 0;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
// Default level : Initialize everything to 0
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
MATRIX cmat = {0}, lgtmat = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
MESH actorPtr = {0}, levelPtr = {0} , propPtr = {0}, meshes[] = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
int meshes_length = 0;
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
NODE curNode = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
CAMPATH camPath = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
CAMANGLE camPtr = {0}, camAngles[] = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
MESH meshPlan = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
VECTOR modelPlan_pos = {0};
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LEVEL curLvl = {
|
2021-04-27 17:12:00 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
&cmat,
|
2021-04-27 17:12:00 +02:00
|
|
|
|
|
|
|
&lgtmat,
|
|
|
|
|
|
|
|
(MESH **)&meshes,
|
|
|
|
|
|
|
|
&meshes_length,
|
|
|
|
|
|
|
|
&actorPtr,
|
|
|
|
|
|
|
|
&levelPtr,
|
|
|
|
|
|
|
|
&propPtr,
|
|
|
|
|
|
|
|
&camPtr,
|
|
|
|
|
|
|
|
&camPath,
|
|
|
|
|
|
|
|
(CAMANGLE **)&camAngles,
|
|
|
|
|
|
|
|
&curNode,
|
|
|
|
|
|
|
|
&meshPlan
|
2021-04-16 20:22:03 +02:00
|
|
|
};
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
// Pad
|
|
|
|
|
|
|
|
void callback();
|
|
|
|
|
|
|
|
int main() {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
if ( level == 0 ){
|
|
|
|
|
|
|
|
overlayFile = "\\level0.bin;1";
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
overlaySize = __lvl0_end;
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
} else if ( level == 1) {
|
|
|
|
|
|
|
|
overlayFile = "\\level1.bin;1";
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
overlaySize = __lvl1_end;
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Load overlay
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
#ifdef USECD
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-15 18:18:39 +02:00
|
|
|
CdInit();
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
LoadLevelCD(overlayFile, &load_all_overlays_here);
|
2021-04-15 18:18:39 +02:00
|
|
|
|
|
|
|
#endif
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
// TODO : Add switch case to get the correct pointers
|
|
|
|
// Get needed pointers from level file
|
2021-04-13 16:52:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
if ( level == 0 ) {
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LvlPtrSet( &curLvl, &level0);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
} else if ( level == 1) {
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LvlPtrSet( &curLvl, &level1);
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 15:56:14 +02:00
|
|
|
// Overlay
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
VECTOR sp = {CENTERX,CENTERY,0};
|
|
|
|
|
|
|
|
VECTOR wp = {0,0,0};
|
|
|
|
|
|
|
|
// FIXME : Poly subdiv
|
|
|
|
|
|
|
|
//~ DIVPOLYGON4 div4 = { 0 };
|
|
|
|
//~ div4.pih = SCREENXRES;
|
|
|
|
//~ div4.piv = SCREENYRES;
|
|
|
|
//~ div4.ndiv = 2;
|
|
|
|
//~ long OTc = 0;
|
|
|
|
|
|
|
|
//~ DIVPOLYGON3 div3 = { 0 };
|
|
|
|
//~ div3.pih = SCREENXRES;
|
|
|
|
//~ div3.piv = SCREENYRES;
|
|
|
|
//~ div3.ndiv = 1;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
init(disp, draw, db, curLvl.cmat, &BGc, &BKc);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
InitPAD(controllers[0].pad, 34, controllers[1].pad, 34);
|
|
|
|
|
|
|
|
StartPAD();
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
generateTable();
|
|
|
|
|
|
|
|
VSyncCallback(callback);
|
|
|
|
|
|
|
|
// Load textures
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for (int k = 0; k < *curLvl.meshes_length ; k++){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LoadTexture(curLvl.meshes[k]->tim_data, curLvl.meshes[k]->tim);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load current BG
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPtr->tim_data){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Physics
|
|
|
|
|
|
|
|
short physics = 1;
|
|
|
|
|
|
|
|
long dt;
|
|
|
|
|
|
|
|
VECTOR col_lvl, col_sphere, col_sphere_act = {0};
|
|
|
|
|
|
|
|
// Cam stuff
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// Sprite system
|
|
|
|
|
|
|
|
VECTOR posToCam = {0, 0, 0, 0};
|
|
|
|
|
|
|
|
VECTOR objAngleToCam = {0, 0, 0, 0};
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
//~ int angle = 0; //PSX units = 4096 == 360° = 2Pi
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
//PSX units
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
short timediv = 1;
|
|
|
|
|
|
|
|
int atime = 0;
|
|
|
|
|
|
|
|
// Polycount
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for (int k = 0; k < *curLvl.meshes_length; k++){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
triCount += curLvl.meshes[k]->tmesh->len;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set camera starting pos
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Find curCamAngle if using pre-calculated BGs
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
if (camMode == 2) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPtr->tim_data){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
curCamAngle = 1;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main loop
|
|
|
|
|
|
|
|
//~ while (1) {
|
|
|
|
|
|
|
|
while ( VSync(1) ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (levelHasChanged){
|
2021-04-27 17:12:00 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
switch (level){
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
case 0:
|
|
|
|
|
|
|
|
overlayFile = "\\level0.bin;1";
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
overlaySize = __lvl0_end;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
break;
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
case 1:
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
overlayFile = "\\level1.bin;1";
|
2021-04-26 12:08:34 +02:00
|
|
|
|
|
|
|
overlaySize = __lvl1_end;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
break;
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
default:
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
overlayFile = "\\level0.bin;1";
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:08:34 +02:00
|
|
|
#ifdef USECD
|
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
LoadLevelCD( overlayFile, &load_all_overlays_here );
|
2021-04-26 12:08:34 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
SwitchLevel( overlayFile, &load_all_overlays_here, &curLvl, &level0);
|
|
|
|
|
|
|
|
//~ printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile);
|
2021-04-20 16:45:11 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
levelHasChanged = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
FntPrint("Ovl:%s\nLvlch : %x\nLvl: %x %d", overlayFile, levelHasChanged, &levelHasChanged, level );
|
2021-04-20 16:45:11 +02:00
|
|
|
|
|
|
|
//~ FntPrint("%x\n", curLvl.actorPtr->tim);
|
2021-04-14 15:56:14 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
// Clear the main OT
|
|
|
|
|
|
|
|
ClearOTagR(otdisc[db], OT2LEN);
|
|
|
|
|
|
|
|
// Clear Secondary OT
|
|
|
|
|
|
|
|
ClearOTagR(ot[db], OTLEN);
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
// timeB = time;
|
|
|
|
|
|
|
|
time ++;
|
|
|
|
|
|
|
|
// atime is used for animations timing
|
|
|
|
|
|
|
|
timediv = 1;
|
|
|
|
|
|
|
|
if (time % timediv == 0){
|
|
|
|
|
|
|
|
atime ++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Angle between camera and actor
|
|
|
|
|
|
|
|
// using atantable (faster)
|
|
|
|
|
|
|
|
camAngleToAct.vy = (patan(-posToActor.vx, -posToActor.vz) / 16) - 3076 ;
|
|
|
|
|
|
|
|
camAngleToAct.vx = patan(dist, posToActor.vy) >> 4;
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
// Sprite system WIP
|
|
|
|
|
|
|
|
objAngleToCam.vy = patan( posToCam.vx,posToCam.vz );
|
|
|
|
|
|
|
|
objAngleToCam.vx = patan( posToCam.vx,posToCam.vy );
|
|
|
|
|
|
|
|
//~ objAngleToCam.vz = patan( posToCam.vz,posToCam.vy );
|
|
|
|
|
|
|
|
//~ objAngleToCam.vx = patan( psqrt(posToCam.vx * posToCam.vx + posToCam.vy * posToCam.vy), posToCam.vy );
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ curLvl.meshPlan.rot->vx = -( (objAngleToCam.vx >> 4) - 3076 ) ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ curLvl.meshPlan.rot->vx = (( (objAngleToCam.vx >> 4) - 3076 ) * ( (objAngleToCam.vz >> 4) - 3076 ) >> 12) * (nsin(posToCam.vz) >> 10 < 0 ? -1 : 1);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ curLvl.meshPlan.rot->vx = ( (objAngleToCam.vx >> 4) - 3076 ) * ( (objAngleToCam.vz >> 4) - 3076 ) >> 12 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshPlan->rot.vy = -( (objAngleToCam.vy >> 4) + 1024 ) ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ posToCam = getVectorTo(*curLvl.meshPlan.pos, camera.pos);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ posToCam = getVectorTo(camera.pos, *curLvl.meshPlan.pos);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToCam.vx = -camera.pos.vx - curLvl.meshPlan->pos.vx ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToCam.vz = -camera.pos.vz - curLvl.meshPlan->pos.vz ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToCam.vy = -camera.pos.vy - curLvl.meshPlan->pos.vy ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ psqrt(posToCam.vx * posToCam.vx + posToCam.vy * posToCam.vy);
|
|
|
|
|
|
|
|
// Actor Forward vector for 3d relative orientation
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
fVecActor = curLvl.actorPtr->pos;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
fVecActor.vx = curLvl.actorPtr->pos.vx + (nsin(curLvl.actorPtr->rot.vy/2));
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
fVecActor.vz = curLvl.actorPtr->pos.vz - (ncos(curLvl.actorPtr->rot.vy/2));
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Camera modes
|
|
|
|
|
|
|
|
if(camMode != 2) {
|
|
|
|
|
|
|
|
camera.rot.vy = camAngleToAct.vy;
|
|
|
|
|
|
|
|
// using csin/ccos, no need for theta
|
|
|
|
|
|
|
|
//~ camera.rot.vy = angle;
|
|
|
|
|
|
|
|
camera.rot.vx = camAngleToAct.vx;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(camMode < 4 ) {
|
|
|
|
|
|
|
|
lerping = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Camera follows actor with lerp for rotations
|
|
|
|
|
|
|
|
if(camMode == 0) {
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
dist = 200;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
camera.pos.vx = -(camera.x/ONE);
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
camera.pos.vy = -(camera.y/ONE);
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
camera.pos.vz = -(camera.z/ONE);
|
|
|
|
|
|
|
|
//~ InvCamPos.vx = camera.x/ONE;
|
|
|
|
|
|
|
|
//~ InvCamPos.vz = camera.z/ONE;
|
|
|
|
|
|
|
|
//~ applyVector(&InvCamPos, -1,-1,-1, *=);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
angle.vy = -(curLvl.actorPtr->rot.vy / 2) + angleCam.vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
//~ angle.vx += 10;
|
|
|
|
|
|
|
|
//~ FntPrint("cos %d", (ncos(angle.vy) * ncos(angle.vx)) >> 12);
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ angle = curLvl.actorPtr->rot->vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
// Camera horizontal position
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
getCameraZY(&camera.z, &camera.y, curLvl.actorPtr->pos.vz, curLvl.actorPtr->pos.vy, angle.vx, dist);
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
getCameraXZ(&camera.x, &camera.z, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, angle.vy, dist);
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ getCameraXZY(&camera.x, &camera.z, &camera.y, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, curLvl.actorPtr->pos.vy, angle.vy, angle.vx, dist);
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
//~ void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance) {
|
|
|
|
|
|
|
|
// Camera vertical position
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ getCameraXZ(&camera.x, &camera.y, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vy, angle, dist);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// FIXME! camera lerping to pos
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ angle += lerp(camera.rot.vy, -curLvl.actorPtr->rot->vy, 128);
|
|
|
|
//~ angle = lerpD(camera.rot.vy << 12, curLvl.actorPtr->rot->vy << 12, 1024 << 12) >> 12;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Camera rotates continuously around actor
|
|
|
|
|
|
|
|
if (camMode == 1) {
|
|
|
|
|
|
|
|
dist = 150;
|
|
|
|
|
|
|
|
camera.pos.vx = -(camera.x/ONE);
|
|
|
|
|
|
|
|
//~ camera.pos.vy = -(camera.y/ONE);
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
camera.pos.vy = 100;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
camera.pos.vz = -(camera.z/ONE);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ fVecActor = *curLvl.actorPtr->pos;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ fVecActor.vx = curLvl.actorPtr->pos->vx + (nsin(curLvl.actorPtr->rot->vy));
|
|
|
|
//~ fVecActor.vz = curLvl.actorPtr->pos->vz - (ncos(curLvl.actorPtr->rot->vy));
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
getCameraXZ(&camera.x, &camera.z, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, angle.vy, dist);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
angle.vy += 10;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed Camera with actor tracking
|
|
|
|
if (camMode == 3) {
|
|
|
|
|
|
|
|
// Using precalc sqrt
|
|
|
|
|
|
|
|
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz) );
|
|
|
|
|
|
|
|
camera.pos.vx = 190;
|
|
|
|
|
|
|
|
camera.pos.vz = 100;
|
|
|
|
|
|
|
|
camera.pos.vy = 180;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed Camera angle
|
|
|
|
if (camMode == 2) {
|
|
|
|
|
|
|
|
|
|
|
|
// If BG images exist
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPtr->tim_data){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.camAngles[ curCamAngle ]->fw.v0.vx ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ FntPrint("BL x : %d, y : %d\n", camAngles[ curCamAngle ]->fw.v3.vx, camAngles[ curCamAngle ]->fw.v3.vy);
|
|
|
|
//~ FntPrint("BR x : %d, y : %d\n", camAngles[ curCamAngle ]->fw.v2.vx, camAngles[ curCamAngle ]->fw.v2.vy);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->fw.v3, &camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->bw.v2, &camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) );
|
2021-04-10 14:22:48 +02:00
|
|
|
// If actor in camAngle->fw area of screen
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) == -1 &&
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
( checkLineW( &curLvl.camAngles[ curCamAngle ]->bw.v2, &curLvl.camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) >= 0
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (curCamAngle < 5) {
|
|
|
|
|
|
|
|
curCamAngle++;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.camAngles[ curCamAngle ]->bw.v0.vx ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ FntPrint("BL x : %d, y : %d\n", camAngles[ curCamAngle ]->bw.v3.vx, camAngles[ curCamAngle ]->bw.v3.vy);
|
|
|
|
|
|
|
|
//~ FntPrint("BR x : %d, y : %d\n", camAngles[ curCamAngle ]->bw.v2.vx, camAngles[ curCamAngle ]->bw.v2.vy);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ // FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->bw.v2, &camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// If actor in camAngle->bw area of screen
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) >= 0 &&
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
checkLineW( &curLvl.camAngles[ curCamAngle ]->bw.v2, &curLvl.camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) == -1
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (curCamAngle > 0) {
|
|
|
|
|
|
|
|
curCamAngle--;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flyby mode with LERP from camStart to camEnd
|
|
|
|
|
|
|
|
if (camMode == 4) {
|
|
|
|
|
|
|
|
// If key pos exist for camera
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPath->len) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Lerping sequence has not begun
|
|
|
|
|
|
|
|
if (!lerping){
|
|
|
|
|
|
|
|
// Set cam start position ( first key pos )
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vx = curLvl.camPath->points[curLvl.camPath->cursor].vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vy = curLvl.camPath->points[curLvl.camPath->cursor].vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vz = curLvl.camPath->points[curLvl.camPath->cursor].vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Lerping sequence is starting
|
|
|
|
lerping = 1;
|
|
|
|
|
|
|
|
// Set cam pos index to 0
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pre calculated sqrt ( see psqrt() )
|
|
|
|
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz));
|
|
|
|
|
|
|
|
// Fixed point precision 2^12 == 4096
|
|
|
|
|
|
|
|
int precision = 12;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vx = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vx << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vx << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vy = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vy << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vy << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vz = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vz << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vz << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("Cam %d, %d\n", (int32_t)curLvl.camPath->points[curLvl.camPath->cursor].vx, curLvl.camPath->points[curLvl.camPath->cursor+1].vx);
|
2021-04-10 14:22:48 +02:00
|
|
|
//~ FntPrint("Cam %d, %d, %d\n", camera.pos.vx, camera.pos.vy, camera.pos.vz);
|
|
|
|
//~ FntPrint("Theta y: %d x: %d\n", theta.vy, theta.vx);
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("Pos: %d Cur: %d\nTheta y: %d x: %d\n", curLvl.camPath->pos, curLvl.camPath->cursor, theta.vy, theta.vx);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Linearly increment the lerp factor
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos += 20;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// If camera has reached next key pos, reset pos index, move cursor to next key pos
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPath->pos > (1 << precision) ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor ++;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last key pos is reached, reset cursor to first key pos, lerping sequence is over
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.camPath->cursor == curLvl.camPath->len - 1 ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
lerping = 0;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if no key pos exists, switch to next camMode
|
|
|
|
|
|
|
|
camMode ++; }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Camera "on a rail" - cam is tracking actor, and moving with constraints on all axis
|
|
|
|
|
|
|
|
if (camMode == 5) {
|
|
|
|
|
|
|
|
// track actor. If theta (actor/cam rotation angle) is above or below an arbitrary angle,
|
|
|
|
// move cam so that the angle doesn't increase/decrease anymore.
|
|
|
|
|
|
|
|
short cameraSpeed = 40;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPath->len) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Lerping sequence has not begun
|
|
|
|
|
|
|
|
if (!lerping){
|
|
|
|
|
|
|
|
// Set cam start position ( first key pos )
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vx = curLvl.camPath->points[curLvl.camPath->cursor].vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vy = curLvl.camPath->points[curLvl.camPath->cursor].vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vz = curLvl.camPath->points[curLvl.camPath->cursor].vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Lerping sequence is starting
|
|
|
|
|
|
|
|
lerping = 1;
|
|
|
|
|
|
|
|
// Set cam pos index to 0
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pre calculated sqrt ( see psqrt() )
|
|
|
|
|
|
|
|
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz));
|
|
|
|
|
|
|
|
// Fixed point precision 2^12 == 4096
|
|
|
|
|
|
|
|
short precision = 12;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vx = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vx << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vx << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vy = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vy << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vy << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
camera.pos.vz = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vz << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vz << precision, curLvl.camPath->pos << precision) >> precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ FntPrint("%d %d %d %d\n", camAngleToAct.vy, camera.pos.vx, camera.rot.vy, dist);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
// Ony move cam if position is between first curLvl.camPath->vx and last curLvl.camPath->vx
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( camAngleToAct.vy < -50 && camera.pos.vx > curLvl.camPath->points[curLvl.camPath->len - 1].vx ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
// Clamp curLvl.camPath position to cameraSpeed
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos += dist < cameraSpeed ? 0 : cameraSpeed ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( camAngleToAct.vy > 50 && camera.pos.vx > curLvl.camPath->points[curLvl.camPath->cursor].vx ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos -= dist < cameraSpeed ? 0 : cameraSpeed;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// If camera has reached next key pos, reset pos index, move cursor to next key pos
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPath->pos > (1 << precision) ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor ++;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.camPath->pos < -100 ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->pos = 1 << precision;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor --;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last key pos is reached, reset cursor to first key pos, lerping sequence is over
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.camPath->cursor == curLvl.camPath->len - 1 || curLvl.camPath->cursor < 0 ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
lerping = 0;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if no key pos exists, switch to next camMode
|
|
|
|
|
|
|
|
camMode ++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spatial partitioning
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.curNode){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Actor
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( !getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vx &&
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
!getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vz )
|
2021-04-16 20:22:03 +02:00
|
|
|
{
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.curNode != curLvl.curNode->siblings->list[msh] ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.curNode = curLvl.curNode->siblings->list[msh];
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.levelPtr = curLvl.curNode->plane;
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// DONTNEED ?
|
|
|
|
// Moveable prop
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ if ( !getIntCollision( *propPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vx &&
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ !getIntCollision( *propPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vz ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ if ( propPtr->node != curLvl.curNode->siblings->list[ msh ]){
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ propPtr->node = curLvl.curNode->siblings->list[ msh ];
|
2021-04-16 20:22:03 +02:00
|
|
|
//~ }
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ }
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( !getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vx &&
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
!getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vz ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->node = curLvl.curNode;
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Physics
|
|
|
|
|
|
|
|
if ( physics ) {
|
|
|
|
|
|
|
|
// if(time%1 == 0){
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int k = 0; k < *curLvl.meshes_length; k ++ ) {
|
|
|
|
//~ for ( int k = 0; k < curLvl.curNode->objects->index ; k ++){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( ( curLvl.meshes[k]->isRigidBody == 1 ) ) {
|
|
|
|
//~ if ( ( *curLvl.curNode->rigidbodies->list[k]->isRigidBody == 1 ) ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ applyAcceleration(curLvl.curNode->rigidbodies->list[k]->body);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
applyAcceleration( curLvl.meshes[k]->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Get col with level ( modelgnd_body )
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
col_lvl = getIntCollision( *curLvl.meshes[k]->body , *curLvl.levelPtr->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
col_sphere = getIntCollision( *curLvl.propPtr->body, *curLvl.propPtr->node->plane->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// col_sphere = getIntCollision( *propPtr->body, *levelPtr->body );
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
col_sphere_act = getExtCollision( *curLvl.actorPtr->body, *curLvl.propPtr->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// If no col with ground, fall off
|
|
|
|
|
|
|
|
if ( col_lvl.vy ) {
|
|
|
|
|
|
|
|
if ( !col_lvl.vx && !col_lvl.vz ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->position.vy = curLvl.actorPtr->body->min.vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col_sphere.vy){
|
|
|
|
|
|
|
|
if ( !col_sphere.vx && !col_sphere.vz ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->body->position.vy = curLvl.propPtr->body->min.vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (col_sphere_act.vx && col_sphere_act.vz ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->body->velocity.vx += curLvl.actorPtr->body->velocity.vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->body->velocity.vz += curLvl.actorPtr->body->velocity.vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.propPtr->body->velocity.vx ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
VECTOR L = angularMom( *curLvl.propPtr->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->rot.vz -= L.vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( curLvl.propPtr->body->velocity.vz ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
VECTOR L = angularMom( *curLvl.propPtr->body );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.propPtr->rot.vx -= L.vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->pos.vx = curLvl.meshes[k]->body->position.vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->pos.vy = curLvl.meshes[k]->body->position.vy ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->pos.vz = curLvl.meshes[k]->body->position.vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->body->velocity.vy = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->body->velocity.vx = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.meshes[k]->body->velocity.vz = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( (camMode == 2) && (curLvl.camPtr->tim_data ) ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
worldToScreen( &curLvl.actorPtr->pos, &curLvl.actorPtr->pos2D );
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Camera setup
|
|
|
|
|
|
|
|
// position of cam relative to actor
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToActor.vx = curLvl.actorPtr->pos.vx + camera.pos.vx;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToActor.vz = curLvl.actorPtr->pos.vz + camera.pos.vz;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
posToActor.vy = curLvl.actorPtr->pos.vy + camera.pos.vy;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
// Polygon drawing
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.curNode){
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
static long Flag;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if ( (camMode == 2) && (curLvl.camPtr->tim_data ) ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawBG(curLvl.camPtr, &nextpri, otdisc[db], &db);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Loop on camAngles
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int mesh = 0 ; mesh < curLvl.camAngles[ curCamAngle ]->index; mesh ++ ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
transformMesh(&camera, curLvl.camAngles[curCamAngle]->objects[mesh]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly(curLvl.camAngles[curCamAngle]->objects[mesh], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
// int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Draw current node's plane
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly( curLvl.curNode->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Draw surrounding planes
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly(curLvl.curNode->siblings->list[ sibling ]->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw adjacent planes's children
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int object = 0; object < curLvl.curNode->siblings->list[ sibling ]->objects->index; object++ ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
long t = 0;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
transformMesh(&camera, curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly( curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw current plane children
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int object = 0; object < curLvl.curNode->objects->index; object++ ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
transformMesh(&camera, curLvl.curNode->objects->list[ object ]);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly( curLvl.curNode->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
// Draw rigidbodies
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
for ( int object = 0; object < curLvl.curNode->rigidbodies->index; object++ ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
transformMesh(&camera, curLvl.curNode->rigidbodies->list[ object ]);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
drawPoly( curLvl.curNode->rigidbodies->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
}
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
}
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find and apply light rotation matrix
|
|
|
|
|
|
|
|
RotMatrix(&lgtang, &rotlgt);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
MulMatrix0(curLvl.lgtmat, &rotlgt, &light);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
SetLightMatrix(&light);
|
|
|
|
|
|
|
|
// Set camera
|
|
|
|
|
|
|
|
applyCamera(&camera);
|
|
|
|
|
|
|
|
// Add secondary OT to main OT
|
|
|
|
|
|
|
|
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("curLvl.curNode : %x\nIndex: %d", curLvl.curNode, curLvl.curNode->siblings->index);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
FntPrint("Time : %d dt :%d\n", VSync(-1) / 60, dt);
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
//~ FntPrint("%d\n", curCamAngle );
|
|
|
|
//~ FntPrint("%x\n", primbuff[db]);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("Actor : %d %d\n", curLvl.actorPtr->pos->vx, curLvl.actorPtr->pos->vy);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("%d %d\n", curLvl.actorPtr->pos->vx, curLvl.actorPtr->pos->vz);
|
|
|
|
//~ FntPrint("%d %d\n", curLvl.actorPtr->pos2D.vx + CENTERX, curLvl.actorPtr->pos2D.vy + CENTERY);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
//~ FntPrint(" %d %d %d\n", wp.vx, wp.vy, wp.vz);
|
|
|
|
|
|
|
|
FntFlush(-1);
|
|
|
|
|
|
|
|
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
|
|
|
|
//~ display(disp, draw, otdisc[db], primbuff[db], nextpri, db);
|
|
|
|
|
|
|
|
//~ frame = VSync(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void callback() {
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
// Pad 1
|
|
|
|
|
|
|
|
read_controller( &theControllers[0], &controllers[0].pad[0], 0 ); // Read controllers
|
|
|
|
|
|
|
|
// Pad 2
|
|
|
|
|
|
|
|
read_controller( &theControllers[1], &controllers[1].pad[0], 1 );
|
|
|
|
|
|
|
|
//~ u_short pad = PadRead(0);
|
|
|
|
|
|
|
|
//~ u_short pad = 0;
|
|
|
|
|
|
|
|
u_char PADL = ~theControllers[0].button1;
|
|
|
|
|
|
|
|
u_char PADR = ~theControllers[0].button2;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
static u_short lastPad;
|
|
|
|
|
|
|
|
static short forceApplied = 0;
|
|
|
|
|
|
|
|
int div = 32;
|
|
|
|
|
|
|
|
static int lerpValues[4096 >> 7];
|
|
|
|
|
|
|
|
static short cursor = 0;
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
static short angleCamTimer = 0;
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
//~ static short curCamAngle = 0;
|
|
|
|
|
|
|
|
if( !lerpValues[0] ) {
|
|
|
|
|
|
|
|
for ( long long i = 0; i < div ; i++ ){
|
|
|
|
|
|
|
|
lerpValues[(div-1)-i] = lerp(-24, -264, easeIn(i));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( timer ) {
|
|
|
|
|
|
|
|
timer--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if( cursor ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
cursor--;
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (angleCam.vy > 2048 || angleCam.vy < -2048) {
|
|
|
|
|
|
|
|
angleCam.vy = 0;
|
|
|
|
|
|
|
|
}
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadShldR1 && !timer ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (!curLvl.camPtr->tim_data){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
if(camMode < 6){
|
|
|
|
|
|
|
|
camMode ++;
|
|
|
|
|
|
|
|
lerping = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPath->cursor = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
camMode = 0;
|
|
|
|
|
|
|
|
lerping = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (curCamAngle > 4) {
|
|
|
|
|
|
|
|
curCamAngle = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curCamAngle < 5) {
|
|
|
|
|
|
|
|
curCamAngle++;
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADR;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
timer = 10;
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
//~ if ( !(PADR & PadShldR1) && lastPad & PadShldR1 ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
//pressed = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
//~ }
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadShldL2 ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
lgtang.vy += 32;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadShldL1 ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
lgtang.vz += 32;
|
|
|
|
|
|
|
|
}
|
2021-04-26 12:08:34 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadUp && !timer ){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.actorPtr->isPrism){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->isPrism = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->isPrism = 1;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = 10;
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADR;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadDown && !timer ){
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.actorPtr->body->gForce.vy >= 0 && curLvl.actorPtr->body->position.vy >= curLvl.actorPtr->body->min.vy ){
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
forceApplied -= 150;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
cursor = div - 15;
|
|
|
|
|
|
|
|
timer = 30;
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADR;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( !(PADR & PadDown) && lastPad & PadDown ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
//~ lastPad = pad;
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADR & PadLeft && !timer ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
if (curLvl.actorPtr->anim->interpolate){
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->anim->interpolate = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->anim->interpolate = 1;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = 10;
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADR;
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if (theControllers[0].type == 0x73){
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
// Analog stick L up
|
|
|
|
|
|
|
|
if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < 108 ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * (128 - theControllers[0].analog3 ) >> 15 ;
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * (128 - theControllers[0].analog3 ) >> 15 ;
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
lastPad = PADL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Analog stick L down
|
|
|
|
|
2021-04-27 18:01:41 +02:00
|
|
|
if ( theControllers[0].analog3 > 168 && theControllers[0].analog3 <= 255 ) {
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * ( theControllers[0].analog3 - 128 ) >> 15 ;
|
2021-04-20 11:55:52 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * ( theControllers[0].analog3 - 128 ) >> 15 ;
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
lastPad = PADL;
|
|
|
|
}
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
// Analog stick L dead zone
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if ( theControllers[0].analog3 > 108 && theControllers[0].analog3 < 148 ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = 0;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = 0;
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
}
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
// Analog stick L left
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if ( theControllers[0].analog2 >= 0 && theControllers[0].analog2 < 108 ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->rot.vy -= ( 40 * ( 128 - theControllers[0].analog2 ) ) >> 7 ;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
}
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
// Analog stick L right
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if ( theControllers[0].analog2 > 148 && theControllers[0].analog2 <= 255 ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->rot.vy += ( 40 * ( theControllers[0].analog2 - 128 ) ) >> 7 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
}
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( PADL & PadUp ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz >> 8 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx >> 8 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( !(PADL & PadUp) && lastPad & PadUp) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = 0;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADL & PadDown ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz >> 8 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx >> 8 ;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( !( PADL & PadDown ) && lastPad & PadDown) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vz = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->gForce.vx = 0;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADL & PadLeft ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->rot.vy -= 32;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADL & PadRight ) {
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->rot.vy += 32;
|
2021-04-10 14:22:48 +02:00
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-10 14:22:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
if ( PADL & PadSelect && !timer ) {
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
if (!levelHasChanged){
|
|
|
|
|
2021-04-27 17:12:00 +02:00
|
|
|
//~ #ifndef USECD
|
|
|
|
|
|
|
|
printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile);
|
|
|
|
|
|
|
|
//~ #endif
|
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
level = !level;
|
|
|
|
|
|
|
|
levelHasChanged = 1;
|
|
|
|
}
|
2021-04-27 17:12:00 +02:00
|
|
|
|
2021-04-16 20:22:03 +02:00
|
|
|
timer = 30;
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
lastPad = PADL;
|
2021-04-16 20:22:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
if( theControllers[0].type == 0x73 && camMode == 0){
|
|
|
|
|
|
|
|
// Cam control - horizontal
|
|
|
|
|
|
|
|
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < 108) {
|
|
|
|
|
|
|
|
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
|
|
|
|
|
|
|
|
angleCamTimer = 120;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( theControllers[0].analog0 > 148 && theControllers[0].analog0 <= 255) {
|
|
|
|
|
|
|
|
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
|
|
|
|
|
|
|
|
angleCamTimer = 120;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < 108) {
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
|
|
|
|
|
|
|
|
angleCamTimer = 120;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( theControllers[0].analog0 > 148 && theControllers[0].analog0 <= 255) {
|
|
|
|
|
2021-04-20 11:55:52 +02:00
|
|
|
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
|
|
|
|
|
|
|
|
angleCamTimer = 120;
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
}
|
2021-04-20 11:55:52 +02:00
|
|
|
|
|
|
|
// Timer to lerp cam back behind actor
|
|
|
|
|
|
|
|
if ( angleCamTimer ){
|
|
|
|
|
|
|
|
angleCamTimer --;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!angleCamTimer && angleCam.vy){
|
|
|
|
|
|
|
|
angleCam.vy += lerp( angleCam.vy, 0, 64 ) == 0 ? 1 : lerp( angleCam.vy, 0, 64 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:41:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//~ FntPrint("level :%d", level);
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint("angleCam :%d %d\n", angleCam.vy, lerp( angleCam.vy, 0, 64) );
|
2021-04-18 23:41:28 +02:00
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
//~ FntPrint( "Pad 1 : %02x\nButtons:%02x %02x, Stick:%02d %02d %02d %02d\n",
|
|
|
|
//~ theControllers[0].type, // Controller type : 0x00 == none, 0x41 == standard, 0x73 == analog/dualshock, 0x12 == mouse, 0x23 == steering wheel, 0x63 == gun, 0x53 == analog joystick
|
|
|
|
//~ theControllers[0].button1, //
|
|
|
|
//~ theControllers[0].button2,
|
|
|
|
//~ theControllers[0].analog0, // R3 hor : left: 0 7F right: 7F FF dz 78 83
|
|
|
|
//~ theControllers[0].analog1, // R3 vert : up : 0 7F down : 7F FF : dz 83 86
|
|
|
|
//~ theControllers[0].analog2, // L3 hor : left : 0 7F right: 7F FF : dz 69 81 68 - 8E
|
|
|
|
//~ theControllers[0].analog3 ); // L3 vert : up : 0 7F down : 7F FF : dz 74 8D
|
2021-04-16 20:22:03 +02:00
|
|
|
|
2021-04-10 14:22:48 +02:00
|
|
|
if ( cursor ) {
|
|
|
|
|
2021-04-20 16:45:11 +02:00
|
|
|
curLvl.actorPtr->body->position.vy = lerpValues[cursor];}
|
2021-04-10 14:22:48 +02:00
|
|
|
|
|
|
|
};
|