com.threed.jpct
Class World

java.lang.Object
  extended bycom.threed.jpct.World
All Implemented Interfaces:
java.io.Serializable

public class World
extends java.lang.Object
implements java.io.Serializable

The World class is the most important class in jPCT. It's like the "glue" that holds everything together. The world contains objects and light sources that define the scene for jPCT.

See Also:
Serialized Form

Field Summary
static int FOGGING_DISABLED
          No linear distance fogging will be used (default)
static int FOGGING_ENABLED
          Linear distance fogging will be used.
static int FOGGING_PER_PIXEL
          Fogging will be applied per pixel.
static int FOGGING_PER_VERTEX
          Fogging will be applied per vertex by jPCT (default).
static int MAIN_OBJECT_NOT_SET
          The main object (used for portal rendering only) is not set.
 
Constructor Summary
World()
          Creates a new "world".
 
Method Summary
 int addLight(SimpleVector lightPos, java.awt.Color col)
          Adds a light source to the World.
 int addLight(SimpleVector lightPos, float r, float g, float b)
          Adds a light source to the World.
 int addObject(Object3D obj)
          Adds an object to the World's object collection.
 void addObjects(Object3D[] objs)
          Adds all objects from the given array to the world.
 void addPolyline(Polyline line)
          Adds a new Polyline to the world.
 void buildAllObjects()
          Calls build() for every object in the world.
 float calcMinDistance(SimpleVector orig, SimpleVector dir, float ignoreIfLarger)
          Returns the minimal distance to some polygon of the world's objects (have to be colliders) from a particular position vector looking into a specific direction.
 java.lang.Object[] calcMinDistanceAndObject3D(SimpleVector orig, SimpleVector dir, float ignoreIfLarger)
          Returns the minimal distance to some polygon of the world's objects (have to be colliders) from a particular position vector looking into a specific direction.
 boolean checkCameraCollision(int mode, float moveSpeed)
          Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible.
 boolean checkCameraCollision(int mode, float moveSpeed, boolean slideMode)
          Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible.
 boolean checkCameraCollision(int mode, float moveSpeed, float distance, boolean slideMode)
          Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible.
 boolean checkCameraCollision(SimpleVector direction, float moveSpeed, float distance, boolean slideMode)
          Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible.
 boolean checkCameraCollisionEllipsoid(int mode, SimpleVector ellipsoid, float moveSpeed, int recursionDepth)
          Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible.
 boolean checkCameraCollisionEllipsoid(SimpleVector direction, SimpleVector ellipsoid, float moveSpeed, int recursionDepth)
          Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible.
 boolean checkCameraCollisionSpherical(int mode, float radius, float moveSpeed, boolean slideMode)
          Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible.
 boolean checkCameraCollisionSpherical(SimpleVector direction, float radius, float moveSpeed, boolean slideMode)
          Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible.
 int checkCollision(SimpleVector org, SimpleVector dr, float step)
          Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction.
 SimpleVector checkCollisionEllipsoid(SimpleVector org, SimpleVector translation, SimpleVector ellipsoid, int recursionDepth)
          Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction.
 SimpleVector checkCollisionSpherical(SimpleVector org, SimpleVector translation, float radius)
          Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction.
 boolean containsObject(Object3D obj)
          Returns true, if an Object3D belongs to this world and false otherwise.
 void createTriangleStrips()
          Tries to rebuild all objects of this world in a way that they can be rendered by using triangle strips in the most optimal way.
 void decoupleVisibilityList()
          Creates a non-shared visibility list for this World even if Config.shareVisibilityList is set to true.
 void dispose()
          Disposes the world.
 void draw(FrameBuffer buffer)
          Draws the current scene that has been generated geometry wise by renderScene().
 void draw(FrameBuffer buffer, int start, int end)
          Draws the current scene that has been generated geometry wise by renderScene().
 void drawWireframe(FrameBuffer buffer, java.awt.Color color)
          Draws the current scene as a single-colored wireframe.
 int[] getAmbientLight()
          Returns the ambient light's intensities in an int[]-array in r,g,b order.
 float[] getBounds(boolean visibleOnly)
          Returns the world space bounds of all (optional only the visible) objects that belong to this world.
 Camera getCamera()
          Gets the current camera.
 int getCameraSector()
          Returns the sector-number of the sector the current camera is in.
static java.lang.Thread getDefaultThread()
          Returns the default thread or null if none has been set.
 int getFogging()
          Returns if fogging is being used or not.
 int getFoggingMode()
          Returns the current fogging mode.
 long getFrameCounter()
          Returns the number of frames rendered since startup.
 GLSLShader getGlobalShader()
          Returns the global shader or null if none has been set.
 float getLightAttenuation(int number)
          Gets the attenuation of a light source, if it has be set before.
 float getLightDiscardDistance(int number)
          Gets the discard distance of a light source, if it has be set before.
 float getLightDistanceOverride(int number)
          Returns the overriden distance.
 SimpleVector getLightIntensity(int number)
          Returns the intensity of a light source.
 SimpleVector getLightPosition(int number)
          Gets the position of a light source in world space.
 Lights getLights()
          Returns the Lights instance used by this instance of World to illuminate the scene.
 Object3D getMainObject()
          Gets the main object or null if none is set.
 int getMainObjectID()
          Gets the ID of the main object or MAIN_OBJECT_NOT_SET, if it's not set.
 Object3D getObject(int id)
          Returns the object with the given ID from the World's object collection.
 Object3D getObjectByName(java.lang.String name)
          Returns the object named "name" from the World's object collection.
 java.util.Enumeration getObjects()
          Returns an Enumeration of all user defined objects in this world.
 Portals getPortals()
          Gets the Portals instance used by this world
 int getSize()
          Returns the number of user defined objects in this World.
 VisList getVisibilityList()
          Gets the visibility list of the last rendered frame.
 void invertCulling(boolean inv)
          Inverts culling for all objects in the world at once.
 void lockMatrices()
          The rotations and translations of 3D objects in jPCT are not thread-safe because of performance reasons (and because it is not required in most cases).
 void newCamera()
          Resets the camera to origin looking along the z-axis.
 void removeAll()
          Removes all lights and objects from the world.
 void removeAllLights()
          Removes all lights from the world.
 void removeAllObjects()
          Removes all but the internal objects from the world.
 void removeAllPolylines()
          Removes all Polylines.
 void removeLight(int number)
          Removes a light from the world.
 void removeObject(int id)
          Removes the object with the specified ID from the World's object collection.
 void removeObject(Object3D obj)
          Removes the given object from the World's object collection.
 void removePolyline(Polyline line)
          Removes a Polyline from a world.
 void renderScene(FrameBuffer buffer)
          Transforms and lights all the polygons.
 void setAmbientLight(int r, int g, int b)
          Sets the light intensity for the ambient light source.
 void setCameraTo(Camera cam)
          Sets the camera to another one.
 void setClippingPlanes(float near, float far)
          Deprecated. Use the equally named method in Camera instead
static void setDefaultThread(java.lang.Thread def)
          jPCT's methods can be called from within different threads.
 void setFogging(int fog)
          Enables/Disables linear distance-fogging.
 void setFoggingMode(int mode)
          Sets the fogging mode (per pixel or per polygon).
 void setFogParameters(float distance, float red, float green, float blue)
          Sets the parameters for the linear distance fog (if enabled).
 void setFogParameters(float start, float distance, float red, float green, float blue)
          Sets the parameters for the linear distance fog (if enabled).
 void setGlobalShader(GLSLShader globalShader)
          Sets a global shader.
 void setLightAttenuation(int number, float at)
          Overrides the setting from Config.linearDiv and Config.fadeoutLight for the given light.
 void setLightDiscardDistance(int number, float distance)
          Overrides the setting from Config.discardDistance for the given light number.
 void setLightDistanceOverride(int number, float distance)
          Overrides the distance that is usually calculated by taking the distance between the light source and an object.
 void setLightIntensity(int number, float r, float g, float b)
          Sets the intensity for a light source (the "color" of the light source).
 void setLightPosition(int number, SimpleVector lightPos)
          Moves a light source to a new position in worldspace.
 void setLightRotation(int number, float rx, float ry, float rz)
          Sets the current rotation behaviour of the light source with this number.
 void setLightRotation(int number, SimpleVector rotPos, float rx, float ry, float rz)
          Sets the current rotation behaviour of the light source with this number.
 void setLightVisibility(int number, boolean mode)
          Sets the light to be visible (default) or invisible.
 void setMainObjectID(int objectID)
          Sets the ID of the main object.
 void setObjectsVisibility(boolean visible)
          Sets the visibility for objects that belong to a world.
 void setWorldProcessor(WorldProcessor proc)
          Sets a new world processor.
 java.lang.String toXML()
          Serializes the world to XML.
 void unlockMatrices()
          Unlocks the matrices so that another thread that is waiting to lock them may do so and continue with his normal operation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIN_OBJECT_NOT_SET

public static final int MAIN_OBJECT_NOT_SET
The main object (used for portal rendering only) is not set.

See Also:
Constant Field Values

FOGGING_DISABLED

public static final int FOGGING_DISABLED
No linear distance fogging will be used (default)

See Also:
Constant Field Values

FOGGING_ENABLED

public static final int FOGGING_ENABLED
Linear distance fogging will be used.

See Also:
Constant Field Values

FOGGING_PER_VERTEX

public static final int FOGGING_PER_VERTEX
Fogging will be applied per vertex by jPCT (default). It's fast but doesn't allow for a target color except black (which is default too).

See Also:
Constant Field Values

FOGGING_PER_PIXEL

public static final int FOGGING_PER_PIXEL
Fogging will be applied per pixel. This is slower in software mode but more accurate and it allows for a target color. Using "per pixel" fog in hardware will use OpenGL's fog, which is per vertex too but looks different from jPCT's per vertex fogging (see above).
The software renderer implements this feature using a post processing based on the depth buffer's data. This may lead to problems with transparent objects, because they don't affect the depth buffer...keep this in mind when using this kind of fog.

See Also:
Constant Field Values
Constructor Detail

World

public World()
Creates a new "world". A world is like an empty room that has to be filled with objects and lights. Every instance of world automatically creates an instance of Portals for managing sectors and portals within this world and an instance of Lights for managing the light sources. Additionally, the TextureManager for this VM is known to the world.

Method Detail

dispose

public void dispose()
Disposes the world. This method should be called before the world goes out of scope. This frees some resources that may otherwise be locked.


lockMatrices

public void lockMatrices()
The rotations and translations of 3D objects in jPCT are not thread-safe because of performance reasons (and because it is not required in most cases). However, if one wants to modify the corresponding matrices (by calling the translate()- or one of the rotate?()-methods of an object or the camera) inside a thread that runs in parallel with the thread executing the renderScene()-method, the rendering thread could try to use these matrices while the other thread is still working on them. This could be a problem if a bunch of transformations should be applied to the objects and no state in between should be accidently rendered. Therefor, jPCT can lock these matrices before using them for transformations and unlocks them right after that. This internal locking jPCT supports can be enabled by changing the configuration in Config. Any other thread that is modifying these matrices should call lockMatrices() before doing the actual modifications and unlock them right after. If lockMatrices() is called while another thread has already locked the matrices, the caller is waiting until the first thread unlocks them again. This way, locking the matrices ensures that every thread is working with the correct matrices.

See Also:
Config.lockingTimer, Config.useLocking, unlockMatrices(), renderScene(com.threed.jpct.FrameBuffer)

unlockMatrices

public void unlockMatrices()
Unlocks the matrices so that another thread that is waiting to lock them may do so and continue with his normal operation. Unlocking the matrices without locking them before is an error.

See Also:
lockMatrices()

getLights

public Lights getLights()
Returns the Lights instance used by this instance of World to illuminate the scene. The implementation for managing the lights in jPCT leaves much to be desired and it will change sometimes. Anyway, these methods should be still in then for compatibility with older sources. So use the current implementation without fear...:-)

Returns:
the lights

getSize

public int getSize()
Returns the number of user defined objects in this World.

Returns:
the number of objects

setMainObjectID

public void setMainObjectID(int objectID)
Sets the ID of the main object. The main object is a special object in jPCT when using portal rendering. The main object is the object that defines the sectors for portal rendering as there is no explicit definition of these sectors. For example: An object is created that consists of three rooms. Each one belongs to another sector. In this stage, the sector information is only present in the triangle definitions of this object. It will be derived from there when build() is called for this object but therefor it is important that jPCT knows that it should derive this information from this object. So before calling build() for such an object it is required to set it as main object. The main object is the only object in jPCT where object-space has to be equal to world-space. So one should never transform this object (albeit the current implementation would let one do so...). Important: One world can only have one main object.

Parameters:
objectID - the ID of the object obtained from addObject()
See Also:
Object3D.build(), addObject(com.threed.jpct.Object3D)

getMainObjectID

public int getMainObjectID()
Gets the ID of the main object or MAIN_OBJECT_NOT_SET, if it's not set. Remember that setting a main object is only required if portal rendering is used.

Returns:
the ID of the main Object3D
See Also:
MAIN_OBJECT_NOT_SET

getMainObject

public Object3D getMainObject()
Gets the main object or null if none is set.

Returns:
the main object (or null)

getCamera

public Camera getCamera()
Gets the current camera.

Returns:
the current camera

getPortals

public Portals getPortals()
Gets the Portals instance used by this world

Returns:
the portals

getVisibilityList

public VisList getVisibilityList()
Gets the visibility list of the last rendered frame.

Returns:
the visibility list

decoupleVisibilityList

public void decoupleVisibilityList()
Creates a non-shared visibility list for this World even if Config.shareVisibilityList is set to true. This is required if a threaded renderer (AWTGLRenderer or the multi-threaded GLRenderer) is used to render multiple Worlds into one frame. Each World rendered into the frame has to have its own list in this case.


newCamera

public void newCamera()
Resets the camera to origin looking along the z-axis. This is the position and orientation the camera has after creating a new "world". In fact, this method creates a new camera...hence the name.


setCameraTo

public void setCameraTo(Camera cam)
Sets the camera to another one.

Parameters:
cam - the camera to use

invertCulling

public void invertCulling(boolean inv)
Inverts culling for all objects in the world at once.

Parameters:
inv - invert culling?

getCameraSector

public int getCameraSector()
Returns the sector-number of the sector the current camera is in. Useful for portal rendering only

Returns:
the sector-number

removeObject

public void removeObject(int id)
Removes the object with the specified ID from the World's object collection. This method doesn't check for child/parent objects of the removed object, which will remain intact.

Parameters:
id - the ID of the object to remove

removeObject

public void removeObject(Object3D obj)
Removes the given object from the World's object collection. This method doesn't check for child/parent objects of the removed object, which will remain intact.

Parameters:
obj - the object to remove

getObject

public Object3D getObject(int id)
Returns the object with the given ID from the World's object collection.

Parameters:
id - the ID of the object
Returns:
the object or null if it doesn't exist

containsObject

public boolean containsObject(Object3D obj)
Returns true, if an Object3D belongs to this world and false otherwise.

Parameters:
obj - the object in question
Returns:
true or false

getObjectByName

public Object3D getObjectByName(java.lang.String name)
Returns the object named "name" from the World's object collection. This is an alternative albeit slower way to retrieve objects from the World. A better idea would be not ot lose them anyway...:-)

Parameters:
name - the name of the object
Returns:
the object or null if it doesn't exist

addObject

public int addObject(Object3D obj)
Adds an object to the World's object collection. The object will be referenced in this collection by its ID. The ID of the object in the collection is the same as the object's own ID. addObject() also returns this ID due to "historical reasons". So id=addObject(obj) is basically the same as id=obj.getID(); addObject(obj); Note: Current implementation limits the object-World bindings in a way that an object can only be added to one world at a time. This method doesn't check if the object has been added multiple times. This may change later.

Parameters:
obj - the object to be added
Returns:
the ID of the object in this World's collection
See Also:
Object3D.getID()

addObjects

public void addObjects(Object3D[] objs)
Adds all objects from the given array to the world. This can be useful, if one wants to add a Object3Ds loaded by the 3DS/OBJ loaders to a world at once.

Parameters:
objs - the objects

addLight

public int addLight(SimpleVector lightPos,
                    float r,
                    float g,
                    float b)
Adds a light source to the World. This method allows for overbright lighting and fractional light intensities. The OpenGL renderer doesn't support overbright lighting in the rasterization stage (because hardware usually doesn't), so if one wants to look OpenGL und software renderer output to look similar, overbright lighting shouldn't be used. The intensity will be multiplied by the value of Config.lightMul.

Parameters:
lightPos - the light's position in worldspace
r - the red component of light's color
g - the green component of light's color
b - the blue component of light's color
Returns:
the number of the light source within the light source collection. Used for further references because single light sources are not single Objects but all light sources are part of a Lights Object. This may change some day as mentioned in the description for getLights().
See Also:
getLights(), Config.lightMul

addLight

public int addLight(SimpleVector lightPos,
                    java.awt.Color col)
Adds a light source to the World. The intensity (=color) will be multiplied by the value of Config.lightMul.

Parameters:
lightPos - the light's position in worldspace
col - the Color of the light source. jPCT supports overbright lighting (light values higher than 255 per color). and fractional light intensities (like 10.5f). If you want to use these features, add the light source using addLight(pos,r,g,b) instead
Returns:
the number of the light source within the light source collection. Used for further references.
See Also:
addLight(com.threed.jpct.SimpleVector,float,float,float), Config.lightMul

removeLight

public void removeLight(int number)
Removes a light from the world.

Parameters:
number - the number of the light source ro remove (as returned by addLight())

setLightRotation

public void setLightRotation(int number,
                             SimpleVector rotPos,
                             float rx,
                             float ry,
                             float rz)
Sets the current rotation behaviour of the light source with this number. The rotation will be applied to the light source every frame (a behaviour which is different from what rotations mean for object). So if you want to stop a light source from rotating, set rx, ry and rz to 0f.

Parameters:
number - the number of the light source (as returned by addLight())
rotPos - the position of the rotation center of this light source
rx - the angle around which the light source will be rotated around the x-axis every frame
ry - the angle around which the light source will be rotated around the y-axis every frame
rz - the angle around which the light source will be rotated around the z-axis every frame

setLightRotation

public void setLightRotation(int number,
                             float rx,
                             float ry,
                             float rz)
Sets the current rotation behaviour of the light source with this number. The rotation will be applied to the light source every frame (a behaviour which is different from what rotations mean for object). So if you want to stop a light source from rotating, set rx, ry and rz to 0f. The rotation center of this light source won't be touched by this methods.

Parameters:
number - the number of the light source (as returned by addLight())
rx - the angle around which the light source will be rotated around the x-axis every frame
ry - the angle around which the light source will be rotated around the y-axis every frame
rz - the angle around which the light source will be rotated around the z-axis every frame

setLightPosition

public void setLightPosition(int number,
                             SimpleVector lightPos)
Moves a light source to a new position in worldspace.

Parameters:
number - the number of the light source (as returned by addLight())
lightPos - the position of the light source

setLightVisibility

public void setLightVisibility(int number,
                               boolean mode)
Sets the light to be visible (default) or invisible.

Parameters:
number - the number of the light source (as returned by addLight())
mode - the visibility mode
See Also:
Lights.LIGHT_VISIBLE, Lights.LIGHT_INVISIBLE

setLightDiscardDistance

public void setLightDiscardDistance(int number,
                                    float distance)
Overrides the setting from Config.discardDistance for the given light number.

Parameters:
number - the number of the light source (as returned by addLight())
distance - the discard distance, i.e. the distance where the light will be "cut off" at latest. -1 means never.

setLightDistanceOverride

public void setLightDistanceOverride(int number,
                                     float distance)
Overrides the distance that is usually calculated by taking the distance between the light source and an object. With this, it's possible to let a light source have an effect on an object even if it's very far away and many other lights are actually closer.

Parameters:
number - the number of the light source (as returned by addLight())
distance - the new distance

getLightDistanceOverride

public float getLightDistanceOverride(int number)
Returns the overriden distance. If none is set, -1 will be returned.

Parameters:
number - the number of the light source (as returned by addLight())
Returns:
the overriden distance or -1

setLightAttenuation

public void setLightAttenuation(int number,
                                float at)
Overrides the setting from Config.linearDiv and Config.fadeoutLight for the given light.

Parameters:
number - the number of the light source (as returned by addLight())
at - the attenuation. The lower the value, the faster the light will fade. -1 means no fading at all.

setLightIntensity

public void setLightIntensity(int number,
                              float r,
                              float g,
                              float b)
Sets the intensity for a light source (the "color" of the light source). The intensity will be multiplied by the value of Config.lightMul.

Parameters:
number - the number of the light source (as returned by addLight())
r - the red component of the intensity
g - the green component of the intensity
b - the blue component of the intensity
See Also:
Config.lightMul

getLightAttenuation

public float getLightAttenuation(int number)
Gets the attenuation of a light source, if it has be set before. If it hasn't, the result of this call in undefined (but lower than -1).

Parameters:
number - the number of the light source
Returns:
float the attenuation (is previously set, otherwise something below -1)

getLightDiscardDistance

public float getLightDiscardDistance(int number)
Gets the discard distance of a light source, if it has be set before. If it hasn't, the result of this call in undefined (but lower than -1).

Parameters:
number - the number of the light source
Returns:
float the discard distance (is previously set, otherwise something below -1)

getLightPosition

public SimpleVector getLightPosition(int number)
Gets the position of a light source in world space.

Parameters:
number - the number of the light source (as returned by addLight())
Returns:
SimpleVector the position

getLightIntensity

public SimpleVector getLightIntensity(int number)
Returns the intensity of a light source.

Parameters:
number - the number of the light source (as returned by addLight())
Returns:
a SimpleVector containing the light's intensities in in rbg format in the x,y,z-components of the vector.

setWorldProcessor

public void setWorldProcessor(WorldProcessor proc)
Sets a new world processor. If none is set, jPCT will create a single threaded one by itself. You can use this, to distribute object processing to multiple cores. This is useful for scenes with a high object count only.
Setting a new processor automatically disposes the old one.


setAmbientLight

public void setAmbientLight(int r,
                            int g,
                            int b)
Sets the light intensity for the ambient light source.
Setting this is negative values will darken the whole scene while positive ones will light up everything.

Parameters:
r - the red component (100 is default)
g - the red component (100 is default)
b - the red component (100 is default)

getAmbientLight

public int[] getAmbientLight()
Returns the ambient light's intensities in an int[]-array in r,g,b order.

Returns:
the light's intensities

setFogging

public void setFogging(int fog)
Enables/Disables linear distance-fogging. Keep in mind that for compiled objects, you most likely want to switch the fogging mode to FOGGING_PER_PIXEL as well.

Parameters:
fog - fogging enabled or not
See Also:
FOGGING_ENABLED, FOGGING_DISABLED, FOGGING_PER_PIXEL, setFogParameters(float, float, float, float)

setFoggingMode

public void setFoggingMode(int mode)
Sets the fogging mode (per pixel or per polygon). Per pixel is slower when using software rendering but much more flexible.
If per pixel fog should be used in combination with the OpenGL-renderer, it's advised to (re-)call this method after changing the renderer to OpenGL, because the renderer may not be aware of the current setting otherwise. This is caused by a flaw in jPCT's design...;-)

Parameters:
mode - the fogging mode
See Also:
FOGGING_PER_VERTEX, FOGGING_PER_PIXEL, setFogParameters(float, float, float, float)

getFogging

public int getFogging()
Returns if fogging is being used or not.

Returns:
fogging usage
See Also:
FOGGING_ENABLED, FOGGING_DISABLED

getFoggingMode

public int getFoggingMode()
Returns the current fogging mode.

Returns:
the fogging mode
See Also:
FOGGING_PER_VERTEX, FOGGING_PER_PIXEL

setFogParameters

public void setFogParameters(float distance,
                             float red,
                             float green,
                             float blue)
Sets the parameters for the linear distance fog (if enabled). For the legacy software renderer, the resulting color of a pixel if calculated as col=texelColor+ambient+(fogColor*d)+(lightColors*(1-d)), where d is 0 at z=0 and 1 at z=dist (or higher).
An example: setFogParameters(200,255,-255,-255) will result in a red fog reaching its maximum density at a depth of 200. -255 for both green and blue is required to get a red fog without any traces of green and/or blue. The color components are NOT limited to a range of 0..255 in this case.
However, in OpenGL modes (software and hardware), the colors will be clamped at 0 and 255. There are two modes: per pixel and per vertex. Per pixel allows for a target color, while per vertex doesn't.

Parameters:
distance - the distance in camera-space coordinates at which the fog reaches its maximum density (150 is default, 1 is minimum)
red - the red component of the fog ([0..255] for OpenGL modes, 0 is default)
green - the green component of the fog ([0..255] for OpenGL modes, 0 is default)
blue - the blue component of the fog ([0..255] for OpenGL modes, 0 is default)

setFogParameters

public void setFogParameters(float start,
                             float distance,
                             float red,
                             float green,
                             float blue)
Sets the parameters for the linear distance fog (if enabled). For the legacy software renderer, the resulting color of a pixel if calculated as col=texelColor+ambient+(fogColor*d)+(lightColors*(1-d)), where d is 0 at z=0 and 1 at z=dist (or higher).
An example: setFogParameters(200,255,-255,-255) will result in a red fog reaching its maximum density at a depth of 200. -255 for both green and blue is required to get a red fog without any traces of green and/or blue. The color components are NOT limited to a range of 0..255 in this case.
However, in OpenGL modes (software and hardware), the colors will be clamped at 0 and 255. There are two modes: per pixel and per vertex. Per pixel allows for a target color, while per vertex doesn't.

Parameters:
start - where the fog actually starts. This setting is currently ignored by the software renderers
distance - the distance in camera-space coordinates at which the fog reaches its maximum density (150 is default, 1 is minimum)
red - the red component of the fog ([0..255] for OpenGL modes, 0 is default)
green - the green component of the fog ([0..255] for OpenGL modes, 0 is default)
blue - the blue component of the fog ([0..255] for OpenGL modes, 0 is default)

checkCollision

public int checkCollision(SimpleVector org,
                          SimpleVector dr,
                          float step)
Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction. The method can be used to implement various kinds of collision detection/response and uses a ray-polygon collision detection. All objects should have been set to an appropiate collision mode.

Parameters:
org - the position vector of "something"
dr - the direction vector of "something" (a unit vector)
step - the length of the casted ray (a collision will only be detected of it takes place within this range)
Returns:
the ID of the Object3D if there is a collision, otherwise NO_OBJECT
See Also:
Object3D.getID(), Object3D.NO_OBJECT

checkCollisionSpherical

public SimpleVector checkCollisionSpherical(SimpleVector org,
                                            SimpleVector translation,
                                            float radius)
Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction. The method can be used to implement various kinds of collision detection/response and uses a sphere-polygon collision detection. All objects should have been set to an appropiate collision mode.

Parameters:
org - the position vector of "something"
translation - that should be applied to "something" (Note that this method just checks this translation...it doesn't apply it)
radius - the radius of the sphere (a collision will only be detected of it takes place within this radius)
Returns:
a SimpleVector containing the corrected translation (i.e. the translation that should be used to avoid a collision) or, if no collision takes place, the translation from the call (i.e. no collision means returned SimpleVector.equals(translation)).

checkCollisionEllipsoid

public SimpleVector checkCollisionEllipsoid(SimpleVector org,
                                            SimpleVector translation,
                                            SimpleVector ellipsoid,
                                            int recursionDepth)
Checks if a collision between "something" and an object would take place if this "something" would move step units from its position into a given direction. The method can be used to implement various kinds of collision detection/response and uses a (swept)ellipsoid-polygon collision detection. All objects should have been set to an appropiate collision mode.

Parameters:
org - the position vector of "something"
translation - that should be applied to "something" (Note that this method just checks this translation...it doesn't apply it)
ellipsoid - the radius of the epplisoid in x,y and z direction
recursionDepth - the max. recursion depth of the collision detection. A higher value will improve the accuracy of the collision detection but reduce performance. Reasonable values lie between 1 and 5.
Returns:
a SimpleVector containing the corrected translation (i.e. the translation that should be used to avoid a collision) or, if no collision takes place, the translation from the call (i.e. no collision means returned SimpleVector.equals(translation)).

checkCameraCollision

public boolean checkCameraCollision(int mode,
                                    float moveSpeed)
Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible. If not, the camera will "slide" in the remaining directions. Uses a ray-polygon collision detection.

Parameters:
mode - the direction (relative to its orientation)
moveSpeed - the number of units the camera should move
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.CAMERA_MOVEDOWN, Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEIN, Camera.CAMERA_MOVEOUT, Camera.CAMERA_MOVELEFT, Camera.CAMERA_MOVERIGHT

checkCameraCollision

public boolean checkCameraCollision(int mode,
                                    float moveSpeed,
                                    boolean slideMode)
Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible. Uses a ray-polygon collision detection.

Parameters:
mode - the direction (relative to its orientation)
moveSpeed - the number of units the camera should move
slideMode - indicates if the camera should slide or just stand still in case of collision
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.CAMERA_MOVEDOWN, Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEIN, Camera.CAMERA_MOVEOUT, Camera.CAMERA_MOVELEFT, Camera.CAMERA_MOVERIGHT, Camera.SLIDE, Camera.DONT_SLIDE

checkCameraCollision

public boolean checkCameraCollision(int mode,
                                    float moveSpeed,
                                    float distance,
                                    boolean slideMode)
Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible. Uses a ray-polygon collision detection.

Parameters:
mode - the direction (relative to its orientation)
moveSpeed - the number of units the camera should move
distance - the maximum distance the position vector can have from the polygon before a collision is detected.
slideMode - indicates if the camera should slide or just stand still in case of collision
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.CAMERA_MOVEDOWN, Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEIN, Camera.CAMERA_MOVEOUT, Camera.CAMERA_MOVELEFT, Camera.CAMERA_MOVERIGHT, Camera.SLIDE, Camera.DONT_SLIDE

checkCameraCollision

public boolean checkCameraCollision(SimpleVector direction,
                                    float moveSpeed,
                                    float distance,
                                    boolean slideMode)
Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible. Uses a ray-polygon collision detection.

Parameters:
direction - the direction (should be a normalized vector (i.e. a length of 1))
moveSpeed - the number of units the camera should move
distance - the maximum distance the position vector can have from the polygon before a collision is detected.
slideMode - indicates if the camera should slide or just stand still in case of collision
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.SLIDE, Camera.DONT_SLIDE

calcMinDistanceAndObject3D

public java.lang.Object[] calcMinDistanceAndObject3D(SimpleVector orig,
                                                     SimpleVector dir,
                                                     float ignoreIfLarger)
Returns the minimal distance to some polygon of the world's objects (have to be colliders) from a particular position vector looking into a specific direction. It only takes polygons into consideration that have at least one vertex that is closer than ignoreIfLarger units to the position vector and whose bounding box/octree-node is closer than that value too.
In addition to calcMinDistance(), this method returns the object to which the polygon belongs.

Parameters:
orig - a SimpleVector containing the x,y,z-coordinates of the position vector
dir - a SimpleVector array containing the x,y,z-coordinates of the direction vector (a unit vector)
ignoreIfLarger - only polygons/bounding boxes/octree-nodes within this range will be taken into account
Returns:
the minimal distance to some polygon (= how far can one move into this direction until something will be hit) and the object to which this polygon belongs in an Object[] containing a Float at position 0 and an Object3D on position 1. If there is no such polygon, the array will contain [COLLISION_NONE, null].
See Also:
Object3D.COLLISION_NONE

calcMinDistance

public float calcMinDistance(SimpleVector orig,
                             SimpleVector dir,
                             float ignoreIfLarger)
Returns the minimal distance to some polygon of the world's objects (have to be colliders) from a particular position vector looking into a specific direction. It only takes polygons into consideration that have at least one vertex that is closer than ignoreIfLarger units to the position vector and whose bounding box/octree-node is closer than that value too.

Parameters:
orig - a SimpleVector containing the x,y,z-coordinates of the position vector
dir - a SimpleVector array containing the x,y,z-coordinates of the direction vector (a unit vector)
ignoreIfLarger - only polygons/bounding boxes/octree-nodes within this range will be taken into account
Returns:
the minimal distance to some polygon (= how far can one move into this direction until something will be hit). If there is no such polygon, COLLISION_NONE will be returned.
See Also:
Object3D.COLLISION_NONE

checkCameraCollisionSpherical

public boolean checkCameraCollisionSpherical(int mode,
                                             float radius,
                                             float moveSpeed,
                                             boolean slideMode)
Moves the camera moveSpeed units from its current position and regarding its current orientation into "mode" direction, if this is possible. Uses a sphere-polygon collision detection. This method can be used in CAMERA_DONT_MOVE-mode too, where the camera will only be adjusted automatically if anything that is a collider has moved in its way.

Parameters:
mode - the direction (relative to its orientation)
radius - the radius of the sphere. A collision will only be detected within this radius.
moveSpeed - the number of units the camera should move
slideMode - indicates if the camera should slide or just stand still in case of collision
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.CAMERA_MOVEDOWN, Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEIN, Camera.CAMERA_MOVEOUT, Camera.CAMERA_MOVELEFT, Camera.CAMERA_MOVERIGHT, Camera.CAMERA_DONT_MOVE, Camera.SLIDE, Camera.DONT_SLIDE

checkCameraCollisionSpherical

public boolean checkCameraCollisionSpherical(SimpleVector direction,
                                             float radius,
                                             float moveSpeed,
                                             boolean slideMode)
Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible. Uses a sphere-polygon collision detection.

Parameters:
direction - the direction (should be a normalized vector (i.e. a length of 1))
radius - the radius of the sphere. A collision will only be detected within this radius.
moveSpeed - the number of units the camera should move
slideMode - indicates if the camera should slide or just stand still in case of collision
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.SLIDE, Camera.DONT_SLIDE

checkCameraCollisionEllipsoid

public boolean checkCameraCollisionEllipsoid(int mode,
                                             SimpleVector ellipsoid,
                                             float moveSpeed,
                                             int recursionDepth)
Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible. Uses a (swept)ellipsoid-polygon collision detection. This method will always use sliding.

Parameters:
mode - the direction (relative to its orientation)
ellipsoid - the radius of the epplisoid in x,y and z direction
moveSpeed - the number of units the camera should move
recursionDepth - the max. recursion depth of the collision detection. A higher value will improve the accuracy of the collision detection but reduce performance. Reasonable values lie between 1 and 5.
Returns:
true if the camera collided with something, otherwise false
See Also:
Camera.CAMERA_MOVEDOWN, Camera.CAMERA_MOVEUP, Camera.CAMERA_MOVEIN, Camera.CAMERA_MOVEOUT, Camera.CAMERA_MOVELEFT, Camera.CAMERA_MOVERIGHT, Camera.CAMERA_DONT_MOVE

checkCameraCollisionEllipsoid

public boolean checkCameraCollisionEllipsoid(SimpleVector direction,
                                             SimpleVector ellipsoid,
                                             float moveSpeed,
                                             int recursionDepth)
Moves the camera moveSpeed units from its current position into an arbitrary direction, if this is possible. Uses a (swept)ellipsoid-polygon collision detection. This method will always use sliding.

Parameters:
direction - the direction (should be a normalized vector (i.e. a length of 1))
ellipsoid - the radius of the epplisoid in x,y and z direction
moveSpeed - the number of units the camera should move
recursionDepth - the max. recursion depth of the collision detection. A higher value will improve the accuracy of the collision detection but reduce performance. Reasonable values lie between 1 and 5.
Returns:
true if the camera collided with something, otherwise false

buildAllObjects

public void buildAllObjects()
Calls build() for every object in the world.

See Also:
Object3D.build()

createTriangleStrips

public void createTriangleStrips()
Tries to rebuild all objects of this world in a way that they can be rendered by using triangle strips in the most optimal way. This may be useful when using the OpenGL renderer to increase performance for complex objects. The software renderer doesn't use this information (but it shouldn't hurt either). This calculation may take some time on complex objects.

See Also:
Object3D.createTriangleStrips(), Config.glTriangleStrips, Config.useMultipassStriping

renderScene

public void renderScene(FrameBuffer buffer)
Transforms and lights all the polygons. This method does everything required to start drawing the current scene. It just doesn't scanconvert the results. This is done by the draw()-method.

Parameters:
buffer - the framebuffer that should be used for rendering
See Also:
draw(com.threed.jpct.FrameBuffer)

draw

public void draw(FrameBuffer buffer)
Draws the current scene that has been generated geometry wise by renderScene(). Usually, renderScene() and draw() are used one right after the other (with draw being the last).

Parameters:
buffer - the framebuffer that should be used for rendering
See Also:
renderScene(com.threed.jpct.FrameBuffer)

draw

public void draw(FrameBuffer buffer,
                 int start,
                 int end)
Draws the current scene that has been generated geometry wise by renderScene(). Usually, renderScene() and draw() are used one right after the other (with draw being the last).
This is a special purpose version of draw() that allows for giving a starting and ending index to limit drawing to a certain part of the VisList. Maybe helpful for special effects of some kind, but usually not needed. Keep in mind that when using a threaded renderer (AWTGL or GL in multi threading mode), the actual drawing doesn't happen when calling this method, so it's not possible to do something between drawing two parts of the VisList by using this method.

Parameters:
buffer - the framebuffer that should be used for rendering
start - the index of the first polygon to draw (in the VisList)
end - the index of the last polygon to draw (in the VisList)
See Also:
renderScene(com.threed.jpct.FrameBuffer)

drawWireframe

public void drawWireframe(FrameBuffer buffer,
                          java.awt.Color color)
Draws the current scene as a single-colored wireframe. This is done using the same buffer draw() draws into. drawWireframe() can be called instead of draw() to get the wireframe only as well as right after draw() to combine the two renderings for some special effects. Calling drawWireframe() before draw() doesn't make much sense.
jPCT's wireframe mode is not as optimized as the texturemapped mode is (yet) but it should be "fast enough".

Parameters:
buffer - the framebuffer that should be used for rendering
color - the wireframe's color

getFrameCounter

public long getFrameCounter()
Returns the number of frames rendered since startup.

Returns:
the number of frames (to be precise: how often draw() has been called)

getObjects

public java.util.Enumeration getObjects()
Returns an Enumeration of all user defined objects in this world.

Returns:
the objects (instances of Object3D)

setObjectsVisibility

public void setObjectsVisibility(boolean visible)
Sets the visibility for objects that belong to a world.

Parameters:
visible - visible or not?

removeAll

public void removeAll()
Removes all lights and objects from the world.


removeAllObjects

public void removeAllObjects()
Removes all but the internal objects from the world. The world is empty after calling this method.


removeAllLights

public void removeAllLights()
Removes all lights from the world. The scene will be lit by ambient lighting only after calling this method.


addPolyline

public void addPolyline(Polyline line)
Adds a new Polyline to the world. A Polyline is a line strip with a color that will be drawn into the scene after all other objects has been drawn. A Polyline's coordinates are to be given in world space. You can add multiple Polylines to a world.

Parameters:
line - the Polyline

removePolyline

public void removePolyline(Polyline line)
Removes a Polyline from a world.

Parameters:
line - the line

removeAllPolylines

public void removeAllPolylines()
Removes all Polylines.


setDefaultThread

public static void setDefaultThread(java.lang.Thread def)
jPCT's methods can be called from within different threads. However, it's very likely that one thread will do most of the work while others may run less often or doing less work. With this method, it's possible to tell jPCT which is the "default" thread, i.e. the thread that does most of the work. If jPCT knows this, some optimizations for this thread can be performed. Note that this value isn't serialized if World is.
If you don't set this value, jPCT will auto-detect the default thread.

Parameters:
def - the "default" thread

getDefaultThread

public static java.lang.Thread getDefaultThread()
Returns the default thread or null if none has been set.

Returns:
the thread or null

setGlobalShader

public void setGlobalShader(GLSLShader globalShader)
Sets a global shader. If set, this shader will be applied to all objects that have no own shader assigned.

Parameters:
globalShader - the global shader

getGlobalShader

public GLSLShader getGlobalShader()
Returns the global shader or null if none has been set.

Returns:
the global shader

setClippingPlanes

public void setClippingPlanes(float near,
                              float far)
Deprecated. Use the equally named method in Camera instead

If set, this overrides the settings in Config for the near and the far clipping plane for this world. If you don't touch this method, the settings in Config will be taken instead.
This method is deprecated and only here for compatibility reasons. The setting has moved into the Camera class. Calling this method here is just a shortcut to getCamera().setClippingPlanes(...).

Parameters:
near - the near plane
far - the far plane
See Also:
Config.farPlane, Config.nearPlane, Camera.setClippingPlanes(float, float)

getBounds

public float[] getBounds(boolean visibleOnly)
Returns the world space bounds of all (optional only the visible) objects that belong to this world. Or in other words: All vertices of all objects in this world will be located inside the returned bounding box. Format of the return array is minX, maxX, minY, maxY, minZ, maxZ.

Parameters:
visibleOnly - if true, only visible objects will be taken into account. If false, all objects will.
Returns:
the bounding box

toXML

public java.lang.String toXML()
Serializes the world to XML. Not all of the world's and objects' attributes are serialized. Have a look at the DTD for jPCT's XML-format for more details. The resulting XML can be quite huge.

Returns:
the XML