00001 #include "flGlobal.h"
00002 #if FL_CAMERA != 0
00003 #include <stdio.h>
00004 #include <psprtc.h>
00005 #include <pspkernel.h>
00006 #include <pspgu.h>
00007 #include <pspgum.h>
00008
00009 #if FL_INCLUDE_ALL_C == 0
00010 #include "flCamera.h"
00011 #include "flMemory.h"
00012 #include "flMath.h"
00013
00014 #if FL_DEBUG != 0
00015 #include "flDebug.h"
00016 #endif
00017 #endif
00018
00019 void camViewCalc(Camera* inCam) {
00020 while(inCam->camRot.y > MATH_PI)
00021 inCam->camRot.y -= (MATH_PI * 2.0f);
00022 while(inCam->camRot.y <= -MATH_PI)
00023 inCam->camRot.y += (MATH_PI * 2.0f);
00024
00025 while(inCam->camRot.x > MATH_PI)
00026 inCam->camRot.x -= (MATH_PI * 2.0f);
00027 while(inCam->camRot.x <= -MATH_PI)
00028 inCam->camRot.x += (MATH_PI * 2.0f);
00029
00030 while(inCam->camRot.z > MATH_PI)
00031 inCam->camRot.z -= (MATH_PI * 2.0f);
00032 while(inCam->camRot.z <= -MATH_PI)
00033 inCam->camRot.z += (MATH_PI * 2.0f);
00034
00035 inCam->camView.x = (mathSinf(inCam->camRot.x) * mathCosf(inCam->camRot.y));
00036 inCam->camView.y = (mathCosf(inCam->camRot.x) * mathCosf(inCam->camRot.y));
00037 inCam->camView.z = mathSinf(inCam->camRot.y);
00038
00039 inCam->camUp.x = (mathCosf(inCam->camRot.x) * mathSinf(inCam->camRot.z));
00040 inCam->camUp.y = (mathSinf(inCam->camRot.x) * mathSinf(inCam->camRot.z));
00041 inCam->camUp.z = mathCosf(inCam->camRot.z);
00042 }
00043
00044 Camera* camCreate() {
00045 Camera* tempOut = memAlloc(sizeof(Camera));
00046 if(!tempOut) {
00047 #if FL_DEBUG_WARNING != 0
00048 debugWarning("Couldn't create camera\nProbably out of memory.");
00049 #endif
00050 return NULL;
00051 }
00052 camReset(tempOut);
00053 return tempOut;
00054 }
00055
00056 void camFree(Camera* inCam) {
00057 #if FL_MEMORY == 0
00058 if(!inCam)
00059 return;
00060 #endif
00061 memFree(inCam);
00062 }
00063
00064 void camReset(Camera* inCam) {
00065 inCam->camPos = (vect3f){ 0.0f, 0.0f, 0.0f };
00066 inCam->camView = (vect3f){ 0.0f, 1.0f, 0.0f };
00067 inCam->camUp = (vect3f){ 0.0f, 0.0f, 1.0f };
00068 inCam->camRot = (vect3f){ 0.0f, 0.0f, 0.0f };
00069 }
00070
00071 void camView(Camera* inCam) {
00072 if(!inCam)
00073 return;
00074
00075 sceGumMatrixMode(GU_VIEW);
00076 sceGumLoadIdentity();
00077
00078 camViewCalc(inCam);
00079
00080 sceGumLookAt(&inCam->camPos, &(vect3f_Add(inCam->camPos, inCam->camView)), &inCam->camUp);
00081 sceGumUpdateMatrix();
00082 sceGumMatrixMode(GU_MODEL);
00083 }
00084
00085 void camMove(Camera* inCam, vect3f inMove) {
00086 if(!inCam)
00087 return;
00088 inCam->camPos = vect3f_Add(inCam->camPos, inMove);
00089 }
00090
00091 void camMoveTo(Camera* inCam, vect3f inTarget) {
00092 if(!inCam)
00093 return;
00094 vect3f tempMove = vect3f_Sub(inTarget, inCam->camPos);
00095 camMove(inCam, tempMove);
00096 }
00097
00098 void camMoveForward(Camera* inCam, float inSize) {
00099 if(!inCam)
00100 return;
00101 camViewCalc(inCam);
00102 vect3f tempMove;
00103 tempMove.x = (inCam->camView.x * inSize);
00104 tempMove.y = (inCam->camView.y * inSize);
00105 tempMove.z = (inCam->camView.z * inSize);
00106 camMove(inCam, tempMove);
00107 }
00108
00109 void camMoveStrafe(Camera* inCam, float inSize) {
00110 if(!inCam)
00111 return;
00112
00113 camViewCalc(inCam);
00114
00115 vect3f tempMove;
00116
00117 tempMove.x = (mathCosf(inCam->camRot.x) * mathCosf(inCam->camRot.z)) + (mathSinf(inCam->camRot.y) * mathSinf(inCam->camRot.z));
00118 tempMove.y = (-mathSinf(inCam->camRot.x) * mathCosf(inCam->camRot.z)) + (mathSinf(inCam->camRot.x) * mathSinf(inCam->camRot.z));
00119 tempMove.z = (-mathSinf(inCam->camRot.z) * mathCosf(inCam->camRot.y));
00120
00121 tempMove.x *= inSize;
00122 tempMove.y *= inSize;
00123 tempMove.z *= inSize;
00124
00125 camMove(inCam, tempMove);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 #endif