Nov 28 2010

Hello Wire

Unless you really want me to take pictures of my (paper) notebook on which I worked out the trig for this, there’s not too much in this update.

.swf after the jump. Pretend it’s lime green and you know which game I’m patterning after. :)

W- move forward
S – move backward
A – rotate camera left
D – rotate camera right

J- rotate box left
K- rotate box right

The model is defined as an array of verticies (x,y,z) and edges. (The edges are structurally points… an edge defined as (1,2) connects verticies 1 and 2…). The verticies are defined in 3d coordinates relative to their center of rotation. Each frame, the renderer rotates the verticies in pitch, yaw, and roll (although right now only yaw is implemented) and then translates them to Global coordinates. From the Global coordinates, the points are projected onto a 2d plane located 1 nonunit* from a camera point. The projection is then magnified (scaled) to get screen coordinates for each vertex. In the actual drawing phase, the renderer just runs down the list of edges using moveTo() and lineTo(). It looks complicated, but isn’t really.

Rendering Code

Click to view legibly

You can see also a visibility check… lines start to get drawn unpredictably if the object has a Z value (relative to the camera axis, not the global axis) less than 0, so I set a flag if that’s the case.

So… wire-frame renderer and camera movement. 4.02kb release build, 5.36kb debug.

*- the coordinates are dimensionless… the plane is 1 dimensionless unit away from the camera.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment