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
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
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.
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:
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
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.
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
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:
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:
Public Function DirectInput_Key_State(Key_Code As Long) As Long
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
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
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
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.
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?..
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
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.
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
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.
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
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