Sign in to follow this  
sqpat

upside down billboards? [solved]

Recommended Posts

I'm having trouble with textures on my billboards; they're rendering upside down (flipped in the Z coordinate). I searched and found some other topics on the subject but the suggested solutions I keep seeing people say to scale the matrix negative in the Z. When i do this, the billboarding system gets messed up; the sprite stops facing the screen in the z coordinate, so when you rotate the camera upward, the sprite starts to disappear. This obviously isn't good! Im using D3DXSprites. I tried flipping the top/bottom coordinates of the rectangle argument and that didnt do anything, either. Since im using D3DXSprites i have no u/v cooridnates to work with. Is there another way to flip this without flipping it in the image file? Like, when I load the texture, maybe I flip it there? So close to my little engine being correct!! :) here is my code in the area right now in case anyone sees something:
     for (int x = 0; x < numChars; x++){  // draw all char sprites

         charSprites[x]->Begin(D3DXSPRITE_ALPHABLEND| D3DXSPRITE_OBJECTSPACE  ); 

         // calculate scaling matrix
         D3DXMATRIX scaleMat;
         D3DXMatrixScaling(&scaleMat, (1.f/64),(1.f/64),(1.f/64));
		 
         // get inverse of view mat
         D3DXMATRIX inverseMat;
         D3DXMatrixInverse(&inverseMat, NULL, &m_View);
         
         // set translation to 0 for inverse mat
         inverseMat._41 = 0.0f;
         inverseMat._42 = 0.0f;
         inverseMat._43 = 0.0f;
            
         // multiply em together
         D3DXMATRIX result;
         D3DXMatrixMultiply(&result,&inverseMat,&scaleMat); 

         // apply translation
         result._41 = charPos[x].x;
         result._42 = charPos[x].y;
         result._43 = charPos[x].z+.25f;

         charSprites[x]->SetTransform(&result);

         RECT tempRect;
         SetRect(&tempRect, 64*(1+charCameraDir[x]), 64*charCurrentFrame[x], 64*charCameraDir[x], 64*(charCurrentFrame[x]+1));
         
         charSprites[x]->Draw(charSpriteFrames[x],
             &tempRect,
             NULL,
             NULL,
             0xffffffff);

         charSprites[x]->End();
     }
[Edited by - sqpat on July 28, 2008 4:06:41 PM]

Share this post


Link to post
Share on other sites
Just one tip real Quick- you only need the sprite->begin and ->end once, your rendering will be MUCH faster if you do it this way, you only need 1 sprite object in this example too.

Also are you sure you don't want to be changing y values rather than z? (y is up in the DX cords system)

And if you are actually Billboarding the sprites let the sprite frame-work do the work for you: D3DXSPRITE_BILLBOARD, and make sure you set the world view for them:

D3DXMATRIX sptView;
pd3dDevice->GetTransform(D3DTS_VIEW, &sptView);
Sprites->SetWorldViewLH(NULL,&sptView);

An issue I have run into using D3DXMatrixScaling is that it may scale the other transforms as well, so watch out for that. You may also have an issue with scaling the sprite while not using the full texture, but not setting a center for the texture, it scales from that center (I believe, someone correct me if I'm wrong). Hope that helps.
-vs

Share this post


Link to post
Share on other sites
Quote:
Original post by vs322
Just one tip real Quick- you only need the sprite->begin and ->end once, your rendering will be MUCH faster if you do it this way, you only need 1 sprite object in this example too.


OK! I'll keep that in mind. I assume i use the flush method to clear out the transformations then? And yeah, it really doesnt look like multiple sprite objects are needed. (However, i've only been testing with one thing on screen to this point anyway.)

Quote:
Original post by vs322
Also are you sure you don't want to be changing y values rather than z? (y is up in the DX cords system)


My up vector is actually (0,0,1). Fine by me because Z being up and x/y being the main movement plane works intuitively in my favor.

Quote:
Original post by vs322
And if you are actually Billboarding the sprites let the sprite frame-work do the work for you: D3DXSPRITE_BILLBOARD, and make sure you set the world view for them:

D3DXMATRIX sptView;
pd3dDevice->GetTransform(D3DTS_VIEW, &sptView);
Sprites->SetWorldViewLH(NULL,&sptView);


I tried that flag but when i use it the sprites disappear and i have no idea what happened to them. I eventually resorted to this method i found on a FAQ somewhere.


Quote:
Original post by vs322
An issue I have run into using D3DXMatrixScaling is that it may scale the other transforms as well, so watch out for that. You may also have an issue with scaling the sprite while not using the full texture, but not setting a center for the texture, it scales from that center (I believe, someone correct me if I'm wrong). Hope that helps.
-vs


Yeah, I saw that and modified the center vector to (0, 32, 0) (i.e. the bottom of the 64x64 sprite)



As for my original problem i just ended up writing a little program that takes in a 24-bit color bitmap and spits out another with sets of 64 lines of pixels flipped over. I can live with things that way.

Share this post


Link to post
Share on other sites
that actually messed up the billboarding which is why i didnt do it.

however, everything is fine now since i wrote that little sprite flipping program. sorry, should have marked this solved!

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