Skip to content

how to use the library

angerangel edited this page Jun 27, 2014 · 4 revisions

Fist of all you need a model to display, a model is a list of points (x,y,z) and face (list of points which define each face).

Then you have to load your model in a way that Livecode can read. A the present the way is to create a model matrix defined this way:

  • model["points"][n][1][1] is the X coordinate of the n point
  • model["points"][n][2][1] is the Y coordinate of the n point
  • model["points"][n][3][1] is the Z coordinate of the n point
  • model["scale"] is an optional scale to consider rendering the 3D model
  • model["faces"][n] is a list of points for the face n, like "1,2,5,8"
  • model["color"] is the color of the model

The entire scene is called world, you can put many models in the world:

  • world[1] is the first model in the world
  • world[2] is the second model in the world
  • ...

You can apply any transformation to any single model of the world. See rotate, scale and translate.

Now you have to create your camera, to do so you have to give three points: the first one is where camera is located, the second one where you are looking, the third one is the UP of the camera direction. For example:

#objp is camera position
put 300 into objp[1][1]
put 290 into objp[2][1]
put 320 into objp[3][1]
#posl is camera view direction
put 100 into posl[1][1]
put 100 into posl[2][1]
put 100 into posl[3][1]
#upp is camera up
put sin(pi / 180) into upp[1][1]
put 0 into upp[2][1]   
put cos(pi / 180) into upp[3][1]

then use the r3d_position_object() to build the camera correctly:

put r3d_position_object(objp,posl,upp) into camera

Now you have to create the perspective matrix ( it just divide x,y coordinates by [(z+f)/f] ). The value 256 for f is a good value, but you can change it:

 put r3d_perspective(256) into projection

Now You have to select the window size of the rendering:

 put "400,360" into canvas

Finally you can launch render2 in order to render your scene:

render2  world,camera,canvas,false

The last option regards avoiding backface culling, a method to not displaying face showing only their back. False do the backfaceculling, true doesn't do the backface culling.

Clone this wiki locally