I'm unable to find the documentation that helps me on this. I want to draw a bitmap on a face of a cube. I'm going off of the View3D sample. What's the technique for doing this?
I suspect that'll be using BltFast onto the visible region of a face within the OnNextFrame handler. If this is the case, some sample code that shows how I use the vertex positions to specify the region to blt to would be very helpful.
Thanks,
Brian
Hi Brian,
There are two ways to do this. Using a 3D model or by drawing the polygon directly yourself. From your message I understand you like to have control on where it exactly draws (in pixels). For that I recommend E2DSurface::TexturePolygon.
Here is a small sample drawing a square:
- Code:
display->buffer.TexturePoly(20, 20, 0, 0,
80, 20, image.GetWidth(), 0,
20, 80, 0, image.GetHeight(),
ℑ);
display->buffer.TexturePoly(80, 20, image.GetWidth(), 0,
20, 80, 0, image.GetHeight(),
80, 80, image.GetWidth(), image.GetHeight(),
ℑ);
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
Hi Brian,
I think it's better to use the 3D model structure. Take a look at how the cube is generated. It uses texture coordinates to determine how the picture is mapped on the cube faces.
When rendering the model, bind the texture (image) you like to use to the display object, and finally call Render(). Texture coordinates go from 0 to 65536, they are independent of the size of your texture image.
I recommend reading the 3D tutorial here:
http://www.edgelib.com/index.php?node=1097
The 3D tutorial does not make it clear what I need to do. I really need answers to the questions I'm asking.
I am using a 3D Model: the cube that's in the View3D sample, and I'm trying to draw an image onto *one* (not all) of its faces. You gave me the right API, TexturePoly, but I'm having difficulty in determining the coordinates to pass into TexturePoly, based on the current positions of my vertices.
Again: CalculatePerspective is not giving me the coordinates that I can use with TexturePoly. Can you help me solve this with the appropriate modifications to View3D?
Thanks.
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.