Results 1 to 11 of 11

Thread: Problems w/ 3D-rotatation (kedaman?)

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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!

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It works fine for me fox...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Zaei
    Guest
    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.

  4. #4

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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)

  5. #5

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  6. #6

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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)

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well thats not enough to allow the camera to rotate freely, why not use a matrix instead?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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?

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I have no idea how you come up with it in the first place and what rx ry and rz stand for
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    the x- y- and z-angle of the camera of course

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width