Flylib.com

Books Software

 
 
 

SetFlatSet GouraudSetLambert


SetFlat/Set Gouraud/SetLambert

SetFlat and SetGouraud enable or disable the flat or Gouraud rendering modes.

object.SetFlat(On/Off)

or

object.SetGouraud(On/Off)

Notes

Objects in Jamagic can have Gouraud or flat shading (a third type is Lambert shading, which is nearly identical to Gouraud).

Flat shading is not very realistic. It is uniformly bright over the entire object s surface.

Gouraud shading gives a much more realistic and interesting effect in that the brightness of the surface is not uniform.

Sample Code

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
sphere.SetPosition(0,200,0);
mats = New Material(oworld,,RED,"mats");
sphere.SetGouraud();
sphere.ReplaceMaterial(mats);
plane = oworld.CreatePlane(600,600);
Matplane = New Material(oworld, ,GREEN, "Matplane");
matplane.SetFlat;
plane.ReplaceMaterial(matplane);
plane.SetAngle(-Pi/2,0,0);
plane.SetStatic();
oworld.Optimize(ocamera);
ocamera.MoveBack(1200);
ocamera.MoveUp(200);
sphere.Walk();

sphere.SetShadowMode(Object.SHADOW_MODE_TRUE);
sphere.EnableShadow();
//loop
While(TRUE);



SetGravity

Sets gravity (motion down) on an object.

object.SetGravity(speed)

Parameters

speed

Refers to the rate at which the object will drop.

Notes

The larger the value, the faster the drop. Please note that using negative values will cause the object to rise instead of drop.

Sample Code

The following code will drop the sphere using the gravity command until it reaches a y value of “100, at which point it will be moved back to its starting point.

Please note as well that the Stop command will not stop an object under the gravity command. You must stop it by setting gravity to zero.

oworld = New World();
ocamera = New Camera(oworld);
// Create sphere 100 around, and place it at (0,300,0).
osphere = oworld.CreateSphere(100,100,100)
osphere.Set Position(0,300,0);
ocamera.MoveBack(1200);
osphere.set gravity(0.01);

//Loop
While(TRUE)
 {
  If((osphere.gety) < -100)
   {
    Osphere.SetPosition(0,300,0);
   }
}



SetPosition

Sets the location of an object in the 3D world.

object.SetPosition(x, y, z, speed)

Parameters

speed

Refers to the rate at which the change in position will be made (in seconds)

x, y, z

The new position of the object in the 3D reference axes

Notes

Alternately, we could write the following:

object.SetPosition(Other3DObject, speed)

In this case, the position of our object becomes that of another object.

Sample Code

oworld = New World();
ocamera = New Camera(oworld);
// Create sphere 100 around, and place it at (0,300,0).
osphere = oworld.CreateSphere(100,100,100)
osphere.Set Position(0,300,0);
ocamera.MoveBack(1200);
osphere.set gravity(0.01);

//Loop
While(TRUE)
 {
  If((osphere.gety) < -100)
   {
    Osphere.SetPosition(0,300,0);
   }
 }



SetRelativeAngle

This command changes the angle of the object relative to its own position. It changes the angle immediately or at a speed that you can specify.

object.SetRelativeAngle(xangle, yangle, zangle, time)

Parameters

xangle , yangle , and zangle

Refer to the number of radians to add about each axis

time

Refers to the number of seconds for which the rotation is to take place (in seconds)

Notes

Alternately, you can say

object.SetRelativeAngle(another3DObject, time),

where another3DObject refers to another object from which to set the angle.

It is important to know that there is a difference between the SetRelativeAngle command and the AddAngle command. The AddAngle command moves the object about the stationary world axes. The SetRelativeAngle moves the object about its own x, y, and z axes.

Sample Code

The following code illustrates the difference between moving objects with the AddAngle command and moving them with the SetRelativeAngle command by moving two different objects using the two commands.

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateBrick(50,50,50);
sphere2 = oworld.CreateBrick(50,50,50);
sphere2.SetPosition(100,0,0);
ocamera.MoveBack(1200);
ocamera.Walk();

sphere.AddAngle(1,2,3,10); //Rotates it in 5 seconds.
sphere2.SetRelativeAngle(1,2,3,10); //Rotates it in 5 seconds.
//Show the axes of the two objects.
oworld.ShowObjectAxis();

//Loop
While(TRUE)
{
}

SetShadowMode selects one of two types of shadows to be used ”true or texture.

object.SetShadowMode(ShadowMode)

SetShadowTexture selects the picture to be used as a shadow in the texture mode (see this demonstrated in the code later in this section).

SetShadowTextureSize sets the size of the shadow in the texture mode (see this demonstrated in the code later in this section).

EnableShadow turns on the shadow mode.

Parameters

There are two types of shadow modes:

Object.SHADOW_MODE_TEXTURE

This type is faster than True Mode and uses a texture that you specify as the shadow.

Object.SHADOW_MODE_TRUE

This type makes a true shadow of the object.

Notes

Objects in Jamagic can have shadows that rest underneath them. Shadows are displayed on static backgrounds (backgrounds that have been declared as static objects).

True shadows are slower (this is important to know if your game is starting to run slowly). They take the form of a dark surface underneath your object and they have a shape similar to the object. Textured shadows are fake in that they are images you specify to represent the shape of the shadow rather than the shape of the object and its shadow. Textured shadows run faster.

Sample Code

The following code allows you to observe the differences between the two types of shadow by commenting out the appropriate lines. Please note that shadows must be enabled using the EnableShadow command.

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
sphere.SetPosition(0,200,0);
mats = New Material(oworld,,RED,"mats");
mats.SetFlat();
sphere.ReplaceMaterial(mats);
plane = oworld.CreatePlane(600,600);
Matplane = New Material(oworld, ,GREEN, "Matplane");
matplane.SetFlat;
plane.ReplaceMaterial(matplane);
plane.SetAngle(-Pi/2,0,0);
plane.SetStatic();
oworld.Optimize(ocamera);
ocamera.MoveBack(1200);
ocamera.MoveUp(200);
sphere.Walk();

// Next line is for true shadow mode.
// sphere.SetShadowMode(Object.SHADOW_MODE_TRUE);

//Next 4 lines are for texture shadow mode. Wheel is the //picture
//to be used as a shadow. If you run this program, you must //have
// an image under "pictures" named "wheel," or some other name
// if you modify the code.

tex = New Texture(oworld, "wheel");
sphere.SetShadowMode(Object.SHADOW_MODE_TEXTURE);
sphere.SetShadowTexture(tex);
sphere.SetShadowTextureSize(100,100);

sphere.EnableShadow();
//Loop
While(TRUE);