Appendix A

NVMC Class

We have already seen in Section 2.5.1 how the framework is structured and showed a few examples of access to the element of the scene. Here we will give a more detailed description of the framework to serve as reference.

A.1 Elements of the Scene

NVMC.Race.prototype = {…
 get bbox   : function …
 get track   : function …
 get tunnels  : function …
 get arealigths  : function …
 get lamps   : function …
 get trees   : function …
 get buildings  : function …
 get weather  : function …
 get startPosition  : function …
 get observerPosition : function …
 get photoPosition  : function …
};

The class Race contains all the elements of the scene except the participants to the race (that is, the cars). These elements are: the bounding box of the scene, track, tunnels, trees, buildings, area lights, lamps and weather. Obviously more elements can be considered in the scene (for example, people, flags, etc.), but our intention was not to realize a video game, but to learn computer graphics, so we only introduced essential elements to implement the techniques explained.

Bounding box

race.bbox = [];

bbox is an array of six floating points containing the minimun and maximum corners of the bounding box of the scene: [minx,miny,minz,maxx,maxy,maxz]. It is guaranteed that every element of the scene lies inside this bounding box.

Track

race.track = new Track()
Track.prototype = {…
 get leftSideAt : function …
 get rightSideAt : function …
 get pointsCount : function …
};

The track is described by two arrays of 3D points, race.track.leftSideAt and race.track.rightSideAt, describing the left and right margin, respectively. The layout of the coordinates is: x0, y0, z0, x1, y1, z1, …, xn−1, yn−1, zn−1 where the value of n is found as race.track.pointsCount.

Tunnels

race.tunnels = [];
Tunnel.prototype = {…
  get leftSideAt : function …
  get rightSideAt : function …
  get pointsCount : function …
  get height  : function …
};

A tunnel is described just like a track, with one more member value indicating the height of the entire tunnel.

Buildings

race.buildings = [];
Building.prototype = {…
  get positionAt : function …
  get pointsCount : function …
  get heightAt  : function …
};

A building is described by a polygon for its footprint, specified as a sequence of counterclockwise ordered 3D points on the XZ plane and a height value for each point.

Trees

race.trees = [];
Tree.prototype = {…
  get position  : function …
  get height : function …
};

A tree is described by its position on the ground and its height.

Lamps

race.lamps = [];
Lamp.prototype = {…
 get position : function …
 get height : function …

};

A streelamp, just like a tree, is described with its position on the ground and its height.

Area lights

race.arealights = []
AreaLight.prototype = {…
  get frame  :  function …
  get size  :  function …
  get color  :  function …
};

An area light is emitted from a rectangular surface. The rectangle is lying in the XZ plane of the frame specified by frame (a 4 × 4 matrix), centered on the origin and with size size[0] and size[1]. The color of the area light is specified with color (a 3-value array).

Weather

race.weather = new Weather();
Weather.prototype = {…
 get sunLightDirection  : function …
 get cloudDensity   : function …
 get rainStrength   : function …
};

The weather is characterized by the sunLightDirection (an array of 3 values), the cloudDensity, a real value ranging from 0 (clear sky) to 1 (very cloudy) and rainStrength, also ranging from 0 (no rain) to 1 (storm). Note that in the Upgrade Your Client sections of this book we only used the sunlight direction. The other properties are hints for additional exercises. Clouds may be rendered with impostors just like the trees and rain by means of particle systems as introduced in Section 10.4.

Initial Positions

The last three members of the object Race are used for initialization purposes and are: the car’s starting point position (startPosition), the photographer position (photoPosition) and the observerCamera starting point (observerPosition).

A.2 Players

A player corresponds to a car and it has a PhysicsStaticState and a Physics-DynamicState.

The PhysicsStaticState is the set of the static characteristics of the car, which are all 3-value arrays. The mass is the mass of the car, and the forward-Force (backwardForce) is the magnitude of the force impressed to the car when accelerating forward (backward). The brakingFriction is the friction coefficient imposed to the moving car when the brakes are pressed. These values are set by default to make the car behave as a regular sports car, but you can play with them to obtain different cars.

PhysicsStaticState.prototype = {
  get mass   : function …
  get forwardForce : function …
  get backwardForce  : function …
  get brakingFriction : function …
  get linearFriction : function …
};

The PhysicsDynamicState is the set of characteristics that describe the instantaneous conditions of the car. Frame (a 4 × 4 matrix) is the reference frame of the car and, hence, describes where the car is and how it is oriented. The position and orientation are handy functions to obtain the position of the car (that is, the fourth column of frame) and the orientation (that is, the third column of frame). The linearVelocity, angularVelocity and linearAcceleration are self-explanatory 3-value arrays specifying the current velocity and acceleration of the car.

PhysicsDynamicState.prototype = {
  get position   : function …
  get orientation   : function …
  get frame   : function …
  get linearVelocity : function …
  get angularVelocity : function …
  get linearAcceleration : function …
};
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset