added manual calcs of model-view-proj matrix
This commit is contained in:
@@ -41,7 +41,7 @@ CameraBase::CameraBase(ScreenSettings *t_screen, Vector3 *t_position)
|
||||
void CameraBase::lookAt(Vector3 &t_target)
|
||||
{
|
||||
updatePlanes(t_target);
|
||||
worldView.lookAt(*p_position, t_target);
|
||||
view.lookAt(*p_position, 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);
|
||||
}
|
||||
|
||||
/** Adds 3D objects 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
|
||||
*/
|
||||
/** Adds meshes to current packet */
|
||||
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);
|
||||
@@ -145,7 +140,7 @@ void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCoun
|
||||
xyz = new xyz_t[vertexCount];
|
||||
rgbaq = new color_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);
|
||||
delete[] xyz;
|
||||
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
|
||||
* After it addCurrentSTQ() can be done
|
||||
* @param worldView Matrix
|
||||
* @param perspective Matrix with .setPerpsective() used [clone of gluPerspective]
|
||||
* @param mesh 3D object
|
||||
* After it addCurrentCalcs() can be done
|
||||
*/
|
||||
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);
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ Renderer::Renderer(u32 t_packetSize, ScreenSettings *t_screen)
|
||||
gifSender = new GifSender(t_packetSize, t_screen, &light);
|
||||
vifSender = new VifSender(&light);
|
||||
perspective.setPerspective(*t_screen);
|
||||
renderData.perspective = &perspective;
|
||||
renderData.projection = &perspective;
|
||||
PRINT_LOG("Renderer initialized!");
|
||||
}
|
||||
|
||||
@@ -277,7 +277,8 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount)
|
||||
if (!t_mesh.isDataLoaded())
|
||||
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);
|
||||
|
||||
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))
|
||||
return;
|
||||
u32 vertCount = t_mesh.getMaterial(i).getFacesCount();
|
||||
VECTOR __attribute__((aligned(16))) vertices[vertCount];
|
||||
VECTOR __attribute__((aligned(16))) normals[vertCount];
|
||||
VECTOR __attribute__((aligned(16))) coordinates[vertCount];
|
||||
VECTOR vertices[vertCount] __attribute__((aligned(16)));
|
||||
VECTOR normals[vertCount] __attribute__((aligned(16)));
|
||||
VECTOR coordinates[vertCount] __attribute__((aligned(16)));
|
||||
Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId());
|
||||
changeTexture(tex);
|
||||
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)
|
||||
{
|
||||
renderData.worldView = t_worldView;
|
||||
renderData.view = t_worldView;
|
||||
renderData.cameraPosition = t_cameraPos;
|
||||
renderData.frustumPlanes = t_planes;
|
||||
}
|
||||
|
||||
@@ -68,22 +68,22 @@ void VifSender::uploadMicroProgram()
|
||||
dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, 1);
|
||||
packet2_free(packet2);
|
||||
}
|
||||
|
||||
#include <fastmath.h>
|
||||
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 localWorld, localScreen;
|
||||
create_local_world(localWorld, position, rotation);
|
||||
create_local_screen(localScreen, localWorld, t_renderData.worldView->data, t_renderData.perspective->data);
|
||||
// Small undo, because im testing new matrix funcs, which are DIFFERENT than PS2SDK, so cant be used right now.
|
||||
// Matrix viewProj = Matrix();
|
||||
// viewProj.rotation(t_rotation); // model matrix
|
||||
// viewProj.translate(t_position); // model matrix
|
||||
// viewProj *= *t_renderData.worldView * *t_renderData.perspective; // viewproj = model * (view * projection)
|
||||
|
||||
Matrix model;
|
||||
model.identity();
|
||||
model.rotate(t_rotation);
|
||||
model.translate(t_position);
|
||||
|
||||
modelViewProj.identity();
|
||||
modelViewProj = model * modelViewProj;
|
||||
modelViewProj = *t_renderData.view * modelViewProj;
|
||||
modelViewProj = *t_renderData.projection * modelViewProj;
|
||||
|
||||
packet2_reset(matricesPacket, false);
|
||||
// packet2_utils_vu_add_unpack_data(matricesPacket, 0, &viewProj.data, 8, 0);
|
||||
packet2_utils_vu_add_unpack_data(matricesPacket, 0, localScreen, 8, 0);
|
||||
packet2_utils_vu_add_unpack_data(matricesPacket, 0, &modelViewProj.data, 8, 0);
|
||||
packet2_utils_vu_add_end_tag(matricesPacket);
|
||||
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
||||
dma_channel_send_packet2(matricesPacket, DMA_CHANNEL_VIF1, 1);
|
||||
|
||||
Reference in New Issue
Block a user