Jump to content
  • Advertisement
Sign in to follow this  
SlickKobra

Float to Pixel

This topic is 3724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys this is my first post! Recently I had the same problem as someone known as WinRad - How to convert a world space value to a screen space one, but by reading the replies figured that out. Suprisingly though I also had the size problem same as WinRad, which was answered by someone. Although I understood it my function still messed up and I'm hoping you pros could take a look ---> [code = C++] RECT ParticleSystem::GetParticleRect(D3DXVECTOR3 GPRPos, FLOAT GPRSize) { INT Left, Top, Right, Bottom; RECT ParticlePosition; D3DXMATRIX View, Projection, Identity; D3DVIEWPORT9 VP; D3DXVECTOR3 ParticlePos, TempSize1, ActualSize; GameInformation.D3DDevice->GetTransform(D3DTS_VIEW, &View); GameInformation.D3DDevice->GetTransform(D3DTS_PROJECTION, &Projection); GameInformation.D3DDevice->GetViewport(&VP); D3DXMatrixIdentity(&Identity); D3DXVec3Project(&ParticlePos, &GPRPos, &VP, &Projection, &View, &Identity); D3DXVec3Project(&TempSize1, &D3DXVECTOR3(GPRPos.x + GPRSize, GPRPos.y + GPRSize, 0.0f), &VP, &Projection, &View, &Identity); ActualSize.x = (TempSize1.x - ParticlePos.x); ActualSize.y = (TempSize1.y - ParticlePos.y); Left = ParticlePos.x - ActualSize.x; Top = ParticlePos.y - ActualSize.y; Right = ParticlePos.x + ActualSize.x; Bottom = ParticlePos.y + ActualSize.y; SetRect(&ParticlePosition, Left, Top, Right, Bottom); return ParticlePosition; } Basicly it should work out the borders of my particle yet it doesn't. What happens instead is the it works out the centre of my particle so left, top, right and bottom are equal to the centre. Thanks!!!

Share this post


Link to post
Share on other sites
Advertisement
I was thinking about this post yesterday but couldn't come to a conclusion worth posting.

Part of me thinks your approach is mathematically flawed as the shape is view dependent, and whilst that is desirable I wondered if you had to handle it in a different way...

You can fairly easily break down the D3DXVec3Project() operation into component matrix operations and step through it. I'd highly recommend you do some step-through debugging of known test data and identity matrices and go back to first principles. It should become clear which operation or which bit of data is not doing what you expect it to.

hth
Jack

Share this post


Link to post
Share on other sites
Hard to say from your code. I'd suggest running your program in debug, and verifying that GPRSize is non-zero.

Share this post


Link to post
Share on other sites
Thanks for the replies, currently I do get the correct results for the centre of the particle, but when it comes to the size it just ain't workin' for me... so I think the problem may be with the GPRSize variablr... I'll check it when I get home and tell you guys my report.

Share this post


Link to post
Share on other sites
Well I tested the variable and it seems that the variable is being passed the correct value... but there was a problem and it was that the value ended being negative so I just reversed it and it started working but yet there is another problem; the rectangle around the circle is too small for some reason so I multiplicated the value for it by two... but I think there is something wrong and I just don't get it. Here's the new code --->


RECT ParticleSystem::GetParticleRect(D3DXVECTOR3 GPRPos, FLOAT GPRSize)
{

INT Left, Top, Right, Bottom;
RECT ParticlePosition;
D3DXMATRIX View, Projection, Identity;
D3DVIEWPORT9 VP;
D3DXVECTOR3 ParticlePos, TempSize1, ActualSize;

GameInformation.D3DDevice->GetTransform(D3DTS_VIEW, &View);
GameInformation.D3DDevice->GetTransform(D3DTS_PROJECTION, &Projection);
GameInformation.D3DDevice->GetViewport(&VP);

D3DXMatrixIdentity(&Identity);
D3DXVec3Project(&ParticlePos, &GPRPos, &VP, &Projection, &View, &Identity);
D3DXVec3Project(&TempSize1, &D3DXVECTOR3(GPRPos.x + GPRSize, GPRPos.y + GPRSize, 0.0f), &VP, &Projection, &View, &Identity);

ActualSize.x = -(TempSize1.x - ParticlePos.x); //Reversed
ActualSize.y = -(TempSize1.y - ParticlePos.y); //Reversed

Left = ParticlePos.x - ActualSize.x * 2; //Temporarily the
Top = ParticlePos.y - ActualSize.y * 2; //values have been multiplicated
Right = ParticlePos.x + ActualSize.x * 2; //as the rectangle is just too
Bottom = ParticlePos.y + ActualSize.y * 2; //small...

SetRect(&ParticlePosition, Left, Top, Right, Bottom);

return ParticlePosition;

}


Any ideas on what went wrong?

Thanks.

[Edited by - SlickKobra on August 22, 2008 9:57:19 PM]

Share this post


Link to post
Share on other sites
LEFT, TOP, RIGHT, and BOTTOM are integers. If the particle size is very small (less than a pixel), it'll be rounded down to zero. Try making float versions of those and checking them out in a debugger.

Share this post


Link to post
Share on other sites
You mind me tellin' you that I love you? Hehe joking :).

It seems so obvious now! I'll go home and use D3DXVECTOR4(from memory) for the rectangle instead of a RECT struct. It will probably work though.

Unless I reply again - This thread is resolved.

Share this post


Link to post
Share on other sites
Unblievable! For some reason I'm basically getting the same results! Well here's the updated code and yet I still don't know what's wrong :( -


D3DXVECTOR4 ParticleSystem::GetParticleRect(D3DXVECTOR3 GPRPos, FLOAT GPRSize)
{

D3DVIEWPORT9 VP;
D3DXMATRIX View, Projection, Identity;
D3DXVECTOR3 ParticlePos, TempSize1, ActualSize;
D3DXVECTOR4 ParticleRectangle;
FLOAT Left, Top, Right, Bottom;

GameInformation.D3DDevice->GetTransform(D3DTS_VIEW, &View);
GameInformation.D3DDevice->GetTransform(D3DTS_PROJECTION, &Projection);
GameInformation.D3DDevice->GetViewport(&VP);

D3DXMatrixIdentity(&Identity);
D3DXVec3Project(&ParticlePos, &GPRPos, &VP, &Projection, &View, &Identity);
D3DXVec3Project(&TempSize1, &D3DXVECTOR3(GPRPos.x + GPRSize, GPRPos.y + GPRSize, 0.0f), &VP, &Projection, &View, &Identity);

ActualSize.x = -(TempSize1.x - ParticlePos.x);
ActualSize.y = -(TempSize1.y - ParticlePos.y);

Left = ParticlePos.x - ActualSize.x;
Top = ParticlePos.y - ActualSize.y;
Right = ParticlePos.x + ActualSize.x;
Bottom = ParticlePos.y + ActualSize.y;

ParticleRectangle.w = Left;
ParticleRectangle.x = Top;
ParticleRectangle.y = Right;
ParticleRectangle.z = Bottom;

return ParticleRectangle;

}


If you even have the slightest of clues on what may be wrong then please say so.

Thanks :(.

Share this post


Link to post
Share on other sites
Guys isn't there anything wrong with the code? I mean its throwing me false values everywhere... Can someone please just tell me what is wrong with the code? Or please make a function of your own that takes a central position of a particle and size and then returns a D3DXVECTOR4 variable which is the boundary of the particle.

The central position(where the particle is) variable = D3DXVECTOR3 Pos.
The size of the particle = FLOAT Size;

Thanks you!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!