PDA

View Full Version : To get colour from a 3Dcube



GMV
05-16-2002, 05:50 AM
Hi, all!
Please, help me!
I have created 3D cube, using OpenGl. I can rotate and scale it.
When i click on any side of the cube, i need to get a color of this side. How can i make it?
Thx!!!

nexusone
05-16-2002, 06:47 AM
Since you have drawn the cube, you know what colors you have put on each side.
Just look at how much you have rotated the cube and figure out what side is facing the camera when the mouse button is pressed.

Example:
rotation_x = 0; rotation_y = 0; Front of cube facing user.
rotation_x = 90; rotation_y = 0; Left side of cube facing user.
rotation_x = 0; rotation_y = 90; Top of cube facing user.

You also may want to look at object picking, see nehe.gamedev.net for an example of that.


Originally posted by GMV:
Hi, all!
Please, help me!
I have created 3D cube, using OpenGl. I can rotate and scale it.
When i click on any side of the cube, i need to get a color of this side. How can i make it?
Thx!!!



[This message has been edited by nexusone (edited 05-16-2002).]

GMV
05-16-2002, 07:08 AM
Thx.
What i must to do, to get colour of a point when i click mouse on the cube?

Gavin
05-16-2002, 07:19 AM
wouldn't it be better to use selection?

GMV
05-16-2002, 07:22 AM
How i can make it?

coredump
05-16-2002, 07:51 AM
look up glReadPixels.

b

nexusone
05-16-2002, 07:54 AM
I think that you have not been clear on what you want to do?

Are you wanting to get the color of a pixel on the screen?
Or just the color of the side of the cube that is clicked on?
If you want to get the color of the side clicked on, then my last message explains that.


Originally posted by GMV:
Thx.
What i must to do, to get colour of a point when i click mouse on the cube?

Penance
05-17-2002, 08:00 AM
He's not assuming every side is a solid color. He wants to know how to click on any point on the cube and get the color there.

Which I suppose would be glReadPixels but he'd probably also need to use a bounding box to make sure he's clicking on the cube and not the background or another object.

Omaha
05-17-2002, 04:16 PM
Ok, then check your mouse coordinates against a simple bounding box, provided the click is in the box, proceed to read the frame buffer within the bounding box into an array, then just use the mouse position to extract (I imagine) R G and B values.

Nothin' but net.

Certainly not the only way to do it but one of the more direct ways.