3 d axis

Alan deLespinasse aldel at alum.mit.edu
Sun Oct 22 05:11:41 UTC 2000


I played with the 3D stuff a while back (with some help from this
list) and can at least begin to answer your questions.

To begin with, there's currently no support for drawing lines,
although you should be able to get the same effect by drawing very
narrow rectangles.  There's also no support for transparency.  Or at
least, there wasn't last time I checked; I vaguely recall reading
about a change set that "fixed alpha blending" or something like that,
so maybe you can do transparency now.

Beyond that, it's not too hard, once you figure out the calling idioms
for the rendering engine.  Basically, you make a B3DRenderEngine
object, and then you send it messages to render things.  Here's some
test code I came up with when I was figuring it all out.  It just
renders a single square directly on the Squeak desktop (the Display),
using a texture grabbed from the screen.


rend _ B3DRenderEngine defaultForPlatformOn: Display.  "Make a renderer"
rend viewport: (Rectangle origin: 10 at 10 extent: 200 at 200). "Where to draw"
rend clearViewport: Color black.           "Clear the background"
cam _ B3DCamera new.                       "Make a camera"
cam initialize.                            "Initialize the camera"
cam position: 0 at 0@2.                       "Set the location of the camera"
                          "The camera looks towards the origin by default."
rend clearDepthBuffer.                     "Start hidden surface algorithm"
rend loadIdentity.                         "Reset world transformation"
cam renderOn: rend.                        "Set transformation with camera"
tex _ Form fromUser.                       "Grab a texture (user interaction)"
rend texture: tex.                         "Use the texture for drawing"
rend trackEmissionColor: true.             "(Not sure what this does)"
rend normal: 0 at 0@1.                        "Set the normal of the polygon"
rend color: Color white.                   "Full brightness, no extra color"
rend drawPolygonAfter: [                   "Draw a polygon..."
	rend                               
		texCoords: -1 at -1;          "These are the texture coordinates"
		vertex: -1 at -1@0;           "These are the world coordinates"
		texCoords:1 at -1;
		vertex: 1 at -1@0;
		texCoords: 1 at 1;
		vertex: 1 at 1@0;
		texCoords: -1 at 1;
		vertex: -1 at 1@0.
	].
rend finish.                               "Send it all to the display"


So you can probably steal the first part of the code above to set up
the world, and then put in drawPolygonAfter blocks for each primitive
you want to draw.  I think you can leave out all of the texture and
texCoords stuff, and just let it draw in the solid colors you specify.
I hope this helps.

I've been seriously thinking about volunteering to help develop the 3D
engine-- adding the missing features like line drawing, transparency,
back face culling, etc., and maybe working on hardware acceleration
support.  The main thing holding me back (aside from lack of time, of
course) is that I still don't understand the existing code well
enough, but that could change.  How about it, Andreas?  Want some help
from a relative newbie?

Alan deLespinasse


>From: "rhian.lewis" <rhian.lewis at mcr1.poptel.org.uk>
>
>r(theta) = R cos theta i + R sin theta j + C theta  is a general helix
>curve passing through three dimensional space.
>
>Rather than trying to explain the problems I am having, and spending weeks
>trying to decipher this B3D code I thought I would ask for help . I have
>looked at B3DMorph, and although I understand in principal the structure of
>the code, I am still finding it dificult to interact with the B3D renderer.
>
>Has anyone had experience representing such curves using Squeak, or maybe
>have some worked examples of representations of other 3D objects, eg
>spheres, cones etc.  How do I actually get the real points into the
>rederer?  and how do you go about getting a representation of a 3D axis in
>the middle of the screen.  I would kind of like a transparent cube in the
>center of the sceen in which to place objects.  As you can see I am lost.
>Help!!!!!!
>
>My helix is  r (theta) = 2 cos theta i + 2 sin theta j + 0.3 theta k.
>
>
>





More information about the Squeak-dev mailing list