[futurebasic] Re: [FB] 3D Object Rendering with Materials

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2001 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Tue, 30 Oct 2001 22:39:37 -0500
>Hi All,
>  I have a program ( same as the one in GWorld Blues) that draws in 3D. I
>have two questions at the moment.
>
>  1. What formula do I use for translating a 3D point to a 2D point? I am
>currently using:
>'3D to 2D Transformation
>xOut = (XYZX# + XYZY#*cos(pi#/6)) : yOut = -(XYZZ# +
>XYZY#*sin(pi#/6))'Screen Coords

For a flat projection, just discard the Z parameter and use the X,Y.

If using perspective you will need to mix in a little Z.

One method of a simple project is X = X+(.5*z)  Y = Y+(.5*Z)

>  2. I have some world maps that I would like to render onto a sphere. The
>code below is what I currently use to plot all 3D points. What do I need
>to do to make a version that will draw the globe. I am using GWorlds and
>all the coordinates are scalled down from it's real size to screen size
>before it is passed into this function. The sphere is a real size Earth.
>All coordinates are in the scale of 1 pixel is 1Km.
>
>local fn PlotXYZ(XYZX#,XYZY#,XYZZ#,xRot#,yRot#,zRot#)
>'X Rotation
>Y# = XYZY# : Z# = XYZZ#
>XYZY# = Y# * cos(xRot#) - Z# * sin(xRot#)
>XYZZ# = Y# * sin(xRot#) + Z# * cos(xRot#)
>
>'Y Rotation
>X# = XYZX# : Z# = XYZZ#
>XYZX# = X# * cos(yRot#) - Z# * sin(yRot#)
>XYZZ# = X# * sin(yRot#) + Z# * cos(yRot#)
>
>'Z Rotation
>X# = XYZX# : Y# = XYZY#
>XYZX# = X# * cos(zRot#) - Y# * sin(zRot#)
>XYZY# = X# * sin(zRot#) + Y# * cos(zRot#)
>
>'3D to 2D Transformation
>xOut = (XYZX# + XYZY#*cos(pi#/6)) : yOut = -(XYZZ# +
>XYZY#*sin(pi#/6))'Screen Coords
>pen _Map3Bound/275,_Map3Bound/275
>plot xOut,yOut
>end fn
>
>  Thanks in advance,
>
>  Ashley ~)~


You will need to UV map the sphere model with Texture coordinates, and use
these to guide drawing in the color from a texture map. OpenGL  or
QuickDraw 3D can aid with this. Lot of setup to do. Look at the OpenGL Cube
demo on the CD.


For any X,Y,Z vertex on the Sphere, you would need to have a UV coordinate
to match.

UV coordinates are just normalized coordinates, that is they go from 0 to 1.0

If you have a maximum X of 400, and a maximum Y of 400, then the UV
equivalent of X = 200, Y = 200  will be .5,.5

To get that just use U = X/400, V = Y/400 or whatever the maximum of either
valus is.

Then say you have a Spherical point that is 100,100 ... 100/ 400 = .25

If the Y is the same, thus the V, you will find whatever pixel lies on your
texture map at .25,.25

If your Texture map is 200 X 400, you will want the pixel at   50,100

This is derived from X = U*200, Y = V*400


Complicated. Then there is a need for anti-aliasing when scaling the model,
etc.

Best to use OpenGL for this if you don't know the fundamentals. It will
automate a lot of it, and the headers are already done thankfully. Tricks
of the Game Programming Guru's also has info on this, and with Quickdraw
3D, which is not longer supported. Quesa 3D is the pickup where that left
off.



Robert Covington