[Resolved]Spherical billboarding using matrices
The transpose of the original matrix I showed you, which I calculated in a further post. I just made it bold to make it stand out.
P = WorldCameraPosition - WorldParticlePosition
Matrix =
1 0 0 0
0 1 0 0
0 0 1 0
P.x P.y P.z 1
Using this, everything is projected a distance behind the camera. If P = WorldParticlePosition - WorldCameraPosition then everything is projected a distance infront of the camera, further than their positions were before, and still no billboarding. I'm setting this matrix as my world matrix.
Matrix =
1 0 0 0
0 1 0 0
0 0 1 0
P.x P.y P.z 1
Using this, everything is projected a distance behind the camera. If P = WorldParticlePosition - WorldCameraPosition then everything is projected a distance infront of the camera, further than their positions were before, and still no billboarding. I'm setting this matrix as my world matrix.
Yeah, that isn't correct.
Ok, the particle as at position P (in world space), and the camera is at position C (again in world space).
Firstly, you'll need to calculate the "front" vector of the particle, which would be:
F = C-P
Using the particles up vector as (0,1,0) helps to calculate the side vector like so:
S = U x F
(where here U = [0,1,0])
We then recalculate U to it's actual value using the cross product of the front and side vector. Note that you will get a little artifact when F and U get very close (the particle will spin as F passes over U - however this isn't very noticable).
You then normalise all the basis vectors (U, F, and S), and plonk them in the matrix along with P, and add to the transformation pipeline.
P is not the vector from the particle to the camera - as you have calculated it to be. It is simply the particles position in world space.
Ok, the particle as at position P (in world space), and the camera is at position C (again in world space).
Firstly, you'll need to calculate the "front" vector of the particle, which would be:
F = C-P
Using the particles up vector as (0,1,0) helps to calculate the side vector like so:
S = U x F
(where here U = [0,1,0])
We then recalculate U to it's actual value using the cross product of the front and side vector. Note that you will get a little artifact when F and U get very close (the particle will spin as F passes over U - however this isn't very noticable).
You then normalise all the basis vectors (U, F, and S), and plonk them in the matrix along with P, and add to the transformation pipeline.
P is not the vector from the particle to the camera - as you have calculated it to be. It is simply the particles position in world space.
Thanks, worked like a charm. I tried to rate you up a while back to extremely helpful, but for some reason, I get the error message "you can only rate one user at a time"
Final code used
Final code used
Dim F As Vector3 = Camera.Position - Position Dim S As Vector3 = Vector3.Cross(New Vector3(0, 1, 0), F) Dim U As Vector3 = Vector3.Cross(S, F) F.Normalize() S.Normalize() U.Normalize() Dim matBillboard As Matrix = Matrix.Identity With matBillboard .M11 = S.X .M12 = S.Y .M13 = S.Z .M14 = 0 .M21 = U.X .M22 = U.Y .M23 = U.Z .M24 = 0 .M31 = F.X .M32 = F.Y .M33 = F.Z .M34 = 0 .M41 = Pos.X .M42 = Pos.Y .M43 = Pos.Z .M44 = 1 End With
Watch out so that your lookat vector never becomes exactly (0,1,0) :) you could also test for this and modify your cross products in this case.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement