From e6d01b1159e894eda995527955cf31e3535e89f3 Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 14 Jun 2018 23:17:55 +0200 Subject: [PATCH] fixed view matrix; im2d UV --- skeleton/imgui/imgui_impl_rw.cpp | 7 ++++--- src/camera.cpp | 6 ++++++ src/d3d/rwd3d.h | 4 ++-- src/gl/rwgl3.h | 4 ++-- tools/clumpview/font.cpp | 26 +++++++++++++----------- tools/clumpview/main.cpp | 35 +++++++++++++++++++++++++++----- tools/clumpview/tests.cpp | 8 ++++---- 7 files changed, 62 insertions(+), 28 deletions(-) diff --git a/skeleton/imgui/imgui_impl_rw.cpp b/skeleton/imgui/imgui_impl_rw.cpp index 9df1e26..c326eba 100644 --- a/skeleton/imgui/imgui_impl_rw.cpp +++ b/skeleton/imgui/imgui_impl_rw.cpp @@ -38,6 +38,7 @@ ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data) rw::Camera *cam = (rw::Camera*)rw::engine->currentCamera; Im2DVertex *vtx_dst = g_vertbuf; + float recipZ = 1.0f/cam->nearPlane; for(int n = 0; n < draw_data->CmdListsCount; n++){ const ImDrawList *cmd_list = draw_data->CmdLists[n]; const ImDrawVert *vtx_src = cmd_list->VtxBuffer.Data; @@ -46,10 +47,10 @@ ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data) vtx_dst[i].setScreenY(vtx_src[i].pos.y + yoff); vtx_dst[i].setScreenZ(rw::im2d::GetNearZ()); vtx_dst[i].setCameraZ(cam->nearPlane); - vtx_dst[i].setRecipCameraZ(1.0f/cam->nearPlane); + vtx_dst[i].setRecipCameraZ(recipZ); vtx_dst[i].setColor(vtx_src[i].col&0xFF, vtx_src[i].col>>8 & 0xFF, vtx_src[i].col>>16 & 0xFF, vtx_src[i].col>>24 & 0xFF); - vtx_dst[i].setU(vtx_src[i].uv.x); - vtx_dst[i].setV(vtx_src[i].uv.y); + vtx_dst[i].setU(vtx_src[i].uv.x, recipZ); + vtx_dst[i].setV(vtx_src[i].uv.y, recipZ); } vtx_dst += cmd_list->VtxBuffer.Size; } diff --git a/src/camera.cpp b/src/camera.cpp index 845a137..e293d32 100755 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -207,6 +207,12 @@ cameraSync(ObjectWithFrame *obj) Camera *cam = (Camera*)obj; Matrix inv, proj; Matrix::invertOrthonormal(&inv, cam->getFrame()->getLTM()); + + inv.right.x = -inv.right.x; + inv.up.x = -inv.up.x; + inv.at.x = -inv.at.x; + inv.pos.x = -inv.pos.x; + float32 xscl = 1.0f/(2.0f*cam->viewWindow.x); float32 yscl = 1.0f/(2.0f*cam->viewWindow.y); diff --git a/src/d3d/rwd3d.h b/src/d3d/rwd3d.h index 4054b57..c5bc854 100644 --- a/src/d3d/rwd3d.h +++ b/src/d3d/rwd3d.h @@ -51,8 +51,8 @@ struct Im2DVertex void setCameraZ(float32 z) { } void setRecipCameraZ(float32 recipz) { this->w = recipz; } void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { this->color = D3DCOLOR_ARGB(a, r, g, b); } - void setU(float32 u) { this->u = u; } - void setV(float32 v) { this->v = v; } + void setU(float32 u, float recipZ) { this->u = u; } + void setV(float32 v, float recipZ) { this->v = v; } }; void setD3dMaterial(D3DMATERIAL9 *mat9); diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index 446e685..4a917cc 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -114,8 +114,8 @@ struct Im2DVertex void setRecipCameraZ(float32 recipz) { } void setColor(uint8 r, uint8 g, uint8 b, uint8 a) { this->r = r; this->g = g; this->b = b; this->a = a; } - void setU(float32 u) { this->u = u; } - void setV(float32 v) { this->v = v; } + void setU(float32 u, float recipz) { this->u = u; } + void setV(float32 v, float recipz) { this->v = v; } }; void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs); diff --git a/tools/clumpview/font.cpp b/tools/clumpview/font.cpp index fa80204..86c8ecb 100644 --- a/tools/clumpview/font.cpp +++ b/tools/clumpview/font.cpp @@ -29,12 +29,14 @@ printScreen(const char *s, float32 x, float32 y) curVert = 0; curIndex = 0; float32 u, v, du, dv; + float recipZ; cam = (Camera*)engine->currentCamera; vert = &vertices[curVert]; ix = &indices[curIndex]; du = curfont->glyphwidth/(float32)curfont->tex->raster->width; dv = curfont->glyphheight/(float32)curfont->tex->raster->height; + recipZ = 1.0f/cam->nearPlane; while(c = *s){ if(c >= curfont->numglyphs) c = 0; @@ -45,40 +47,40 @@ printScreen(const char *s, float32 x, float32 y) vert->setScreenY(y); vert->setScreenZ(rw::im2d::GetNearZ()); vert->setCameraZ(cam->nearPlane); - vert->setRecipCameraZ(1.0f/cam->nearPlane); + vert->setRecipCameraZ(recipZ); vert->setColor(255, 255, 255, 255); - vert->setU(u); - vert->setV(v); + vert->setU(u, recipZ); + vert->setV(v, recipZ); vert++; vert->setScreenX(x+curfont->glyphwidth); vert->setScreenY(y); vert->setScreenZ(rw::im2d::GetNearZ()); vert->setCameraZ(cam->nearPlane); - vert->setRecipCameraZ(1.0f/cam->nearPlane); + vert->setRecipCameraZ(recipZ); vert->setColor(255, 255, 255, 255); - vert->setU(u+du); - vert->setV(v); + vert->setU(u+du, recipZ); + vert->setV(v, recipZ); vert++; vert->setScreenX(x); vert->setScreenY(y+curfont->glyphheight); vert->setScreenZ(rw::im2d::GetNearZ()); vert->setCameraZ(cam->nearPlane); - vert->setRecipCameraZ(1.0f/cam->nearPlane); + vert->setRecipCameraZ(recipZ); vert->setColor(255, 255, 255, 255); - vert->setU(u); - vert->setV(v+dv); + vert->setU(u, recipZ); + vert->setV(v+dv, recipZ); vert++; vert->setScreenX(x+curfont->glyphwidth); vert->setScreenY(y+curfont->glyphheight); vert->setScreenZ(rw::im2d::GetNearZ()); vert->setCameraZ(cam->nearPlane); - vert->setRecipCameraZ(1.0f/cam->nearPlane); + vert->setRecipCameraZ(recipZ); vert->setColor(255, 255, 255, 255); - vert->setU(u+du); - vert->setV(v+dv); + vert->setU(u+du, recipZ); + vert->setV(v+dv, recipZ); vert++; *ix++ = curVert; diff --git a/tools/clumpview/main.cpp b/tools/clumpview/main.cpp index c77c676..186cd23 100644 --- a/tools/clumpview/main.cpp +++ b/tools/clumpview/main.cpp @@ -251,15 +251,16 @@ im2dtest(void) 0, 1, 2, 3 }; + float recipZ = 1.0f/Scene.camera->nearPlane; for(i = 0; i < 4; i++){ verts[i].setScreenX(vs[i].x); verts[i].setScreenY(vs[i].y); verts[i].setScreenZ(rw::im2d::GetNearZ()); verts[i].setCameraZ(Scene.camera->nearPlane); - verts[i].setRecipCameraZ(1.0f/Scene.camera->nearPlane); + verts[i].setRecipCameraZ(recipZ); verts[i].setColor(vs[i].r, vs[i].g, vs[i].b, vs[i].a); - verts[i].setU(vs[i].u); - verts[i].setV(vs[i].v); + verts[i].setU(vs[i].u, recipZ); + verts[i].setV(vs[i].v, recipZ); } rw::engine->imtexture = tex2; @@ -324,9 +325,9 @@ Draw(float timeDelta) camera->update(); camera->m_rwcam->beginUpdate(); - Scene.clump->render(); +// Scene.clump->render(); // im2dtest(); -// tlTest(Scene.clump); + tlTest(Scene.clump); // im3dtest(); // printScreen("Hello, World!", 10, 10); @@ -380,11 +381,23 @@ KeyDown(int key) } } +void +MouseMove(int x, int y) +{ +} + +void +MouseButton(int buttons) +{ +} + sk::EventStatus AppEventHandler(sk::Event e, void *param) { using namespace sk; Rect *r; + MouseState *ms; + switch(e){ case INITIALIZE: Init(); @@ -399,8 +412,20 @@ AppEventHandler(sk::Event e, void *param) case KEYUP: KeyUp(*(int*)param); return EVENTPROCESSED; + case MOUSEBTN: + ms = (MouseState*)param; + MouseButton(ms->buttons); + return EVENTPROCESSED; + case MOUSEMOVE: + ms = (MouseState*)param; + MouseMove(ms->posx, ms->posy); + return EVENTPROCESSED; case RESIZE: r = (Rect*)param; + // TODO: register when we're minimized + if(r->w == 0) r->w = 1; + if(r->h == 0) r->h = 1; + sk::globals.width = r->w; sk::globals.height = r->h; // TODO: set aspect ratio diff --git a/tools/clumpview/tests.cpp b/tools/clumpview/tests.cpp index 68d159d..b8158f5 100644 --- a/tools/clumpview/tests.cpp +++ b/tools/clumpview/tests.cpp @@ -87,8 +87,8 @@ drawAtomic(Atomic *a) im2dverts[i].setCameraZ(xvert[i].z); im2dverts[i].setRecipCameraZ(recipZ); im2dverts[i].setColor(255, 0, 0, 255); - im2dverts[i].setU(texcoords[i].u); - im2dverts[i].setV(texcoords[i].v); + im2dverts[i].setU(texcoords[i].u, recipZ); + im2dverts[i].setV(texcoords[i].v, recipZ); } for(int32 i = 0; i < mh->numMeshes; i++){ for(uint32 j = 0; j < m[i].numIndices; j++){ @@ -172,8 +172,8 @@ genIm3DTransform(void *vertices, int32 numVertices, Matrix *world) clipverts[i].setCameraZ(pos.z); clipverts[i].setRecipCameraZ(recipZ); clipverts[i].setColor(c.red, c.green, c.blue, c.alpha); - clipverts[i].setU(objverts[i].u); - clipverts[i].setV(objverts[i].v); + clipverts[i].setU(objverts[i].u, recipZ); + clipverts[i].setV(objverts[i].v, recipZ); } }