 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Sat Apr 30, 2011 11:00 pm Post subject: [C++][Direct3D] Drawing line in world coordinates |
|
|
I'm trying to draw a 3D line using world coordinates in my EndScene hook.
I had no problems when trying to draw in screen coordinates. However for some reason when trying to draw a line in 3D, it does not seem to be getting rendered.
| Code: |
HRESULT WINAPI EndScene(IDirect3D9* This) {
if(render) {
DWORD zBuffer;
DWORD lighting;
DWORD fvf;
LPDIRECT3DBASETEXTURE9 texture;
IDirect3DVertexShader9* vertexShader;
// Save
d3dDev->GetFVF(&fvf);
d3dDev->GetTexture(0, &texture);
d3dDev->GetVertexShader(&vertexShader);
d3dDev->GetRenderState(D3DRS_LIGHTING, &lighting);
d3dDev->GetRenderState(D3DRS_ZENABLE, &zBuffer);
// Set
d3dDev->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
d3dDev->SetTexture(0, NULL);
d3dDev->SetVertexShader(0);
d3dDev->SetRenderState(D3DRS_LIGHTING, FALSE);
d3dDev->SetRenderState(D3DRS_ZENABLE, TRUE);
drawLine(d3dDev, 460.0f, 27.0f, 73.0f, 460.0f, 200.0f, 73.0f, D3DCOLOR_ARGB(255, 255, 0, 0));
// Restore
d3dDev->SetFVF(fvf);
d3dDev->SetTexture(0, texture);
d3dDev->SetVertexShader(vertexShader);
d3dDev->SetRenderState(D3DRS_LIGHTING, lighting);
d3dDev->SetRenderState(D3DRS_ZENABLE, zBuffer);
}
return oEndScene(This);
}
|
| Code: |
void drawLine(IDirect3DDevice9* device, float x1, float y1, float z1, float x2, float y2, float z2, COLORREF color) {
D3DTLVERTEX vertex[2];
vertex[0] = D3DTLVERTEX(x1, y1, z1, 1.0f, color);
vertex[1] = D3DTLVERTEX(x2, y2, z2, 1.0f, color);
if(device->DrawPrimitiveUP(D3DPT_LINELIST, 1, &vertex, sizeof(D3DTLVERTEX)) != D3D_OK)
console("drawLine failed");
}
|
Last edited by 661089799107 on Mon May 09, 2011 2:08 pm; edited 2 times in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun May 01, 2011 1:46 am Post subject: |
|
|
taking shots in the dark
i'd probably disable the depth buffer first, maybe other geometry is occluding it
your vertex definition is suspect. D3DTLVERTEX looks ancient, don't know why you're using it. if you want to draw strictly in 2d, use an orthogonal projection or D3DFVF_XYZRHW (and THEN introduce W)
| Code: | | D3DFVF_XYZ | D3DFVF_DIFFUSE |
should just be a struct like:
| Code: | struct AWESOMEVERT
{
f32 x, y, z;
u32 color;
}; |
|
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Sun May 01, 2011 2:27 am Post subject: |
|
|
| Quote: | | if you want to draw strictly in 2d, use an orthogonal projection or D3DFVF_XYZRHW (and THEN introduce W) |
I used D3DFVF_XYZRHW when I was drawing in 2D previously(to test my hook), and it worked fine. I only want to draw in 3D though.
| Quote: | | your vertex definition is suspect. D3DTLVERTEX looks ancient |
This is my D3DTLVERTEX:
| Code: |
class D3DTLVERTEX {
public:
float x;
float y;
float z;
float rhw;
DWORD color;
D3DTLVERTEX() {}
D3DTLVERTEX(float x, float y, float z, float rhw, DWORD color) {
this->x = x;
this->y = y;
this->z = z;
this->rhw = rhw;
this->color = color;
}
};
|
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun May 01, 2011 2:33 am Post subject: |
|
|
drop the rhw part of the struct if you aren't using it. make sure you're trying to send a vertex that matches the format you specified. you can also use a D3DXVECTOR3
setting the reciprocal of homogeneous w to 1 effectively does nothing in the perspective divide since you (hopefully) already have your coordinates in screen space, hence why it's useful for 2d.
|
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Sun May 01, 2011 2:58 am Post subject: |
|
|
| slovach wrote: | | drop the rhw part of the struct if you aren't using it. |
After removing the rhw, it still does not work.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun May 01, 2011 3:55 am Post subject: |
|
|
are you sure you're drawing it somewhere it's actually visible?
check the dx debug runtime info / returns.
|
|
| Back to top |
|
 |
661089799107 Expert Cheater
Reputation: 3
Joined: 25 Jan 2009 Posts: 186
|
Posted: Wed May 11, 2011 6:17 am Post subject: |
|
|
| slovach wrote: | are you sure you're drawing it somewhere it's actually visible?
check the dx debug runtime info / returns. |
It's not being drawn near any other object.
I can use the game's in-game console command to draw a line with the same coordinates.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed May 11, 2011 9:37 am Post subject: |
|
|
| I keep seeing you bump this but I don't know. Disable the depth buffer and culling and try to draw something obnoxious that's impossible to miss. The D3D debug output might have something interesting to say, failing that.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|