Page 1 of 1

Drawing an image on a face of a cube

PostPosted: May 7, 2008 @ 12:41am
by brian

PostPosted: May 8, 2008 @ 8:42am
by edge

PostPosted: May 8, 2008 @ 5:54pm
by brian
Thanks for your reply. I am able to replicate the result you posted, and now want to draw onto the actual face of the cube (I'm modifying the View3D sample). Here's what I have:

EVERTEX3D v[NumVertices];
POINT p[NumVertices];

display->Perspective3D(display->GetWidth(), display->GetHeight());
for(int i = 0; i < NumVertices; i++)
{
cube.GetVertex(i,&v[i]);
display->CalculatePerspective(&v[i].position,&p[i]);
}

// lower-left of front-triangle is 0, 2, 1
display->buffer.TexturePoly(p[0].x, p[0].y, // x1, y1
0, h, // u1, v1
p[2].x, p[2].y, // x2, y2,
0, 0, // u2, v2
p[1].x, p[1].y, // x3, y3
w, h, // u3, v3
&background);

// upper-right of front-triangle is 1, 2, 3
display->buffer.TexturePoly(p[1].x, p[1].y, // x1, y1
w, h, // u1, v1
p[2].x, p[2].y, // x2, y2,
0, 0, // u2, v2
p[3].x, p[3].y, // x3, y3
w, 0, // u3, v3
&background);

The problem is that the CalculatePerspective returns points with values such as (-4,4) for one of the points of the cube, rather than something meaningful like the lower left corener of the actual 320x240 display.

Furthermore, the cube's vertex position is the *original* position, not the rotated one. (I already called cube.rotate per the View3D sample).

Aren't there examples/samples that demonstrate more of the 3D stuff?

Thanks,
Brian

PostPosted: May 9, 2008 @ 12:57pm
by edge

PostPosted: May 9, 2008 @ 4:50pm
by brian

PostPosted: May 12, 2008 @ 5:41pm
by edge
Hi Brian,

To use a different texture for each face, you need to split the surface into 6 seperate surfaces. Another technique is to have one big texture with 6 different images on it, then map each image to its matching face of the cube.

If you still want to use CalculatePerspective, you need to specify larger coordinates (in the range of -4096 to 4096), otherwise you get very small numbers.