Image projection!
Hi,
I've written a rotating cube for a navigation. You can see the applet on http://you.are.at/Reinbacher .
Now i want to draw to every side of the cube an image.
My applet should look like the cube applet on (without the light effects) :
http://www.fouda.de/html/applets/effects.htm
I don't know how i can do it.
Please give ma a few good instructions or some helpful links.
Thank you a very much
Thomas Reinbacher
Okies, I would start by determining the image's rotation. This would be done by assigning each image an orientation, including one edge of its face to be the "top." Determine the angle of rotation necessary from the image's current position to reach the angle at which that edge is turned.
Then, create a grid space containing the image data where the center of the image is in the center of the graph. Convert each pixel to a polar coordinate pair and adjust the theta coordinate appropriately. Convert them back to cartesian coordinates, painting in a gridspace.
Then fill in the blank pixels that are contained within the image with whichever correctional method you prefer (nearest neighbor, etc.) and fit your new grid (using transparent pixels for those pixels that do not have values) into the height and width of the target cube face as it appears on the screen.
That's what I would do. I'm not an expert on 3D, so that might be a bunch of ****. :)
tvynr at 2007-7-5 21:58:55 >

There are two basic approaches: ray-tracing and polygon scan conversion.
Ray-tracing
For each (x,y) in your paintable area, fire a ray towards the cube. Use the maths you're probably already using to work out the intersection on each face. Choose the intersection nearest the screen, and find the corresponding value in your texture.
PSC
I'd like to link to the notes for my graphics course last year, but they're not on the web. Roughly speaking, you draw each face as a series of (for the sake of argument, horizontal) lines. So for each y-value, you calculate the minimum and maximum extent in the x-direction. You then work out for each pixel along this what the corresponding value in your texture is. For full details of this, you want to take probably Bresenham's line drawing algorithm, to work out the extents in the x-direction efficiently, and interpolate in interesting ways. A google for Bresenham "Polygon Scan Conversion" interpolate shows up what look like three university lecture note sets which might be useful.
Finding the colour of (x,y) in the texture
In general, x and y are non-integral doubles. There's an obvious time-quality tradeoff. For really quick, poor quality, use nearest neighbour, breaking a tie arbitrarily. For moderately better quality, use bi-linear interpolation: find the integer values that bracket x (call them x_ and x^) and y (y_ and y^). Call the texture map T(u,v). Interpolate in the y-direction and say that T(x_, y) is roughly the weighted average of T(x_, y_) and T(x_, y^). More precisely, T(x_, y) ~ (y-y_)T(x_, y_) + (y^-y)T(x_, y^). Do likewise for T(x^, y) ~ (y-y_)T(x^, y_) + (y^-y)T(x^, y^). Then do the same thing in the x-direction: T(x, y) ~ (x-x_)T(x_, y) + (x^-x)T(x^, y). Bi-quadratic is better still.
pjt33 at 2007-7-5 21:58:55 >

Forgot to mention z-buffer for the PSC. You want a data structure which stores for each point the colour value and the depth (distance from the viewpoint). Then when scanning each polygon, you only update a pixel if the depth is less than the existing depth. Clearly, in the case of a cube, hidden face removal will save you this effort.
pjt33 at 2007-7-5 21:58:55 >
