Jump to content
  • Advertisement
Sign in to follow this  
CadeF

Billboarding problem - Billboards work but I dont want them to rotate on the y axis

This topic is 4757 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

I got billboards working properly (to use ShaderX's texture perturbation fire effect) in my 3d engine and I only want it to rotate on the x and z axis (horizontally, not vertically). Code used DXmatWorld = Matrix.Identity DXmatTemp = Matrix.Identity DXmatTemp = Matrix.TransposeMatrix(DXmatView) With DXmatTemp .M14 = 0 .M24 = 0 .M34 = 0 .M41 = 0 .M42 = 0 .M43 = 0 End With D3DDevice.SetTransform(TransformType.World, DXmatTemp) D3DDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, FireVert.Length / 2, FireVert) DXmatWorld = Matrix.Identity D3DDevice.SetTransform(TransformType.World, DXmatWorld) It works great for particles (the matrix), but I want it to preserve the y axis using this code. Any ideas? Edit: Fire is rendered at 0,0,0 (for now). That is why M41,M42,M43 are 0,0,0.

Share this post


Link to post
Share on other sites
Advertisement
If i get you right, then you want it to point towards the camera but without losing up = y?

Share this post


Link to post
Share on other sites
Well i admit i'm having a guess here but have you tried removing the y component of the view matrix before you transpose it, and then adding it back in after the view has been transposed?

This might make sense, but im actually in a class at uni now, so havn't got the time to look it up.

ace

Share this post


Link to post
Share on other sites
I have just recently been working on billboarding myself. I posted something here not too long ago about not being able to use the D3DXMatrixTranspose function, but I found a workaround. I only used it on the y axis, but I don't think it would be too hard to adapt to just the x and z.

Firstly I found the position of the viewport (x, y, and z) and the position of the thing to be rotated (x, y, and z). Using these values, I found the difference in positions for all the axis (no idea what the plural of axis is). So here I would have something like this (this is in C++):

float x, y, z, x1, y1, z1; // x, y, and z are the viewport
float XDiff, YDiff, ZDiff;
float XRot, ZRot;

XDiff = (float)x - x1;
YDiff = (float)y - y1;
ZDiff = (float)z - z1;

It's late-ish here in Australia, and I have school tomorrow, so I may have missed out some steps (you might need to use some Pythagoras in here to find the differences, but I'm not sure). But anyway, then I used inverse tan to figure out the angle it had to rotate:

XRot = -1*(atanf(YDiff/ZDiff));
ZRot = -1*(atanf(YDiff/XDiff));

Once again, I only used this while using the y-axis, so I don't know how it will work here. You might find that if the viewport is in a certain position in relation to the object, it might be flipped so it is facing away from you. To solve this you just need to put in a line like:

if(blahblahblah) XRot += 3.14;

Then when you have the rotation, use D3DXMatrixRotationX, and D3DXMatrixRotationZ, then multiply them with the world matrix, and it should work. It might take a little while to get it working properly, but that is the general gist of it.

Like I said at the beginning, I only used this because I couldn't get D3DXMatrixTranspose working. For all I know this might do something bad, but it is how I do it now (it's also how I make my enemies face towards the player!), and it works quite well for me (even if it's only on the y axis).

I really hope this helps.

Share this post


Link to post
Share on other sites
Thanks, but I figured it out...
DXmatView = Matrix.LookAtLH(RenderCamPos, New Vector3(RenderCamViewDir.X + RenderCamPos.X, RenderCamViewDir.Y + RenderCamPos.Y, RenderCamViewDir.Z + RenderCamPos.Z), CamUp)

RenderCamPos.Y = 0

DXmatViewFlat = Matrix.LookAtLH(RenderCamPos, New Vector3(RenderCamViewDir.X + RenderCamPos.X, RenderCamViewDir.Y + RenderCamPos.Y, RenderCamViewDir.Z + RenderCamPos.Z), CamUp)

I use DXmatView as the world View matrix and DXmatViewFlat as the transpose matrix...

:)

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!