Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bzroom

Rubiks cube hell....

This topic is 5423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a rubiks cube program for school. I know theres a no homework policy but i not asking for the answer. I have an array of 27 pointers to my sCube struct, representing each cube on the cube. When I rotate a slice of the cube i manualy (because i couldn''t think of an easy equation) coded how the pointers would change ed:
	memcpy(&temp[0], &cubes[0], sizeof(sCube *)*27);

	if (set==0) //top - red

	{

		temp[0] = cubes[2];
		temp[1] = cubes[5];
		temp[2] = cubes[8];
		temp[5] = cubes[7];
		temp[8] = cubes[6];
		temp[7] = cubes[3];
		temp[6] = cubes[0];
		temp[3] = cubes[1];

		for(i = 0; i < 9; i ++)
		{
			temp[i]->rz++;
		}
	}
........
        memcpy(&cubes[0], &temp[0], sizeof(sCube *)*27);
The part im having trouble with is finding the cubes new orientation. In my ex i have it adding onto a rx, ry, or rz, this is the latest way i am trying. When i render each cube, i multiply the matrix by all of its rotations glRotatef(90*cube->rx,1,0,0); .... This dosnt work, they dont multiply in the right order and i''ve tried every order, its differnt depending on how the cube got there. The first way i tried envolved saving the cubes original x, y, z in the sCube struct. When i went to render that cube i would figure out the difference between say the X i was rendering at (either a -1,0,1) and the cubes original X and rotate. Did this for each of the 3 axis. Worked the worst. The 2nd way I tried i stored a matrix in each sCube. When i created the cubes they were all identity. Instead of the above line saying temp->rx++, I had: glLoadMatrixf(temp[i]->matrix); glRotatef(90,0,0,1); glGetFloatv(temp[i]->matrix); Right before i rendered the cube i would multiply the stack by the saved matrix. This worked perfectly as long as the cube was only rotated once, it would work on any slice. When i tried multiple rotations once again i ran into the wrong multiplying order. So the 3rd way i tried is almost identical to the 2nd. In the above for loop i had this code: glLoadIdentity(); glRotate(90,0,0,1); glMultMatrixf(temp[i]->matrix); glGetFloatv(temp[i]->matrix); Reversing the matrix order. This worked equaly as well since at first the multiplied matrix was identity so only the first rotate was effective. Multiplying by a second rotate screwed things up. Oh boy. haha This can''t be that hard, any suggestions? Sorry about the typing, mostly the i''s.

Share this post


Link to post
Share on other sites
Advertisement
http://honayboyz.tripod.com/rubixcube.zip




Requires glut, glaux, all the bullshit.

This uses method 2.

Sorry about the goofy controls, all the arrows rotate the same way, mouse rotates the whole cube, home (why?) changes which slice u are working on.



[edited by - honayboyz on January 14, 2004 7:36:22 PM]

Share this post


Link to post
Share on other sites
"This file is hosted by Tripod, a Lycos®Network Site, and is not available for download. Please check out Tripod''s Help system for more information about Remote Loading and our Remote Loading policy. " get a nice host like sourceforge or even geocities.

i dont get why angelfire who is also lycos hosting alows downloads.

[Mercury Software] [Google!]

Share this post


Link to post
Share on other sites
If i had to start over again id probably do a texture and change it when the cubes change, would sure make solving it easier. Thats another feature i eventualy have to add. Alright no more comments from me.

Share this post


Link to post
Share on other sites
When I wrote my dodecahellspawn project (like a Rubik''s cube except a dodecahedron, screenshot here if you''re interested), I handled rotations somewhat differently. Basically, I rotated the relevent sections one turn, then reset things back to the original state. Then, I swapped the colors on the relevant sections.

The link for your code isn''t working for me, so I really can''t give more advice than that.

Share this post


Link to post
Share on other sites
Wow your game would probably make me kill myself. The link works, you just have to copy and paste it in, i''ll remove the hyperlinkness so people dont try to click it.

Share this post


Link to post
Share on other sites
Do you have to animate the rotation?

If not, I would suggest:
- model the pieces of faces, not cubes.
- Switch them around as needed, just colouring each side of the cube appropriately (drawing a 3x3 grid of coloured squares on each face).

Share this post


Link to post
Share on other sites
quote:
Original post by honayboyz
I''m making a rubiks cube program for school. I know theres a no homework policy but i not asking for the answer.


Its okay. You followed my rules, . I appreciate that you mention you''re not asking for a solution, only guidance! Anyway, rubik''s cube is a game also!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
http://www.geocities.com/honayboyz/fisherprice.zip


Ok this is what I have so far. I created a look up table to move the colors around. Its pritty hack I wish I would have done it more mathematicaly so eventualy the user could select the size of the cube they want to play on. But its almost finished as it is and my teacher is impressed. Sure beats the hello world and cd store database programs hes teaching the other students.

Controls:
R - reset
S - scramble (10 moves)
P - pause (for future solve timer)
Space - selects next slice
Arrows - rotate selected slice

edit: uhh same file serving bs. For me, it works if i paste the link into the browser and hit enter. But you guys say this dosnt work.

I made a page with a link on it. MAYBE if you go to the page and try to download it, it will work.

http://www.geocities.com/honayboyz/

[edited by - honayboyz on January 15, 2004 9:24:47 PM]

[edited by - honayboyz on January 15, 2004 9:26:55 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!