Float to Pixel

Started by
16 comments, last by vs322 15 years, 7 months ago
Quote:Original post by SlickKobra
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);



Are you sure this is correct?
Do the particles simply get the wrong size but correct relative-to-distance size scale, or is the distance-to-size scale wrong?
Try ActualSize = Constant * GPRSize / Z-Distance-to-particle and see what happens.
Advertisement
Thanks for the post :D.

I don't really understand what you said but i'm guessing it has to do with the z axis... well, i'm not really using the z axis; rather just x and y. If my particle was 2cm by 2cm big(in real life) then the rectangle which should also be the same is instead something like 1.5cm by 1.5cm big. What I just said in my last sentence is infact the problem... the rectangle is smaller then the actual circle.

Please help me out because my program's status is at a stand-still :(!

Thanks man!
I think you should try something like this, not entirely sure though:
Project the particle position as you do, and save that projected position.
Then for the size part, multiply your world position with the View matrix only, so that you get the viewspace position. That is the position relative to your camera.
Then add the particle's size X/Y to that viewspace position, and then project that result. Now you will have a projected version of a worldspace size, which I think is what you want.

So it would be something like:
ParticlePos = D3DXVec3Project(GPRPos, ....);ViewPos = GPRPos * View;ViewPos.x += GPRSize;ViewPos.y += GPRSize;TempSize1 = ViewPos * Projection;x = TempSize1.x - ParticlePos.x;y = TempSize1.y - ParticlePos.y;
Sorry for my idiosity :( I just don't get it. Could you please edit my function so that it will do... what I want it to?

Thanks.
I'm not sure, I have no D3D9 project to test it with and see if it gives the correct results, which I'm still a bit unsure what they are =)
But try this:
GPRSize is the size the particle should have in worldspace.

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);  // Replace the second Project with this... D3DXVECTOR4	TempSize4, TempSize42; D3DXVec3Transform(&TempSize4, &GPRPos, &View); TempSize4.x += GPRSize; TempSize4.y += GPRSize; D3DXVec4Transform(&TempSize42, &TempSize4, &Projection); TempSize1 = D3DXVECTOR3(TempSize42); // 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;}
Thanks for trying man! But sadly no dice :(. The particles go straight up(while wiggling).

But damn it! What's so wrong with my code that I showed everyone? The mathamatics seem correct. I mean... ugh. I just don't know what to do... are there any documents/tutorials online that teach you how to get a border of an object in world space?

Thanks for the effort to help!
Try allocating space for your ActualSize vector. I'm not familiar with d3d but I don't see anything in your code to either get it from somewhere else or malloc or new. I'm surprised you're not seg faulting.

You probably want to call the constructor somehow for the D3DXVECTOR3 and store its return in ActualSize.

Edit:

ActualSize = new D3DXVECTOR3();

needs to come before

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


D3DXVECTOR3 is not a stl like container. it is just 3 DOUBLES pact together.

There is no memory isue, sure he could have initialized it in some why before using it, but that's only nitpicking, not the real problem.

This topic is closed to new replies.

Advertisement