fixed frustum culling, static game class
This commit is contained in:
+18
-16
@@ -30,13 +30,14 @@ extern u32 VU1Draw3D_CodeEnd __attribute__((section(".vudata")));
|
||||
|
||||
Engine::Engine()
|
||||
{
|
||||
SifInitRpc(0);
|
||||
srand(time(NULL));
|
||||
VU1::uploadProgram(0, &VU1Draw3D_CodeStart, &VU1Draw3D_CodeEnd);
|
||||
audio.startThread();
|
||||
isInitialized = 0;
|
||||
isScreenInitialized = 0;
|
||||
mainThreadId = GetThreadId();
|
||||
setDefaultScreen();
|
||||
firePS2();
|
||||
}
|
||||
|
||||
Engine::Engine(const ScreenSettings &t_screen)
|
||||
{
|
||||
screen = t_screen;
|
||||
firePS2();
|
||||
}
|
||||
|
||||
Engine::~Engine() {}
|
||||
@@ -45,12 +46,6 @@ Engine::~Engine() {}
|
||||
// Methods
|
||||
// ----
|
||||
|
||||
void Engine::setScreen(ScreenSettings &t_settings)
|
||||
{
|
||||
screen = t_settings;
|
||||
isScreenInitialized = true;
|
||||
}
|
||||
|
||||
void Engine::setDefaultScreen()
|
||||
{
|
||||
screen.projectionScale = 4096.0F;
|
||||
@@ -60,13 +55,10 @@ void Engine::setDefaultScreen()
|
||||
screen.aspectRatio = 4.0F / 3.0F;
|
||||
screen.width = 640.0F;
|
||||
screen.height = 480.0F;
|
||||
isScreenInitialized = true;
|
||||
}
|
||||
|
||||
void Engine::init(Game *t_game, u32 t_gifPacketSize)
|
||||
{
|
||||
if (!isScreenInitialized)
|
||||
setDefaultScreen();
|
||||
if (isInitialized)
|
||||
PRINT_ERR("Already initialized!");
|
||||
else
|
||||
@@ -88,6 +80,16 @@ void Engine::wakeup(s32 t_alarmId, u16 t_time, void *t_common)
|
||||
ExitHandler();
|
||||
}
|
||||
|
||||
void Engine::firePS2()
|
||||
{
|
||||
SifInitRpc(0);
|
||||
srand(time(NULL));
|
||||
VU1::uploadProgram(0, &VU1Draw3D_CodeStart, &VU1Draw3D_CodeEnd);
|
||||
audio.startThread();
|
||||
isInitialized = 0;
|
||||
mainThreadId = GetThreadId();
|
||||
}
|
||||
|
||||
void Engine::gameLoop()
|
||||
{
|
||||
for (;;)
|
||||
|
||||
@@ -24,12 +24,12 @@ class Engine
|
||||
{
|
||||
|
||||
public:
|
||||
Engine(const ScreenSettings &screen);
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
void init(Game *t_game, u32 t_gifPacketSize);
|
||||
void setDefaultScreen();
|
||||
void setScreen(ScreenSettings &t_settings);
|
||||
Renderer *renderer;
|
||||
Audio audio;
|
||||
ScreenSettings screen;
|
||||
@@ -37,9 +37,10 @@ public:
|
||||
float fps;
|
||||
|
||||
private:
|
||||
void firePS2();
|
||||
u8 fpsDelayer;
|
||||
Timer timer;
|
||||
u8 isInitialized, isScreenInitialized;
|
||||
u8 isInitialized;
|
||||
void gameLoop();
|
||||
Game *game;
|
||||
s32 mainThreadId;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
void makeZRotation(float t_radians);
|
||||
void translate(float t_x, float t_y, float t_z);
|
||||
void setPerspective(ScreenSettings &screen);
|
||||
void print();
|
||||
const void print() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
void update(Vector3 &a, Vector3 &b, Vector3 &c);
|
||||
inline float distanceTo(Vector3 &t_vec) { return this->distance + this->normal.innerProduct(t_vec); }
|
||||
void print();
|
||||
const void print() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
|
||||
void set(const float &t_x, const float &t_y);
|
||||
void set(const Point &v);
|
||||
void print();
|
||||
const void print() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
void set(const float &x, const float &y, const float &z);
|
||||
void copy(Vector3 &v);
|
||||
float distanceTo(Vector3 &v);
|
||||
void print();
|
||||
const void print() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,6 @@ struct ScreenSettings
|
||||
float aspectRatio;
|
||||
float nearPlaneDist;
|
||||
float farPlaneDist;
|
||||
/** change it to 4096.0F to check out frustum culling! 😎 */
|
||||
float projectionScale;
|
||||
};
|
||||
|
||||
|
||||
@@ -187,8 +187,8 @@ void Matrix::setPerspective(ScreenSettings &t_screen)
|
||||
{
|
||||
float fovYdiv2 = Math::HALF_ANG2RAD * t_screen.fov;
|
||||
float cotFOV = 1.0F / (Math::sin(fovYdiv2) / Math::cos(fovYdiv2));
|
||||
float w = cotFOV * (t_screen.width / 4096.0F) / t_screen.aspectRatio;
|
||||
float h = cotFOV * (t_screen.height / 4096.0F);
|
||||
float w = cotFOV * (t_screen.width / t_screen.projectionScale) / t_screen.aspectRatio;
|
||||
float h = cotFOV * (t_screen.height / t_screen.projectionScale);
|
||||
|
||||
this->data[0] = w;
|
||||
this->data[1] = 0.0F;
|
||||
@@ -253,7 +253,7 @@ void Matrix::lookAt(Vector3 &t_up, Vector3 &t_position, Vector3 &t_target)
|
||||
data[15] = 1;
|
||||
}
|
||||
|
||||
void Matrix::print()
|
||||
const void Matrix::print() const
|
||||
{
|
||||
printf("MATRIX(\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n)\n",
|
||||
data[0], data[1], data[2], data[3],
|
||||
|
||||
@@ -44,7 +44,7 @@ void Plane::update(Vector3 &a, Vector3 &b, Vector3 &c)
|
||||
this->distance = -this->normal.innerProduct(b);
|
||||
}
|
||||
|
||||
void Plane::print()
|
||||
const void Plane::print() const
|
||||
{
|
||||
printf("Plane(Vector3(%f, %f, %f), %f)\n", this->normal.x, this->normal.y, this->normal.z, this->distance);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void Point::set(const Point &v)
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
void Point::print()
|
||||
const void Point::print() const
|
||||
{
|
||||
printf("Point(%f, %f)\n", x, y);
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ float Vector3::distanceTo(Vector3 &v)
|
||||
// (this->z - another.z) * (this->z - another.z));
|
||||
}
|
||||
|
||||
void Vector3::print()
|
||||
const void Vector3::print() const
|
||||
{
|
||||
printf("Vector3(%f, %f, %f)\n", x, y, z);
|
||||
}
|
||||
|
||||
@@ -71,14 +71,15 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position)
|
||||
{
|
||||
Vector3 boxCalcTemp;
|
||||
u8 boxResult = 1, boxIn = 0, boxOut = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
|
||||
for (u8 i = 0; i < 6; i++)
|
||||
{
|
||||
boxOut = 0;
|
||||
boxIn = 0;
|
||||
// for each corner of the box do ...
|
||||
// get out of the cycle as soon as a box as corners
|
||||
// both inside and out of the frustum
|
||||
for (int y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
|
||||
for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
|
||||
{
|
||||
boxCalcTemp.set(
|
||||
boundingBox[y].x + position.x,
|
||||
|
||||
Reference in New Issue
Block a user