Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / coloring a cube

Author
Message
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 20th Apr 2007 09:13
I've tried finding this but I can't seem to find it mentioned anywhere. Is there a way to color a cube so each of the six sides have a different color.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Apr 2007 19:13 Edited at: 20th Apr 2007 20:47
DB primitives can only be coloured/textured as a whole. As such, you can't colour each side of a cube with a different colour.

Even when you load a texture, it applies the same texture on each of the six sides.

The easiest solution is to create your cube in a modelling program, colour the six sides as required, then save it out as a .X file to load into DB - where you would see the cube coloured correctly.

[Edit] Since posting this, I've now created a function to do this, (see next post), so the modelling option is no longer the easiest option!

TDK_Man

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Apr 2007 20:32
OK, I've just done an example to demonstrate doing it the hard way.

I've made it into a function, so you can copy it into your own program.

When you call it, please note that the first parameter is the object number and is an integer, while the second is the size - which must be a float.

Once the object is created, the cube is still referred to with the specified object number, (for scaling etc), but unlike a normal DB primitive cube it now has 6 limbs (sides) which are used when colouring or texturing.

Note: This code was written in DB Classic, but I can't think of any reason why it shouldn't work exactly the same in DBPro.



TDK_Man

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 20th Apr 2007 21:16
your first suggestion worked fine, i made a cube with six different colors and loaded it into my program
the harder was is well harder and it would kind of ruin my doe a bit as i need the cube to rotate at certain times
and since we're on the topic i might as well ask
here is my code:

i have a green sphere which moves on its own a soon as a direction button is pressed and its position is changed when it gets to the end of the cube. the cube is supposed to rotate at the same time to give the effect that the sphere has gone on the next side of the cube, but with this code the cube only rotates twice at certain times. ive included the cube model so you may test it out

Attachments

Login to view attachments
Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 20th Apr 2007 21:28
i attached a picture to sort of explain more of what i mean
the green sphere is going towards the red surface of the cube
i want the cube to rotate so the sphere is now on the red face moving along it, and kind of repeat it for each face
sorry if I'm way exceeding just asking for a little help but i'm really at a lost with this

Attachments

Login to view attachments
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Apr 2007 15:23
Quote: "it would kind of ruin my doe a bit as i need the cube to rotate at certain times"


Not sure what you mean. The second method creates a modified cube yes - but it's still a DB primitive cube and can be controlled with all the DB object commands. So, you can turn the rotation on and off as and when you need to.

You can also change the colours without having to load it back into the modelling program.

Quote: "i want the cube to rotate"


The X/Y/Z centre of the cube's top surface is known and the top, bottom, left and right edge X and Z positions are known. So, once the sphere reaches any of these points you can rotate the cube in the direction denoted by the sphere's position.

The problem might be what happens to the sphere when the cube is rotating.

But do you need to see it rotate?

If not, it might be a lot easier to re-colour the cube sides as though the cube had rotated and reposition the sphere at the point it would have entered the new side.

This would be easy if you created the cube with my function, but, re-colouring a model would require loading it back into the modelling program.

TDK_Man

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 22nd Apr 2007 04:56
did you happen to take a look at my code
what i am looking for is when the cube goes past a certain distance which is either past 160 or under -160 either direction (x or Z) then the sphere gets repositioned at the opposite edge (so if it was at 160 then it would go to -160) and the cube rotates from one face to the next at the same time.

not sure u understand what i'm trying to say

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Apr 2007 22:21
Yes - I'm sure I understand.

It's like the sphere is 'walking' around the cube only when it gets to the edge (and would be walking down one of the vertical sides), the cube rotates so the surface being walked on is always on the top. Right?

I'll see if I can knock an example snippet together for you...

TDK_Man

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Apr 2007 23:44 Edited at: 23rd Apr 2007 03:08
OK, here's the snippet.

As usual, it's written in DB Classic - I'm going to install DBPro now to test it out - I believe the MakeLimbCube() function needs a little tweaking fir DBPro.

Even so, it should work enough as it is to see if what I think you are trying to do is what you are trying to do...

DB Classic Version:



[Edit] DB Pro Version:



Note: At some cube angles, rotation is incorrect but I didn't have time to look into it in any great detail. It might be better to use Pitch and Roll instead of the Rotate commands, but I'll leave that for you.

TDK_Man

Login to post a reply

Server time is: 2024-09-25 21:22:58
Your offset time is: 2024-09-25 21:22:58