Sign in to follow this  
Overdrive

Bounding rectangles problem.

Recommended Posts

Hi guys, I am working on a simple editor for my game. It gives the possibility to select an object and move it around the emviroment. I want to be able to select the object with the mouse, and that is why I simply check if after a WM_LBUTTONDOWN, the coordinates of the mouse are inside a bounding rect for my object. The problem is that it apears that the bounding rects are not where I would expect them to be. I calculate the bounding rects like this:

RECT r;
D3DSURFACE_DESC dsc;
m_pTexture->GetLevelDesc(0, &dsc);
r.top = (LONG)  m_pos.y;
r.left = (LONG) m_pos.x;
r.right = (LONG)r.left + dsc.Width;
r.bottom = (LONG)r.top + dsc.Height;

m_pos is a 3D vector that is used in the renderer like this:
v = (*it)->GetPosition();
m_Sprite->Draw((*it)->GetTexture(), NULL, NULL, (v), D3DCOLOR_XRGB(255, 255, 255));
it = iterator used to go trough an vector<Objects> m_Sprite is a LPD3DXSPRITE. If I try to draw the the bounding rectangle (r), using:
RECT rect = gStaticObjects[i]->GetBoundingRect();
Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
Something very strange happens.The image is like this: Image Hosted by ImageShack.us<br/> Anybody has any idea why this is happening? [Edited by - Overdrive on April 22, 2008 7:20:26 AM]

Share this post


Link to post
Share on other sites
Is it possible that your not taking into account the window border.

The mouse query is returning mouse coords with respect to one frame of reference and the DX-query is returning or using coordinates with a different frame of reference.

Share this post


Link to post
Share on other sites
Quote:
Original post by BionicBytes
Is it possible that your not taking into account the window border.

The mouse query is returning mouse coords with respect to one frame of reference and the DX-query is returning or using coordinates with a different frame of reference.


Mouse coordinates from the WM_MOUSEMOVE or WM_LBUTTONDOWN messages are in client coordinates, which take borders and window menus into account for you. D3D works the same way, AFAIK. In my map editor I render sprites with ID3DXSprite and render bounding boxes with ID3DXLine, and hit-testing with WM_LBUTTONDOWN works fine.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
It looks to me like you're doing everything okay...do you ever set any transforms using ID3DXSprite::SetTransform? Also do you use the D3DX_SPRITE_OBJECTSPACE flag or anything like that when you call ID3DXSprite::Begin?


The only parameter of ID3DXSprite::Begin that i use is D3DXSPRITE_ALPAHABLEND.
This is the full code of the function that renders the static objects(the 3 blocks and background).


void CRenderer::Render(const vector< shared_ptr<StaticObject> >& object_list)
{
vector< shared_ptr<StaticObject> >::const_iterator it;

D3DXMATRIX m;
D3DXMATRIX prevMtx;
D3DXVECTOR3 v;


//Draw the stuff here.
m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);

for (it = object_list.begin(); it!=object_list.end(); ++it)
{
v = (*it)->GetPosition();
m_Sprite->Draw((*it)->GetTexture(), (*it)->GetRect(), NULL, &(v), D3DCOLOR_XRGB(255, 255, 255));
}
m_Sprite->End();
}


In the code for the dynamic objects i use a SpriteTransform to rotate the sprite (for example if the player is walking left, and the original sprite is with the player walking to the right).
But I use GetTransform(&m) and a SetTransform(&m) before and after that in order to preserve the original transformation matrix.
I think that the problem might be with the Rectangle(hDC,...).
I'll try to draw the bounding lines with ID3DXLine().


Later Edit: It worked as expected after i used ID3DXLine() to draw the bounding rectangles for the objects.
Thanks for the help guys :)

[Edited by - Overdrive on April 22, 2008 12:14:00 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this