Ok, I don't know how to explain the problem, look at the project I attached. The rotation matrix seems to scew up when turning around X or Y while Z rotation works fine... Please help!
Printable View
Ok, I don't know how to explain the problem, look at the project I attached. The rotation matrix seems to scew up when turning around X or Y while Z rotation works fine... Please help!
It works fine for me fox...
I havent look at the project, but are you multiplying
matricies, and, if so, are you doing it in the right order?
That can screw things up pretty bad. Just as an example, say you have a wheel, but its lying on its side. you want it to rotate, so you want to rotate 90 along the Z,so it stands up, and then rotate around X so it spins. But, if you first apply the X Rotation, the wheel will be angled up slightly, and when you apply the Z, the wheel will appear to wobble. That MIGHT be your problem, Hope it helps.
Z.
Nope..
Press UP+RIGHT some time, you'll notice the stars becoming flat... they're not flat, the positions are randomized in a cube (when moving far away you see the cube...)
Code:Controls:
Q / E = Rotate Z
Left / Right = Rotate Y
Up / Down = Rotate X
+ / - = Move Z
D / A = Move X
W / S = Move Z (you can replace this, should be Y)
Hm, as I can remember I took all rotation matrices, multiplied them and got the final rotation matrix... looks like this;
Code:'The stars are fixed, I just move the camera object
Sub Draw(iUniverse As tUniverse, iColor As Long)
On Error Resume Next
Dim A As Long
Dim x2 As Single
Dim y2 As Single
Dim z2 As Single
Dim TempX As Long
Dim TempY As Long
With Camera
For A = 0 To iUniverse.StarCount
'Calculate coordinates
x2 = (iUniverse.Star(A).x * Cos(.rY) * Cos(.rZ) + .y * Sin(.rZ) + iUniverse.Star(A).z * -Sin(.rY))
y2 = (iUniverse.Star(A).x * -Sin(.rZ) + iUniverse.Star(A).y * Cos(.rX) * Cos(.rZ) + iUniverse.Star(A).z * Sin(.rX))
z2 = (iUniverse.Star(A).x * Sin(.rY) + iUniverse.Star(A).y * -Sin(.rX) + iUniverse.Star(A).z * Cos(.rX) * Cos(.rY))
If z2 > 0 Then
TempX = (.w / 2) + .FOV * (x2 / z2)
TempY = (.h / 2) + .FOV * (y2 / z2)
'Draw star
SetPixelV .FrontDC, TempX, TempY, iColor
End If
Next
End With
End Sub
I dont have a camera matrix, the camera is a simple type that has x, y, z and rx, ry, rz for the angle.
(project attached; see 1st post)
well thats not enough to allow the camera to rotate freely, why not use a matrix instead?
Well when I started the project I used matrices, but I saw that it makes no sense so instead I used just variables.
However, that's not the problem I think, the only thing I need to know is what's wrong with my rotation forumla?
I have no idea how you come up with it in the first place and what rx ry and rz stand for
the x- y- and z-angle of the camera of course ;)
hmm, this took me ages, i got miscalculations twice and ended up with weird rotations. I hope you're happy with the results now :) I also extracted the trigonometry parts outside the loop to speed up the process
Code:Sub Draw(iUniverse As tUniverse, iColor As Long)
On Error Resume Next
Dim A As Long
Dim x2 As Single
Dim y2 As Single
Dim z2 As Single
Dim TempX As Long
Dim TempY As Long
Dim t0!, t1!, t2!, t3!, t4!, t5!, t6!, t7!, t8!, t9!, t10!
With Camera
t0 = Sin(.rX)
t1 = Cos(.rX)
t2 = Sin(.rY)
t3 = Cos(.rY)
t4 = Sin(.rZ)
t5 = Cos(.rZ)
For A = 0 To iUniverse.StarCount
'Calculate coordinates
t6 = iUniverse.Star(A).y * t5
t7 = iUniverse.Star(A).x * t4
t8 = t5 * iUniverse.Star(A).x
t9 = t4 * iUniverse.Star(A).y
t10 = t3 * iUniverse.Star(A).z
x2 = .x - (t3 * (t8 - t9) + t2 * iUniverse.Star(A).z)
y2 = .y - (t0 * (t2 * t8 - t2 * t9 - t10) + t1 * (t7 + t6))
z2 = .z - (t1 * (-t2 * t8 + t2 * t9 + t10) + t0 * (t7 + t6))
If z2 > 0 Then
TempX = (.w / 2) + .FOV * (x2 / z2)
TempY = (.h / 2) + .FOV * (y2 / z2)
'Draw star
SetPixelV .FrontDC, TempX, TempY, iColor
End If
Next
End With
End Sub