This is fairly simple compared to some other maths involved in 3D engines.
I approached this in my engine by using a form of Yaw/Pitch/Roll, but I sort of skewed it a tad to fit properly.
Lets create a function called RotateVector for sake of ease and fill it with pseudo-code.
Code: Select all
Function RotateVector( CurrentVertex.VECTOR, CurrentAxis.VECTOR, Yaw, Pitch, Roll )
Yaw = Yaw / 57.2957795
Pitch = Pitch / 57.2957795
Roll = Roll / 57.2957795
CurrentVertex = CurrentVertex - CurrentAxis
If Yaw <> 0
X.f = Cos(Yaw) * CurrentVertex\X - Sin(Yaw) * CurrentVertex\Z
CurrentVertex\Z = Sin(Yaw) * CurrentVertex\X + Cos(Yaw) * CurrentVertex\Z
CurrentVertex\X = X
EndIf
If Pitch <> 0
Y.f = Cos(Pitch) * CurrentVertex\Y - Sin(Pitch) * CurrentVertex\Z
CurrentVertex\Z = Sin(Pitch) * CurrentVertex\Y + Cos(Pitch) * CurrentVertex\Z
CurrentVertex\Y = Y
EndIf
If Roll <> 0
X.f = Cos(Roll) * CurrentVertex\X - Sin(Roll) * CurrentVertex\Y
CurrentVertex\Y = Sin(Roll) * CurrentVertex\X + Cos(Roll) * CurrentVertex\Y
CurrentVertex\X = X
EndIf
CurrentVertex = CurrentVertex + CurrentAxis
Return CurrentVertex
EndFunction
This is pseudo-code, make sure to note that
CurrentVertex originaly holds the position of the vertex you want to rotate around the point known as CurrentAxis by the Yaw/Pitch/Roll values. You would call this function for each vertex you want to rotate around your axis. I will post some more in depth stuff if you need once I get home, currently sitting in class ignoring my professor

.