Results 1 to 26 of 26

Thread: rotation, should i use matrices??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Unhappy rotation, should i use matrices??

    Hi. I'm currently working on a program to solve the Rubik's cube. I have drawn some slight semblance of the cube in D3D. My question is in the rotation of it. I know that I have two options: rotate the camera, or rotat the world matrices. I have no clue how to rotate the world matrices, as I've tried before and because the origin lies on a corner of the cube and not in the center of it, it doesnt rotate the cube correctly. I have attached my program, and the camera rotation subroutine is in the DX module in the RenderObjects procedure. I'm wondering if I should use matrices for the roatation, and if so how would i position the pivot point to (8,8,8)? I would have to rotat the matrices in Picture1_Mousemove, but thats not a problem. ANY help would be great. Thanx
    Attached Files Attached Files

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: rotation, should i use matrices??

    To rotate something about a point that isn;t the origin translate (move) the object first, in the opposite direction.

    E.g. move it by -8,-8,-8, then rotate.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    how do i move the object - its made up of 216 points. I really dont want to have to move them all. So is there a matrix I can move or something? I also have the points being dynamically created and that subroutine is a gigantic mess if i try to mess with it.

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    Yes you have to use a matrix to rotate vertices in DirectX. To rotate an object by its world coordinates, you do this:

    VB Code:
    1. Public Sub Rotate_Local_Coordinates(ByVal Angle_X As Single, ByVal Angle_Y As Single, ByVal Angle_Z As Single)
    2.  
    3.     D3DXMatrixRotationX Rotate_X_Matrix, (PI * Angle_X) / 180
    4.     D3DXMatrixMultiply World_Transformation_Matrix, World_Transformation_Matrix, Rotate_X_Matrix
    5.    
    6.     D3DXMatrixRotationY Rotate_Y_Matrix, (PI * Angle_Y) / 180
    7.     D3DXMatrixMultiply World_Transformation_Matrix, World_Transformation_Matrix, Rotate_Y_Matrix
    8.    
    9.     D3DXMatrixRotationZ Rotate_Z_Matrix, (PI * Angle_Z) / 180
    10.     D3DXMatrixMultiply World_Transformation_Matrix, World_Transformation_Matrix, Rotate_Z_Matrix
    11.    
    12.     Direct3D_Device.SetTransform D3DTS_WORLD, World_Transformation_Matrix
    13.    
    14. End Sub
    15.  
    16. Public Sub Translate_Local_Coordinates(ByVal Translate_X As Single, ByVal Translate_Y As Single, ByVal Translate_Z As Single)
    17.    
    18.     D3DXMatrixTranslation Translation_Matrix, Translate_X, Translate_Y, Translate_Z
    19.     D3DXMatrixMultiply World_Transformation_Matrix, World_Transformation_Matrix, Translation_Matrix
    20.     Direct3D_Device.SetTransform D3DTS_WORLD, World_Transformation_Matrix
    21.  
    22. End Sub

    Then in your game loop you rotate first, then translate for every object. Use these two again on the next object, otherwise it'll rotate every other object drawn, rather than rotate independently:

    VB Code:
    1. D3DXMatrixIdentity World_Transformation_Matrix
    2. Rotate_Local_Coordinates Object.Angle_X, Object.Angle_Y, Object.Angle_Z
    3. Translate_Local_Coordinates Object.X, Object.Y, Object.Z

    Now if you want an FPS style camera, you would do this:

    VB Code:
    1. 'Camera
    2.    
    3.     If DirectInput_Key_State(DIK_NUMPAD8) Then 'Camera Forward
    4.  
    5.         Camera_Position_X = Camera_Position_X + Fast_Sin(Camera_Angle_Y) * Camera_Speed
    6.         Camera_Position_Z = Camera_Position_Z - Fast_Cos(Camera_Angle_Y) * Camera_Speed
    7.  
    8.     End If
    9.        
    10.     If DirectInput_Key_State(DIK_NUMPAD5) Then 'Camera Backward
    11.    
    12.         Camera_Position_X = Camera_Position_X - Fast_Sin(Camera_Angle_Y) * Camera_Speed
    13.         Camera_Position_Z = Camera_Position_Z + Fast_Cos(Camera_Angle_Y) * Camera_Speed
    14.    
    15.     End If
    16.        
    17.     If DirectInput_Key_State(DIK_NUMPAD4) Then 'Camera Side Step Left
    18.  
    19.         Camera_Position_X = Camera_Position_X - Fast_Cos(Camera_Angle_Y) * Camera_Speed
    20.         Camera_Position_Z = Camera_Position_Z - Fast_Sin(Camera_Angle_Y) * Camera_Speed
    21.  
    22.     End If
    23.        
    24.     If DirectInput_Key_State(DIK_NUMPAD6) Then 'Camera Side Step Right
    25.  
    26.         Camera_Position_X = Camera_Position_X + Fast_Cos(Camera_Angle_Y) * Camera_Speed
    27.         Camera_Position_Z = Camera_Position_Z + Fast_Sin(Camera_Angle_Y) * Camera_Speed
    28.  
    29.     End If
    30.        
    31.     If DirectInput_Key_State(DIK_NUMPAD7) Then 'Look Left      
    32.  
    33.         Camera_Angle_Y = Camera_Angle_Y - 1    
    34.  
    35.     End If
    36.        
    37.     If DirectInput_Key_State(DIK_NUMPAD9) Then 'Look Right          
    38.  
    39.         Camera_Angle_Y = Camera_Angle_Y + 1
    40.  
    41.     End If
    42.        
    43.     If DirectInput_Key_State(DIK_PRIOR) Then 'Look Up  
    44.  
    45.         Camera_Angle_X = Camera_Angle_X - 1
    46.  
    47.     End If
    48.        
    49.     If DirectInput_Key_State(DIK_NEXT) Then 'Look Down  
    50.  
    51.         Camera_Angle_X = Camera_Angle_X + 1
    52.  
    53.     End If
    54.        
    55.     If DirectInput_Key_State(DIK_NUMPAD3) Then 'Go Up    
    56.  
    57.         Camera_Position_Y = Camera_Position_Y + Camera_Speed
    58.  
    59.     End If
    60.      
    61.     If DirectInput_Key_State(DIK_NUMPAD1) Then 'Come Down    
    62.  
    63.          Camera_Position_Y = Camera_Position_Y - Camera_Speed
    64.  
    65.     End If

  5. #5
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Maine, USA
    Posts
    277

    Re: rotation, should i use matrices??

    Here is a good place to look.
    I have not looked at your code, but I think you would need them in a matrix to be able to transform and rotate them.

    http://forums.microsoft.com/MSDN/Sho...27671&SiteID=1
    <deis> I turn on god mode when I program
    <deis> I just call it .NET


    If my post was helpful, please Rate it

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    My way was better

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    wow Jacob.....im a newb.. i have no idea what most of that code does..and i really like to understand what im doing with d3d as i want to make more programs in the future.....i dont know what an fps style camera is either...maybe if you took a look at my code?... its in vb6.. i would have a clue as to what your talking about..sorry to be a pain.. i hate being a newb at things..:-P

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    actually looking mroe at your code it seems u actually have an object.. to create my object i use the following

    m_D3DDevice.DrawPrimitive D3DPT_TRIANGLELIST, D3DFVF_VERTEX, _
    m_Vertex((i - 1) * 4 + 1), 3, D3DDP_DEFAULT

    becaues i have an array with all ov my vertices in it, therefore.. i know know how to name the object i want to move/rotate....

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    I have a couple sample progs in my site that I've made that should help you out

    www.angelfire.com/fl5/memorydll/index.html

    And an FPS (First Person Shooter) style camera allows you to move forward/backward, side step, and look up/down at any angle you are facing on the Y axis. Makes it move like you are in the real world.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    jacob

    i hate to be a pain, but im on dial up and that code will take forever to dl.. i just spent some time studying the code that u posted however...and perhaps if i provide a bit more detail as to how my program works you could explain to me exactly where to place that code


    a rubiks cube consists of 6 faces (as any cube would)...these faces have what i like to call 9 facelets (the small squares that make up a rubik's cube face).... to map out to coordinates and type them in for 9 facelets x 6 faces x 4 points per facelet...
    i did it on paper instead and noticed a pattern...therefore, I made a subroutine that takes only the coordinates for the first facelet, and the face that facelet is contained on, and appends to the vertex array...i need to call this sub 6 times (once for each face)

    the rear lower left point of the cube is on (0,0,0) and each face is 5 units wide, separated by a .5 unit gap...making the whole cube 16 units wide, and the center at (8,8,8)...

    in my render loop i clear the viewport, change the angle of the matrix, update the angle, and graph each facelet. in order to display each of the facelets properly, i need to look and the vertex array and use a loop to make the DrawPrimitive method only look at 3 vertices (a square is two triangles)... then graph the other triangle for that square....this loop lasts 216 iterations. after which i draw the result..

    my guess is that when i am updating my matrix, should i use your code to rotate the matrix, the move it by (-8,-8,-8)?..... i think i can handle the trig to figure out how to rotate x and z dependsing on the angle of rotation around y..im just curious if thats what you mean with the code you wrote above

  11. #11
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    Well since the rubix cube consists of 9 cubes, you should treat each of them as objects, which means you are gonna need 9 of these in your game loop, each pasted before every cube drawn, only this time, translate before rotating to allow the outer cubes to rotate far from the origin:

    VB Code:
    1. D3DXMatrixIdentity World_Transformation_Matrix
    2. Translate_Local_Coordinates Object.X, Object.Y, Object.Z
    3. Rotate_Local_Coordinates Object.Angle_X, Object.Angle_Y, Object.Angle_Z

    And what I've done for the games was make a sub called Control with the camera stuff in there, and had that FPS camera code located above within it, then in the game loop, you simply call the sub Control before anythings drawn. I also forgot to copy/paste one more function you are gonna need:

    VB Code:
    1. Public Function DirectInput_Key_State(Key_Code As Long) As Long
    2.  
    3.     Keyboard_Device.GetDeviceStateKeyboard Keyboard_State
    4.    
    5.     DirectInput_Key_State = Keyboard_State.Key(Key_Code)
    6.  
    7. End Function

  12. #12
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: rotation, should i use matrices??

    27 cubes I think you'll find, unless its a rubik hypercube and nobody's been able to manufacturer one of those in this universe.
    I don't live here any more.

  13. #13
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    No wossy, it's 9 cubes. Have you ever played it before?

  14. #14
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: rotation, should i use matrices??

    http://www.rubiks.com/

    Sure does look like 3 * 3 * 3 (27) cubes to me!!
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  15. #15
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    Whoops. My bad. It was early in the morning. My brain must have been off in the wrong direction.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    i just drew the faces that are visible.. so all that wouled be drawn would be the colored faces..and I attempted to draw the faces behind it that would make up the "cubes"... but i couldnt get those faces to appear behind the others...so i just left it as a shell. i dont know how to create objects... i just use the drawprimitive command to graph the points of that shell and leave it at that....im not sure if there is something im missing to create objects - this is actually my first d3d attempt.
    GAH ! CONFUSION

  17. #17
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    Upload the project you have and i'll fix it for ya.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    look up^^theres a remark in the game loop... it refers to a textbox.. i used to that troubleshoot my vertex creating sub... just ignore ... any changes you make could you remark out what i have so that i can see what your doing?...and if its not too much trouble.. give some kind of explaination..thanx :-D:-D:-D

  19. #19
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    I see that you are using DirectX7 to do Direct3D. You should have been using DirectX8 cause they made it way easier, so I'm gonna tweak your code a bit to get it going on that.

  20. #20
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    I'm not through with your project just yet, but your basic game engine setup should be like this:
    Attached Files Attached Files

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    You should have been using DirectX8 cause they made it way easier
    that was....easier.. i looked at the engine u set up and im extremely confused..lol... it took me 3 different tutorials where all of the sites used d3d7. i have no idea about d3d8..but it looks like you have about 7 modules...and.. i have...3... i think thats where i get confused...perhaps also because i was using the extreme barebones of d3d to get the result, and not accounting for anything else. I see that you are setting every parameter, and accounting for everything in d3d8. Perhaps you could refer me to a d3d8 for dummies website?..

  22. #22
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    I made some progress so far but still have a while to go. I broken it down for ya by separating the DX stuff from Direct3D, DirectInput, the Game Engine, etc, in separate modules, rather than cramming most of it all in one module (which you did ). MS made D3D easier to work with in DirectX 8, and even easier in 9 with more features, only it's managed. Here's a nice tutorial on DirectX8

    http://directx4vb.vbgamer.com/Direct...T_DX8Start.asp

    No you do not need all that code to initialize it, but what I did was called enumeration. It obtained all the resolutions from your video card, and if the resolution you selected matched one of them, it switched to it, otherwise it uses the same resolution you have. And I also have a hybrid initialization, to where you have a choice of having windowed or fullscreen mode. Here's an update on it so far that I uploaded. I'm gonna be in Cocoa beach this weekend so if you have any more questions, I'll be back to answer them, and even finish up seting up that rubiks cube.
    Attached Files Attached Files

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    ok ill study that and see if i cant come up with an understanding...also.. i dont know if you noticed how i had the reference to the colors for the cube...(a 2d array of fce, facelet).... but if possible id like you to keep it that way... because i need that array to be able to make turns and then i can develop the AI and such and instruction sets on my own.. for the solving part

  24. #24
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: rotation, should i use matrices??

    Don't worry about that. I'll show ya how the colors will be done in a couple days. I got work tommorow, and leaving for the weekend afterwards, and it's bedtime, so you are just gonna have to study the code in the meantime. I may texturemap the cubes instead to give it that realistic non primitive look.

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    110

    Re: rotation, should i use matrices??

    i think you have just given me one of the biggest headaches of my lfie...remember this is the first dx project ive done...EVER...this is the first attempt at anything ive ever done...lol

  26. #26
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: rotation, should i use matrices??

    Quote Originally Posted by SLH
    http://www.rubiks.com/

    Sure does look like 3 * 3 * 3 (27) cubes to me!!

    Just a note - it's really 26. There's no cube in the center - take one apart and you will see it's a spiky thing that lets the cublettes all move. Just thought I'd mention...
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

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