This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Drawing an image on a face of a cube


Drawing an image on a face of a cube

Postby brian » May 7, 2008 @ 12:41am

brian
pm Member
 
Posts: 6
Joined: May 2, 2008 @ 10:12pm


Postby edge » May 8, 2008 @ 8:42am

EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby brian » May 8, 2008 @ 5:54pm

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
brian
pm Member
 
Posts: 6
Joined: May 2, 2008 @ 10:12pm


Postby edge » May 9, 2008 @ 12:57pm

EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Postby brian » May 9, 2008 @ 4:50pm

brian
pm Member
 
Posts: 6
Joined: May 2, 2008 @ 10:12pm


Postby edge » May 12, 2008 @ 5:41pm

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.
EDGELIB: Cross-platform mobile development at your fingertips
http://www.edgelib.com
User avatar
edge
pm Member
 
Posts: 1180
Joined: Aug 22, 2005 @ 3:42pm
Location: The Netherlands


Return to EDGELIB


Sort


Forum Description

Powerful and affordable C++ middleware solution covering true multi-platform 2D, 3D and network features for Apple iPhone, Windows Mobile, Symbian S60, UIQ, Linux and Windows desktop.

Moderator:

edge

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron