fixed view matrix; im2d UV

This commit is contained in:
aap 2018-06-14 23:17:55 +02:00
parent 5cdc0499c5
commit e6d01b1159
7 changed files with 62 additions and 28 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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);
}
}