added manual calcs of model-view-proj matrix
This commit is contained in:
@@ -41,13 +41,13 @@ Engine::~Engine() {}
|
|||||||
|
|
||||||
void Engine::setDefaultScreen()
|
void Engine::setDefaultScreen()
|
||||||
{
|
{
|
||||||
screen.projectionScale = 4096.0F;
|
|
||||||
screen.nearPlaneDist = 2.0F;
|
screen.nearPlaneDist = 2.0F;
|
||||||
screen.farPlaneDist = 2000.0F;
|
screen.farPlaneDist = 2000.0F;
|
||||||
screen.fov = 60.0F;
|
screen.fov = 60.0F;
|
||||||
screen.aspectRatio = 4.0F / 3.0F;
|
|
||||||
screen.width = 640.0F;
|
screen.width = 640.0F;
|
||||||
screen.height = 480.0F;
|
screen.height = 480.0F;
|
||||||
|
screen.aspectRatio = screen.width / screen.height;
|
||||||
|
screen.projectionScale = 4096.0F; // PS2 have 4k drawing area
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::init(Game *t_game, u32 t_gifPacketSize)
|
void Engine::init(Game *t_game, u32 t_gifPacketSize)
|
||||||
|
|||||||
@@ -85,58 +85,70 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline void unit() { identity(); };
|
inline void unit() { identity(); };
|
||||||
|
|
||||||
/** Create translation matrix. */
|
/** Translate matrix. */
|
||||||
inline void translation(const Vector3 &t_val)
|
inline void translate(const Vector3 &t_val)
|
||||||
{
|
{
|
||||||
identity();
|
Matrix temp = Matrix(true);
|
||||||
translate(t_val);
|
temp.translation(t_val);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create rotation matrix. */
|
/** Rotate matrix. */
|
||||||
inline void rotation(const Vector3 &t_val)
|
inline void rotate(const Vector3 &t_val)
|
||||||
{
|
{
|
||||||
identity();
|
Matrix temp = Matrix(true);
|
||||||
Matrix temp = Matrix();
|
|
||||||
|
temp.rotationZ(t_val.z);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
|
|
||||||
temp.identity();
|
temp.identity();
|
||||||
temp.rotateX(t_val.x);
|
temp.rotationY(t_val.y);
|
||||||
operator*=(temp);
|
cross(this->data, temp.data, this->data);
|
||||||
|
|
||||||
temp.identity();
|
temp.identity();
|
||||||
temp.rotateY(t_val.y);
|
temp.rotationX(t_val.x);
|
||||||
operator*=(temp);
|
cross(this->data, temp.data, this->data);
|
||||||
|
|
||||||
temp.identity();
|
|
||||||
temp.rotateZ(t_val.z);
|
|
||||||
operator*=(temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create X rotation matrix. */
|
/** Rotate matrix by X. */
|
||||||
inline void rotationX(const float &t_radians)
|
inline void rotateX(const float &t_radians)
|
||||||
{
|
{
|
||||||
identity();
|
Matrix temp = Matrix(true);
|
||||||
rotateX(t_radians);
|
temp.rotationX(t_radians);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create Y rotation matrix. */
|
/** Rotate matrix by Y. */
|
||||||
inline void rotationY(const float &t_radians)
|
inline void rotateY(const float &t_radians)
|
||||||
{
|
{
|
||||||
identity();
|
Matrix temp = Matrix(true);
|
||||||
rotateY(t_radians);
|
temp.rotationY(t_radians);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create Z rotation matrix. */
|
/** Rotate matrix by Z. */
|
||||||
inline void rotationZ(const float &t_radians)
|
inline void rotateZ(const float &t_radians)
|
||||||
{
|
{
|
||||||
identity();
|
Matrix temp = Matrix(true);
|
||||||
rotateZ(t_radians);
|
temp.rotationZ(t_radians);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create angle rotation matrix. */
|
/** Rotate matrix by angle. */
|
||||||
void rotationByAngle(const float &t_angle, const Vector3 &t_axis);
|
void rotateByAngle(const float &t_angle, const Vector3 &t_axis)
|
||||||
|
{
|
||||||
|
Matrix temp;
|
||||||
|
temp.rotationByAngle(t_angle, t_axis);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
|
}
|
||||||
|
|
||||||
/** Create scale matrix. */
|
/** Scale matrix. */
|
||||||
void setScale(const Vector3 &t_val);
|
void scale(const Vector3 &t_val)
|
||||||
|
{
|
||||||
|
Matrix temp = Matrix(true);
|
||||||
|
temp.setScale(t_val);
|
||||||
|
cross(this->data, temp.data, this->data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create perspective projection matrix.
|
* Create perspective projection matrix.
|
||||||
@@ -161,12 +173,14 @@ public:
|
|||||||
const void print() const;
|
const void print() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rotateX(const float &t_radians);
|
void rotationX(const float &t_radians);
|
||||||
void rotateY(const float &t_radians);
|
void rotationY(const float &t_radians);
|
||||||
void rotateZ(const float &t_radians);
|
void rotationZ(const float &t_radians);
|
||||||
void translate(const Vector3 &t_val);
|
void rotationByAngle(const float &t_angle, const Vector3 &t_axis);
|
||||||
void cross(float res[16], const float a[16], const float b[16]) const;
|
void translation(const Vector3 &t_val);
|
||||||
|
void setScale(const Vector3 &t_val);
|
||||||
void setCamera(const float t_pos[4], const float t_vz[4], const float t_vy[4]);
|
void setCamera(const float t_pos[4], const float t_vz[4], const float t_vy[4]);
|
||||||
|
void cross(float res[16], const float a[16], const float b[16]) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,10 +22,18 @@ struct RenderData
|
|||||||
{
|
{
|
||||||
LightBulb *bulbs;
|
LightBulb *bulbs;
|
||||||
u16 bulbsCount;
|
u16 bulbsCount;
|
||||||
/** Camera (lookAt) */
|
/**
|
||||||
Matrix *worldView;
|
* Camera matrix (glLookAt)
|
||||||
/** Perspective projection */
|
* OpenGL name: View
|
||||||
Matrix *perspective;
|
* Sony name: World view
|
||||||
|
*/
|
||||||
|
Matrix *view;
|
||||||
|
/**
|
||||||
|
* Projection matrix (glPerspective)
|
||||||
|
* OpenGL name: Projection
|
||||||
|
* Sony name: View screen
|
||||||
|
*/
|
||||||
|
Matrix *projection;
|
||||||
Vector3 *cameraPosition;
|
Vector3 *cameraPosition;
|
||||||
Plane *frustumPlanes;
|
Plane *frustumPlanes;
|
||||||
prim_t *prim;
|
prim_t *prim;
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ public:
|
|||||||
Plane planes[6];
|
Plane planes[6];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Projection matrix
|
* View matrix
|
||||||
* Set by lookAt() method.
|
* Set by lookAt() method.
|
||||||
*/
|
*/
|
||||||
Matrix worldView;
|
Matrix view;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Pointer to screen settings */
|
/** Pointer to screen settings */
|
||||||
@@ -42,7 +42,7 @@ protected:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adaption of OpenGL lookAt camera.
|
* Adaption of OpenGL lookAt camera.
|
||||||
* Calculates worldView matrix and update frustum planes
|
* Calculates view matrix and update frustum planes
|
||||||
* Should be called every frame.
|
* Should be called every frame.
|
||||||
*/
|
*/
|
||||||
void lookAt(Vector3 &t_target);
|
void lookAt(Vector3 &t_target);
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ private:
|
|||||||
void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer);
|
void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *textureBuffer);
|
||||||
packet2_t *packets[2] __attribute__((aligned(64)));
|
packet2_t *packets[2] __attribute__((aligned(64)));
|
||||||
packet2_t *currPacket;
|
packet2_t *currPacket;
|
||||||
|
/**
|
||||||
|
* OpenGL name: Model
|
||||||
|
* Sony name: local world
|
||||||
|
*/
|
||||||
|
Matrix model;
|
||||||
|
/**
|
||||||
|
* OpenGL name: ModelViewProjection
|
||||||
|
* Sony name: local screen
|
||||||
|
*/
|
||||||
|
Matrix modelViewProj;
|
||||||
u8 context;
|
u8 context;
|
||||||
packet2_t *matricesPacket __attribute__((aligned(64)));
|
packet2_t *matricesPacket __attribute__((aligned(64)));
|
||||||
VECTOR position, rotation;
|
VECTOR position, rotation;
|
||||||
|
|||||||
@@ -93,47 +93,6 @@ void Matrix::identity()
|
|||||||
: "r"(this->data));
|
: "r"(this->data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::rotationByAngle(const float &t_angle, const Vector3 &t_axis)
|
|
||||||
{
|
|
||||||
Vector3 localAxis = Vector3(t_axis);
|
|
||||||
localAxis.normalize();
|
|
||||||
float x = localAxis.x;
|
|
||||||
float y = localAxis.y;
|
|
||||||
float z = localAxis.z;
|
|
||||||
|
|
||||||
float c = Math::cos(t_angle);
|
|
||||||
float s = Math::sin(t_angle);
|
|
||||||
|
|
||||||
this->data[0] = x * x * (1 - c) + c;
|
|
||||||
this->data[1] = y * x * (1 - c) + z * s;
|
|
||||||
this->data[2] = x * z * (1 - c) - y * s;
|
|
||||||
this->data[3] = 0.0F;
|
|
||||||
|
|
||||||
this->data[4] = x * y * (1 - c) - z * s;
|
|
||||||
this->data[5] = y * y * (1 - c) + c;
|
|
||||||
this->data[6] = y * z * (1 - c) + x * s;
|
|
||||||
this->data[7] = 0.0F;
|
|
||||||
|
|
||||||
this->data[8] = x * z * (1 - c) + y * s;
|
|
||||||
this->data[9] = y * z * (1 - c) - x * s;
|
|
||||||
this->data[10] = z * z * (1 - c) + c;
|
|
||||||
this->data[11] = 0.0F;
|
|
||||||
|
|
||||||
this->data[12] = 0.0F;
|
|
||||||
this->data[13] = 0.0F;
|
|
||||||
this->data[14] = 0.0F;
|
|
||||||
this->data[15] = 1.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::setScale(const Vector3 &t_val)
|
|
||||||
{
|
|
||||||
this->identity();
|
|
||||||
this->data[0] = t_val.x;
|
|
||||||
this->data[5] = t_val.y;
|
|
||||||
this->data[10] = t_val.z;
|
|
||||||
this->data[15] = 1.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::setPerspective(const ScreenSettings &t_screen)
|
void Matrix::setPerspective(const ScreenSettings &t_screen)
|
||||||
{
|
{
|
||||||
float fovYdiv2 = Math::HALF_ANG2RAD * t_screen.fov;
|
float fovYdiv2 = Math::HALF_ANG2RAD * t_screen.fov;
|
||||||
@@ -232,10 +191,8 @@ const void Matrix::print() const
|
|||||||
// Private
|
// Private
|
||||||
// ----
|
// ----
|
||||||
|
|
||||||
void Matrix::rotateX(const float &t_radians)
|
void Matrix::rotationX(const float &t_radians)
|
||||||
{
|
{
|
||||||
Matrix temp = Matrix();
|
|
||||||
temp.identity();
|
|
||||||
float c = Math::cos(t_radians);
|
float c = Math::cos(t_radians);
|
||||||
float s = Math::sin(t_radians);
|
float s = Math::sin(t_radians);
|
||||||
this->data[5] = c; // 1,1
|
this->data[5] = c; // 1,1
|
||||||
@@ -244,10 +201,8 @@ void Matrix::rotateX(const float &t_radians)
|
|||||||
this->data[10] = c; // 2,2
|
this->data[10] = c; // 2,2
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::rotateY(const float &t_radians)
|
void Matrix::rotationY(const float &t_radians)
|
||||||
{
|
{
|
||||||
Matrix temp = Matrix();
|
|
||||||
temp.identity();
|
|
||||||
float c = Math::cos(t_radians);
|
float c = Math::cos(t_radians);
|
||||||
float s = Math::sin(t_radians);
|
float s = Math::sin(t_radians);
|
||||||
this->data[0] = c; // 0,0
|
this->data[0] = c; // 0,0
|
||||||
@@ -256,10 +211,8 @@ void Matrix::rotateY(const float &t_radians)
|
|||||||
this->data[10] = c; // 2,2
|
this->data[10] = c; // 2,2
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::rotateZ(const float &t_radians)
|
void Matrix::rotationZ(const float &t_radians)
|
||||||
{
|
{
|
||||||
Matrix temp = Matrix();
|
|
||||||
temp.identity();
|
|
||||||
float c = Math::cos(t_radians);
|
float c = Math::cos(t_radians);
|
||||||
float s = Math::sin(t_radians);
|
float s = Math::sin(t_radians);
|
||||||
this->data[0] = c; // 0,0
|
this->data[0] = c; // 0,0
|
||||||
@@ -268,11 +221,51 @@ void Matrix::rotateZ(const float &t_radians)
|
|||||||
this->data[5] = c; // 1,1
|
this->data[5] = c; // 1,1
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::translate(const Vector3 &t_val)
|
void Matrix::rotationByAngle(const float &t_angle, const Vector3 &t_axis)
|
||||||
{
|
{
|
||||||
this->data[12] += t_val.x; // 3,0
|
Vector3 localAxis = Vector3(t_axis);
|
||||||
this->data[13] += t_val.y; // 3,1
|
localAxis.normalize();
|
||||||
this->data[14] += t_val.z; // 3,2
|
float x = localAxis.x;
|
||||||
|
float y = localAxis.y;
|
||||||
|
float z = localAxis.z;
|
||||||
|
|
||||||
|
float c = Math::cos(t_angle);
|
||||||
|
float s = Math::sin(t_angle);
|
||||||
|
|
||||||
|
this->data[0] = x * x * (1 - c) + c;
|
||||||
|
this->data[1] = y * x * (1 - c) + z * s;
|
||||||
|
this->data[2] = x * z * (1 - c) - y * s;
|
||||||
|
this->data[3] = 0.0F;
|
||||||
|
|
||||||
|
this->data[4] = x * y * (1 - c) - z * s;
|
||||||
|
this->data[5] = y * y * (1 - c) + c;
|
||||||
|
this->data[6] = y * z * (1 - c) + x * s;
|
||||||
|
this->data[7] = 0.0F;
|
||||||
|
|
||||||
|
this->data[8] = x * z * (1 - c) + y * s;
|
||||||
|
this->data[9] = y * z * (1 - c) - x * s;
|
||||||
|
this->data[10] = z * z * (1 - c) + c;
|
||||||
|
this->data[11] = 0.0F;
|
||||||
|
|
||||||
|
this->data[12] = 0.0F;
|
||||||
|
this->data[13] = 0.0F;
|
||||||
|
this->data[14] = 0.0F;
|
||||||
|
this->data[15] = 1.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix::translation(const Vector3 &t_val)
|
||||||
|
{
|
||||||
|
this->data[12] = t_val.x; // 3,0
|
||||||
|
this->data[13] = t_val.y; // 3,1
|
||||||
|
this->data[14] = t_val.z; // 3,2
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix::setScale(const Vector3 &t_val)
|
||||||
|
{
|
||||||
|
this->data[0] = t_val.x;
|
||||||
|
this->data[5] = t_val.y;
|
||||||
|
this->data[10] = t_val.z;
|
||||||
|
this->data[15] = 1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::setCamera(const float t_pos[4], const float t_vz[4], const float t_vy[4])
|
void Matrix::setCamera(const float t_pos[4], const float t_vz[4], const float t_vy[4])
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position)
|
|||||||
void CameraBase::lookAt(Vector3 &t_target)
|
void CameraBase::lookAt(Vector3 &t_target)
|
||||||
{
|
{
|
||||||
updatePlanes(t_target);
|
updatePlanes(t_target);
|
||||||
worldView.lookAt(*p_position, t_target);
|
view.lookAt(*p_position, t_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraBase::updatePlanes(Vector3 t_target)
|
void CameraBase::updatePlanes(Vector3 t_target)
|
||||||
|
|||||||
@@ -130,12 +130,7 @@ void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *t_rgb)
|
|||||||
packet2_chain_close_tag(currentPacket);
|
packet2_chain_close_tag(currentPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds 3D objects to current packet
|
/** Adds meshes to current packet */
|
||||||
* @param worldView Matrix
|
|
||||||
* @param perspective Matrix with .setPerpsective() used [clone of gluPerspective]
|
|
||||||
* @param objects3D Array of 3D objects pointers
|
|
||||||
* @param amount Amount of 3D objects
|
|
||||||
*/
|
|
||||||
void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
|
void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer)
|
||||||
{
|
{
|
||||||
packet2_chain_open_cnt(currentPacket, 0, 0, 0);
|
packet2_chain_open_cnt(currentPacket, 0, 0, 0);
|
||||||
@@ -145,7 +140,7 @@ void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCoun
|
|||||||
xyz = new xyz_t[vertexCount];
|
xyz = new xyz_t[vertexCount];
|
||||||
rgbaq = new color_t[vertexCount];
|
rgbaq = new color_t[vertexCount];
|
||||||
st = new texel_t[vertexCount];
|
st = new texel_t[vertexCount];
|
||||||
calc3DObject(*t_renderData->perspective, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount);
|
calc3DObject(*t_renderData->projection, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount);
|
||||||
addCurrentCalcs(vertexCount);
|
addCurrentCalcs(vertexCount);
|
||||||
delete[] xyz;
|
delete[] xyz;
|
||||||
delete[] rgbaq;
|
delete[] rgbaq;
|
||||||
@@ -155,10 +150,7 @@ void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCoun
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Calculates 3D object data into xyz, rgbq, st
|
/** Calculates 3D object data into xyz, rgbq, st
|
||||||
* After it addCurrentSTQ() can be done
|
* After it addCurrentCalcs() can be done
|
||||||
* @param worldView Matrix
|
|
||||||
* @param perspective Matrix with .setPerpsective() used [clone of gluPerspective]
|
|
||||||
* @param mesh 3D object
|
|
||||||
*/
|
*/
|
||||||
void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount)
|
void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||||
{
|
{
|
||||||
@@ -176,7 +168,7 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount
|
|||||||
create_local_light(localLight, rotation);
|
create_local_light(localLight, rotation);
|
||||||
|
|
||||||
// I cant put perspective from renderData here. ee-gcc bug?
|
// I cant put perspective from renderData here. ee-gcc bug?
|
||||||
create_local_screen(localScreen, localWorld, t_renderData->worldView->data, t_perspective.data);
|
create_local_screen(localScreen, localWorld, t_renderData->view->data, t_perspective.data);
|
||||||
|
|
||||||
if (SHOULD_BE_LIGHTED)
|
if (SHOULD_BE_LIGHTED)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen)
|
|||||||
gifSender = new GifSender(t_packetSize, t_screen, &light);
|
gifSender = new GifSender(t_packetSize, t_screen, &light);
|
||||||
vifSender = new VifSender(&light);
|
vifSender = new VifSender(&light);
|
||||||
perspective.setPerspective(*t_screen);
|
perspective.setPerspective(*t_screen);
|
||||||
renderData.perspective = &perspective;
|
renderData.projection = &perspective;
|
||||||
PRINT_LOG("Renderer initialized!");
|
PRINT_LOG("Renderer initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +277,8 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
|||||||
if (!t_mesh.isDataLoaded())
|
if (!t_mesh.isDataLoaded())
|
||||||
PRINT_ERR("Can't draw, because no mesh data was loaded!");
|
PRINT_ERR("Can't draw, because no mesh data was loaded!");
|
||||||
|
|
||||||
camRotation.rotation(-t_mesh.rotation);
|
camRotation.identity();
|
||||||
|
camRotation.rotate(-t_mesh.rotation);
|
||||||
Vector3 rotatedCamera = Vector3(camRotation * *renderData.cameraPosition);
|
Vector3 rotatedCamera = Vector3(camRotation * *renderData.cameraPosition);
|
||||||
|
|
||||||
if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
|
if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame())
|
||||||
@@ -287,9 +288,9 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
|||||||
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position))
|
||||||
return;
|
return;
|
||||||
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
||||||
VECTOR __attribute__((aligned(16))) vertices[vertCount];
|
VECTOR vertices[vertCount] __attribute__((aligned(16)));
|
||||||
VECTOR __attribute__((aligned(16))) normals[vertCount];
|
VECTOR normals[vertCount] __attribute__((aligned(16)));
|
||||||
VECTOR __attribute__((aligned(16))) coordinates[vertCount];
|
VECTOR coordinates[vertCount] __attribute__((aligned(16)));
|
||||||
Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||||
changeTexture(tex);
|
changeTexture(tex);
|
||||||
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
|
vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera);
|
||||||
@@ -305,7 +306,7 @@ void Renderer::draw(Mesh &t_mesh) { draw(t_mesh, NULL, 0); }
|
|||||||
|
|
||||||
void Renderer::setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes)
|
void Renderer::setCameraDefinitions(Matrix *t_worldView, Vector3 *t_cameraPos, Plane *t_planes)
|
||||||
{
|
{
|
||||||
renderData.worldView = t_worldView;
|
renderData.view = t_worldView;
|
||||||
renderData.cameraPosition = t_cameraPos;
|
renderData.cameraPosition = t_cameraPos;
|
||||||
renderData.frustumPlanes = t_planes;
|
renderData.frustumPlanes = t_planes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,22 +68,22 @@ void VifSender::uploadMicroProgram()
|
|||||||
dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, 1);
|
dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, 1);
|
||||||
packet2_free(packet2);
|
packet2_free(packet2);
|
||||||
}
|
}
|
||||||
|
#include <fastmath.h>
|
||||||
void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation)
|
void VifSender::sendMatrices(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation)
|
||||||
{
|
{
|
||||||
vec3ToNative(position, t_position, 1.0F);
|
|
||||||
vec3ToNative(rotation, t_rotation, 1.0F);
|
Matrix model;
|
||||||
MATRIX localWorld, localScreen;
|
model.identity();
|
||||||
create_local_world(localWorld, position, rotation);
|
model.rotate(t_rotation);
|
||||||
create_local_screen(localScreen, localWorld, t_renderData.worldView->data, t_renderData.perspective->data);
|
model.translate(t_position);
|
||||||
// Small undo, because im testing new matrix funcs, which are DIFFERENT than PS2SDK, so cant be used right now.
|
|
||||||
// Matrix viewProj = Matrix();
|
modelViewProj.identity();
|
||||||
// viewProj.rotation(t_rotation); // model matrix
|
modelViewProj = model * modelViewProj;
|
||||||
// viewProj.translate(t_position); // model matrix
|
modelViewProj = *t_renderData.view * modelViewProj;
|
||||||
// viewProj *= *t_renderData.worldView * *t_renderData.perspective; // viewproj = model * (view * projection)
|
modelViewProj = *t_renderData.projection * modelViewProj;
|
||||||
|
|
||||||
packet2_reset(matricesPacket, false);
|
packet2_reset(matricesPacket, false);
|
||||||
// packet2_utils_vu_add_unpack_data(matricesPacket, 0, &viewProj.data, 8, 0);
|
packet2_utils_vu_add_unpack_data(matricesPacket, 0, &modelViewProj.data, 8, 0);
|
||||||
packet2_utils_vu_add_unpack_data(matricesPacket, 0, localScreen, 8, 0);
|
|
||||||
packet2_utils_vu_add_end_tag(matricesPacket);
|
packet2_utils_vu_add_end_tag(matricesPacket);
|
||||||
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
||||||
dma_channel_send_packet2(matricesPacket, DMA_CHANNEL_VIF1, 1);
|
dma_channel_send_packet2(matricesPacket, DMA_CHANNEL_VIF1, 1);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Dolphin::~Dolphin()
|
|||||||
void Dolphin::onInit()
|
void Dolphin::onInit()
|
||||||
{
|
{
|
||||||
player.init(engine);
|
player.init(engine);
|
||||||
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.position, camera.planes);
|
engine->renderer->setCameraDefinitions(&camera.view, &camera.position, camera.planes);
|
||||||
|
|
||||||
engine->audio.loadSong("sound/dirediredocks.wav");
|
engine->audio.loadSong("sound/dirediredocks.wav");
|
||||||
engine->audio.playSong();
|
engine->audio.playSong();
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Floors::~Floors()
|
|||||||
void Floors::onInit()
|
void Floors::onInit()
|
||||||
{
|
{
|
||||||
setBgColorAndAmbientColor();
|
setBgColorAndAmbientColor();
|
||||||
engine->renderer->setCameraDefinitions(&camera.worldView, &camera.unitCirclePosition, camera.planes);
|
engine->renderer->setCameraDefinitions(&camera.view, &camera.unitCirclePosition, camera.planes);
|
||||||
engine->audio.addSongListener(this);
|
engine->audio.addSongListener(this);
|
||||||
engine->audio.loadSong("sounds/mafikizolo-loot.wav");
|
engine->audio.loadSong("sounds/mafikizolo-loot.wav");
|
||||||
engine->audio.playSong();
|
engine->audio.playSong();
|
||||||
@@ -61,7 +61,7 @@ void Floors::onUpdate()
|
|||||||
engine->renderer->draw(player->mesh);
|
engine->renderer->draw(player->mesh);
|
||||||
engine->renderer->draw(enemy->getMeshes(), enemy->getMeshesCount());
|
engine->renderer->draw(enemy->getMeshes(), enemy->getMeshesCount());
|
||||||
for (u16 i = 0; i < FLOORS_COUNT; i++)
|
for (u16 i = 0; i < FLOORS_COUNT; i++)
|
||||||
engine->renderer->drawByPath3(floorManager->floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount);
|
engine->renderer->draw(floorManager->floors[i].mesh, lightManager.bulbs, lightManager.bulbsCount);
|
||||||
ui->render(engine->renderer); // 2D rendering ist LAST step, because layers gonna play there.
|
ui->render(engine->renderer); // 2D rendering ist LAST step, because layers gonna play there.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,17 @@ Enemy::Enemy(TextureRepository *t_texRepo)
|
|||||||
meshes[0].loadMD2("meshes/enemy/", "poss_head", 0.3F, false);
|
meshes[0].loadMD2("meshes/enemy/", "poss_head", 0.3F, false);
|
||||||
meshes[0].rotation.x = -1.566F;
|
meshes[0].rotation.x = -1.566F;
|
||||||
meshes[0].rotation.z = 1.566F;
|
meshes[0].rotation.z = 1.566F;
|
||||||
|
meshes[0].shouldBeFrustumCulled = false;
|
||||||
|
|
||||||
meshes[1].loadMD2("meshes/enemy/", "poss_body", 0.3F, false);
|
meshes[1].loadMD2("meshes/enemy/", "poss_body", 0.3F, false);
|
||||||
meshes[1].rotation.x = -1.566F;
|
meshes[1].rotation.x = -1.566F;
|
||||||
meshes[1].rotation.z = 1.566F;
|
meshes[1].rotation.z = 1.566F;
|
||||||
|
meshes[1].shouldBeFrustumCulled = false;
|
||||||
|
|
||||||
meshes[2].loadMD2("meshes/enemy/", "poss_weapon", 0.3F, false);
|
meshes[2].loadMD2("meshes/enemy/", "poss_weapon", 0.3F, false);
|
||||||
meshes[2].rotation.x = -1.566F;
|
meshes[2].rotation.x = -1.566F;
|
||||||
meshes[2].rotation.z = 1.566F;
|
meshes[2].rotation.z = 1.566F;
|
||||||
|
meshes[2].shouldBeFrustumCulled = false;
|
||||||
|
|
||||||
Vector3 initPos = Vector3(0.00F, 40.00F, 0.00F);
|
Vector3 initPos = Vector3(0.00F, 40.00F, 0.00F);
|
||||||
setPosition(initPos);
|
setPosition(initPos);
|
||||||
|
|||||||
Reference in New Issue
Block a user