mirror of
https://github.com/aap/librw.git
synced 2024-11-25 13:15:43 +00:00
fixed view matrix; im2d UV
This commit is contained in:
parent
5cdc0499c5
commit
e6d01b1159
@ -38,6 +38,7 @@ ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data)
|
|||||||
|
|
||||||
rw::Camera *cam = (rw::Camera*)rw::engine->currentCamera;
|
rw::Camera *cam = (rw::Camera*)rw::engine->currentCamera;
|
||||||
Im2DVertex *vtx_dst = g_vertbuf;
|
Im2DVertex *vtx_dst = g_vertbuf;
|
||||||
|
float recipZ = 1.0f/cam->nearPlane;
|
||||||
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
||||||
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
||||||
const ImDrawVert *vtx_src = cmd_list->VtxBuffer.Data;
|
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].setScreenY(vtx_src[i].pos.y + yoff);
|
||||||
vtx_dst[i].setScreenZ(rw::im2d::GetNearZ());
|
vtx_dst[i].setScreenZ(rw::im2d::GetNearZ());
|
||||||
vtx_dst[i].setCameraZ(cam->nearPlane);
|
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].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].setU(vtx_src[i].uv.x, recipZ);
|
||||||
vtx_dst[i].setV(vtx_src[i].uv.y);
|
vtx_dst[i].setV(vtx_src[i].uv.y, recipZ);
|
||||||
}
|
}
|
||||||
vtx_dst += cmd_list->VtxBuffer.Size;
|
vtx_dst += cmd_list->VtxBuffer.Size;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,12 @@ cameraSync(ObjectWithFrame *obj)
|
|||||||
Camera *cam = (Camera*)obj;
|
Camera *cam = (Camera*)obj;
|
||||||
Matrix inv, proj;
|
Matrix inv, proj;
|
||||||
Matrix::invertOrthonormal(&inv, cam->getFrame()->getLTM());
|
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 xscl = 1.0f/(2.0f*cam->viewWindow.x);
|
||||||
float32 yscl = 1.0f/(2.0f*cam->viewWindow.y);
|
float32 yscl = 1.0f/(2.0f*cam->viewWindow.y);
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ struct Im2DVertex
|
|||||||
void setCameraZ(float32 z) { }
|
void setCameraZ(float32 z) { }
|
||||||
void setRecipCameraZ(float32 recipz) { this->w = recipz; }
|
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 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 setU(float32 u, float recipZ) { this->u = u; }
|
||||||
void setV(float32 v) { this->v = v; }
|
void setV(float32 v, float recipZ) { this->v = v; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void setD3dMaterial(D3DMATERIAL9 *mat9);
|
void setD3dMaterial(D3DMATERIAL9 *mat9);
|
||||||
|
@ -114,8 +114,8 @@ struct Im2DVertex
|
|||||||
void setRecipCameraZ(float32 recipz) { }
|
void setRecipCameraZ(float32 recipz) { }
|
||||||
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||||
this->r = r; this->g = g; this->b = b; this->a = a; }
|
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||||
void setU(float32 u) { this->u = u; }
|
void setU(float32 u, float recipz) { this->u = u; }
|
||||||
void setV(float32 v) { this->v = v; }
|
void setV(float32 v, float recipz) { this->v = v; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs);
|
void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs);
|
||||||
|
@ -29,12 +29,14 @@ printScreen(const char *s, float32 x, float32 y)
|
|||||||
curVert = 0;
|
curVert = 0;
|
||||||
curIndex = 0;
|
curIndex = 0;
|
||||||
float32 u, v, du, dv;
|
float32 u, v, du, dv;
|
||||||
|
float recipZ;
|
||||||
|
|
||||||
cam = (Camera*)engine->currentCamera;
|
cam = (Camera*)engine->currentCamera;
|
||||||
vert = &vertices[curVert];
|
vert = &vertices[curVert];
|
||||||
ix = &indices[curIndex];
|
ix = &indices[curIndex];
|
||||||
du = curfont->glyphwidth/(float32)curfont->tex->raster->width;
|
du = curfont->glyphwidth/(float32)curfont->tex->raster->width;
|
||||||
dv = curfont->glyphheight/(float32)curfont->tex->raster->height;
|
dv = curfont->glyphheight/(float32)curfont->tex->raster->height;
|
||||||
|
recipZ = 1.0f/cam->nearPlane;
|
||||||
while(c = *s){
|
while(c = *s){
|
||||||
if(c >= curfont->numglyphs)
|
if(c >= curfont->numglyphs)
|
||||||
c = 0;
|
c = 0;
|
||||||
@ -45,40 +47,40 @@ printScreen(const char *s, float32 x, float32 y)
|
|||||||
vert->setScreenY(y);
|
vert->setScreenY(y);
|
||||||
vert->setScreenZ(rw::im2d::GetNearZ());
|
vert->setScreenZ(rw::im2d::GetNearZ());
|
||||||
vert->setCameraZ(cam->nearPlane);
|
vert->setCameraZ(cam->nearPlane);
|
||||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
vert->setRecipCameraZ(recipZ);
|
||||||
vert->setColor(255, 255, 255, 255);
|
vert->setColor(255, 255, 255, 255);
|
||||||
vert->setU(u);
|
vert->setU(u, recipZ);
|
||||||
vert->setV(v);
|
vert->setV(v, recipZ);
|
||||||
vert++;
|
vert++;
|
||||||
|
|
||||||
vert->setScreenX(x+curfont->glyphwidth);
|
vert->setScreenX(x+curfont->glyphwidth);
|
||||||
vert->setScreenY(y);
|
vert->setScreenY(y);
|
||||||
vert->setScreenZ(rw::im2d::GetNearZ());
|
vert->setScreenZ(rw::im2d::GetNearZ());
|
||||||
vert->setCameraZ(cam->nearPlane);
|
vert->setCameraZ(cam->nearPlane);
|
||||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
vert->setRecipCameraZ(recipZ);
|
||||||
vert->setColor(255, 255, 255, 255);
|
vert->setColor(255, 255, 255, 255);
|
||||||
vert->setU(u+du);
|
vert->setU(u+du, recipZ);
|
||||||
vert->setV(v);
|
vert->setV(v, recipZ);
|
||||||
vert++;
|
vert++;
|
||||||
|
|
||||||
vert->setScreenX(x);
|
vert->setScreenX(x);
|
||||||
vert->setScreenY(y+curfont->glyphheight);
|
vert->setScreenY(y+curfont->glyphheight);
|
||||||
vert->setScreenZ(rw::im2d::GetNearZ());
|
vert->setScreenZ(rw::im2d::GetNearZ());
|
||||||
vert->setCameraZ(cam->nearPlane);
|
vert->setCameraZ(cam->nearPlane);
|
||||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
vert->setRecipCameraZ(recipZ);
|
||||||
vert->setColor(255, 255, 255, 255);
|
vert->setColor(255, 255, 255, 255);
|
||||||
vert->setU(u);
|
vert->setU(u, recipZ);
|
||||||
vert->setV(v+dv);
|
vert->setV(v+dv, recipZ);
|
||||||
vert++;
|
vert++;
|
||||||
|
|
||||||
vert->setScreenX(x+curfont->glyphwidth);
|
vert->setScreenX(x+curfont->glyphwidth);
|
||||||
vert->setScreenY(y+curfont->glyphheight);
|
vert->setScreenY(y+curfont->glyphheight);
|
||||||
vert->setScreenZ(rw::im2d::GetNearZ());
|
vert->setScreenZ(rw::im2d::GetNearZ());
|
||||||
vert->setCameraZ(cam->nearPlane);
|
vert->setCameraZ(cam->nearPlane);
|
||||||
vert->setRecipCameraZ(1.0f/cam->nearPlane);
|
vert->setRecipCameraZ(recipZ);
|
||||||
vert->setColor(255, 255, 255, 255);
|
vert->setColor(255, 255, 255, 255);
|
||||||
vert->setU(u+du);
|
vert->setU(u+du, recipZ);
|
||||||
vert->setV(v+dv);
|
vert->setV(v+dv, recipZ);
|
||||||
vert++;
|
vert++;
|
||||||
|
|
||||||
*ix++ = curVert;
|
*ix++ = curVert;
|
||||||
|
@ -251,15 +251,16 @@ im2dtest(void)
|
|||||||
0, 1, 2, 3
|
0, 1, 2, 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float recipZ = 1.0f/Scene.camera->nearPlane;
|
||||||
for(i = 0; i < 4; i++){
|
for(i = 0; i < 4; i++){
|
||||||
verts[i].setScreenX(vs[i].x);
|
verts[i].setScreenX(vs[i].x);
|
||||||
verts[i].setScreenY(vs[i].y);
|
verts[i].setScreenY(vs[i].y);
|
||||||
verts[i].setScreenZ(rw::im2d::GetNearZ());
|
verts[i].setScreenZ(rw::im2d::GetNearZ());
|
||||||
verts[i].setCameraZ(Scene.camera->nearPlane);
|
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].setColor(vs[i].r, vs[i].g, vs[i].b, vs[i].a);
|
||||||
verts[i].setU(vs[i].u);
|
verts[i].setU(vs[i].u, recipZ);
|
||||||
verts[i].setV(vs[i].v);
|
verts[i].setV(vs[i].v, recipZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
rw::engine->imtexture = tex2;
|
rw::engine->imtexture = tex2;
|
||||||
@ -324,9 +325,9 @@ Draw(float timeDelta)
|
|||||||
camera->update();
|
camera->update();
|
||||||
camera->m_rwcam->beginUpdate();
|
camera->m_rwcam->beginUpdate();
|
||||||
|
|
||||||
Scene.clump->render();
|
// Scene.clump->render();
|
||||||
// im2dtest();
|
// im2dtest();
|
||||||
// tlTest(Scene.clump);
|
tlTest(Scene.clump);
|
||||||
// im3dtest();
|
// im3dtest();
|
||||||
// printScreen("Hello, World!", 10, 10);
|
// printScreen("Hello, World!", 10, 10);
|
||||||
|
|
||||||
@ -380,11 +381,23 @@ KeyDown(int key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MouseMove(int x, int y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MouseButton(int buttons)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
sk::EventStatus
|
sk::EventStatus
|
||||||
AppEventHandler(sk::Event e, void *param)
|
AppEventHandler(sk::Event e, void *param)
|
||||||
{
|
{
|
||||||
using namespace sk;
|
using namespace sk;
|
||||||
Rect *r;
|
Rect *r;
|
||||||
|
MouseState *ms;
|
||||||
|
|
||||||
switch(e){
|
switch(e){
|
||||||
case INITIALIZE:
|
case INITIALIZE:
|
||||||
Init();
|
Init();
|
||||||
@ -399,8 +412,20 @@ AppEventHandler(sk::Event e, void *param)
|
|||||||
case KEYUP:
|
case KEYUP:
|
||||||
KeyUp(*(int*)param);
|
KeyUp(*(int*)param);
|
||||||
return EVENTPROCESSED;
|
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:
|
case RESIZE:
|
||||||
r = (Rect*)param;
|
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.width = r->w;
|
||||||
sk::globals.height = r->h;
|
sk::globals.height = r->h;
|
||||||
// TODO: set aspect ratio
|
// TODO: set aspect ratio
|
||||||
|
@ -87,8 +87,8 @@ drawAtomic(Atomic *a)
|
|||||||
im2dverts[i].setCameraZ(xvert[i].z);
|
im2dverts[i].setCameraZ(xvert[i].z);
|
||||||
im2dverts[i].setRecipCameraZ(recipZ);
|
im2dverts[i].setRecipCameraZ(recipZ);
|
||||||
im2dverts[i].setColor(255, 0, 0, 255);
|
im2dverts[i].setColor(255, 0, 0, 255);
|
||||||
im2dverts[i].setU(texcoords[i].u);
|
im2dverts[i].setU(texcoords[i].u, recipZ);
|
||||||
im2dverts[i].setV(texcoords[i].v);
|
im2dverts[i].setV(texcoords[i].v, recipZ);
|
||||||
}
|
}
|
||||||
for(int32 i = 0; i < mh->numMeshes; i++){
|
for(int32 i = 0; i < mh->numMeshes; i++){
|
||||||
for(uint32 j = 0; j < m[i].numIndices; j++){
|
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].setCameraZ(pos.z);
|
||||||
clipverts[i].setRecipCameraZ(recipZ);
|
clipverts[i].setRecipCameraZ(recipZ);
|
||||||
clipverts[i].setColor(c.red, c.green, c.blue, c.alpha);
|
clipverts[i].setColor(c.red, c.green, c.blue, c.alpha);
|
||||||
clipverts[i].setU(objverts[i].u);
|
clipverts[i].setU(objverts[i].u, recipZ);
|
||||||
clipverts[i].setV(objverts[i].v);
|
clipverts[i].setV(objverts[i].v, recipZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user