Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

View oriented Nebula effect

Started by MikeyO 6 replies 1.4k views
Original Post
MikeyO
MikeyO
I'm trying to create a background nebula effect (in space), I've got it all set up. It's view oriented, but when I turn the camera, the Nebula turns WITH the camera, and I need it to... not turn, but stay static. This is how it looks when facing the planet, But as I turn toward the nebula, it gets closer & closer to the camera, until it eventually passes through. So does anybody have any suggestions, or see where I'm going wrong in my drawing code:

device.Transform.World = Matrix.RotationX(0) * Matrix.RotationY(0) *
	Matrix.RotationZ(0) * Matrix.Translation(0,0,0);

nebulaSprite.SetWorldViewLH(World, View);
sectorNebulas n = (sectorNebulas)Nebula[index];
nebulaSprite.Begin(SpriteFlags.SortTexture | SpriteFlags.Billboard | SpriteFlags.ObjectSpace);
for(int i = 0; i < n.numNebulas; i++)
{
	nebulaSprite.Transform = // Matrix.RotationYawPitchRoll(angle, angle, angle) * 
		Matrix.Scaling(n.Scale, n.Scale, n.Scale) * 
		Matrix.Translation(Vector3.Add(translation, n.Positions));
	Rectangle texStats = new Rectangle(0, 0, textureInfo[n.textureIndex].Width, textureInfo[n.textureIndex].Height);
	nebulaSprite.Draw(nebulaTextures[n.textureIndex],
		translation, n.Positions, 
		Color.White.ToArgb());
}
nebulaSprite.End();

MikeyO
MikeyO
Don't be shy..

Anyway, I'm kind of trying to simulate a skybox, without actually using a box, but just with sprites..
circlesoft
circlesoft
nebulaSprite.Begin(SpriteFlags.SortTexture | SpriteFlags.Billboard | SpriteFlags.ObjectSpace);


Here, you specify the Billboard flag. Billboarding automatically aligns the sprite with the camera. If you don't want the sprite to be aligned with the viewer, than remove this flag.

Note: IIRC, if you remove the Billboard flag, you don't need the nebulaSprite.SetWorldViewLH(World, View); function call anymore.
MikeyO
MikeyO
Yes, thank you 8-)

I already knew that, and it doesn't really help me but thanks for replying. My question is how do I get it to face the camera's position initially, and then just stay like it is, so it doesn't rotate anymore, then I can just translate it with the camera when the camera moves.
sirob
sirob
Ahhh, I had this problem with my skybox :).

What I ended up doing was seperating the translation part of my view matrix from the rotation.

This did force me to reconstruct the view matrix every time I changed it, but I could then only use the translation part (and in your case you can add a fixed rotation -- to make sure it faces the camera) for the skybox drawing.

This does make things a little more difficult when it comes to moving the camera, but I found this was the best way to go.

I hope this is enough, as if you need more info :).
Sirob Yes.» - status: Work-O-Rama.
MikeyO
MikeyO
Right, I know I'll need to rotate it in the Sprite.Translation line.. but I'm stuck on figuring out how to know how to set up the Matrix.RotationYawPitchRoll() so that it will face the camera.
MikeyO
MikeyO
I'm trying to do what you did sirob, but still unsure exactly what you did.. do you have any of your code still?
sirob
sirob
The thing is, I used this method to make a skybox. Since it's a cube, I didn't really have an issue with making it face the camera, I just made a cube around the camera position.

What you need is a tutorial on how to manually set the rotation for a billboard. Heres one I found, I'm sure you'll be able to find more: http://www.opengl.org/resources/tutorials/advanced/advanced97/notes/node31.html...

Good luck :).

[EDIT] Also, since your billboard is moving with the camera, the calculation would only need to be performed once, leaving the rotation the same throughout the entire app.
Sirob Yes.» - status: Work-O-Rama.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.