|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.threed.jpct.World
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.
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 |
prewarmCompiledObjects(FrameBuffer buffer)
Compiles all objects in the world in one run instead of on demand. |
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 |
public static final int MAIN_OBJECT_NOT_SET
public static final int FOGGING_DISABLED
public static final int FOGGING_ENABLED
public static final int FOGGING_PER_VERTEX
public static final int FOGGING_PER_PIXEL
Constructor Detail |
public World()
Method Detail |
public void dispose()
public void lockMatrices()
Config.lockingTimer
,
Config.useLocking
,
unlockMatrices()
,
renderScene(com.threed.jpct.FrameBuffer)
public void unlockMatrices()
lockMatrices()
public Lights getLights()
public int getSize()
public void setMainObjectID(int objectID)
objectID
- the ID of the object obtained from addObject()Object3D.build()
,
addObject(com.threed.jpct.Object3D)
public int getMainObjectID()
MAIN_OBJECT_NOT_SET
public Object3D getMainObject()
public Camera getCamera()
public Portals getPortals()
public VisList getVisibilityList()
public void decoupleVisibilityList()
public void newCamera()
public void setCameraTo(Camera cam)
cam
- the camera to usepublic void invertCulling(boolean inv)
inv
- invert culling?public int getCameraSector()
public void removeObject(int id)
id
- the ID of the object to removepublic void removeObject(Object3D obj)
obj
- the object to removepublic Object3D getObject(int id)
id
- the ID of the object
public boolean containsObject(Object3D obj)
obj
- the object in question
public Object3D getObjectByName(java.lang.String name)
name
- the name of the object
public int addObject(Object3D obj)
obj
- the object to be added
Object3D.getID()
public void addObjects(Object3D[] objs)
objs
- the objectspublic int addLight(SimpleVector lightPos, float r, float g, float b)
lightPos
- the light's position in worldspacer
- the red component of light's colorg
- the green component of light's colorb
- the blue component of light's color
getLights()
,
Config.lightMul
public int addLight(SimpleVector lightPos, java.awt.Color col)
lightPos
- the light's position in worldspacecol
- 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
addLight(com.threed.jpct.SimpleVector,float,float,float)
,
Config.lightMul
public void removeLight(int number)
number
- the number of the light source ro remove (as returned by
addLight())public void setLightRotation(int number, SimpleVector rotPos, float rx, float ry, float rz)
number
- the number of the light source (as returned by addLight())rotPos
- the position of the rotation center of this light sourcerx
- the angle around which the light source will be rotated around
the x-axis every framery
- the angle around which the light source will be rotated around
the y-axis every framerz
- the angle around which the light source will be rotated around
the z-axis every framepublic void setLightRotation(int number, float rx, float ry, float rz)
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 framery
- the angle around which the light source will be rotated around
the y-axis every framerz
- the angle around which the light source will be rotated around
the z-axis every framepublic void setLightPosition(int number, SimpleVector lightPos)
number
- the number of the light source (as returned by addLight())lightPos
- the position of the light sourcepublic void setLightVisibility(int number, boolean mode)
number
- the number of the light source (as returned by addLight())mode
- the visibility modeLights.LIGHT_VISIBLE
,
Lights.LIGHT_INVISIBLE
public void setLightDiscardDistance(int number, float distance)
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.public void setLightDistanceOverride(int number, float distance)
number
- the number of the light source (as returned by addLight())distance
- the new distancepublic float getLightDistanceOverride(int number)
number
- the number of the light source (as returned by addLight())
public void setLightAttenuation(int number, float at)
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.public void setLightIntensity(int number, float r, float g, float b)
number
- the number of the light source (as returned by addLight())r
- the red component of the intensityg
- the green component of the intensityb
- the blue component of the intensityConfig.lightMul
public float getLightAttenuation(int number)
number
- the number of the light source
public float getLightDiscardDistance(int number)
number
- the number of the light source
public SimpleVector getLightPosition(int number)
number
- the number of the light source (as returned by addLight())
public SimpleVector getLightIntensity(int number)
number
- the number of the light source (as returned by addLight())
public void setWorldProcessor(WorldProcessor proc)
public void setAmbientLight(int r, int g, int b)
r
- the red component (100 is default)g
- the red component (100 is default)b
- the red component (100 is default)public int[] getAmbientLight()
public void setFogging(int fog)
fog
- fogging enabled or notFOGGING_ENABLED
,
FOGGING_DISABLED
,
FOGGING_PER_PIXEL
,
setFogParameters(float, float, float, float)
public void setFoggingMode(int mode)
mode
- the fogging modeFOGGING_PER_VERTEX
,
FOGGING_PER_PIXEL
,
setFogParameters(float, float, float, float)
public int getFogging()
FOGGING_ENABLED
,
FOGGING_DISABLED
public int getFoggingMode()
FOGGING_PER_VERTEX
,
FOGGING_PER_PIXEL
public void setFogParameters(float distance, float red, float green, float blue)
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)public void setFogParameters(float start, float distance, float red, float green, float blue)
start
- where the fog actually starts. This setting is currently
ignored by the software renderersdistance
- 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)public int checkCollision(SimpleVector org, SimpleVector dr, float step)
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)
Object3D.getID()
,
Object3D.NO_OBJECT
public SimpleVector checkCollisionSpherical(SimpleVector org, SimpleVector translation, float radius)
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)
public SimpleVector checkCollisionEllipsoid(SimpleVector org, SimpleVector translation, SimpleVector ellipsoid, int recursionDepth)
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 directionrecursionDepth
- 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.
public boolean checkCameraCollision(int mode, float moveSpeed)
mode
- the direction (relative to its orientation)moveSpeed
- the number of units the camera should move
Camera.CAMERA_MOVEDOWN
,
Camera.CAMERA_MOVEUP
,
Camera.CAMERA_MOVEIN
,
Camera.CAMERA_MOVEOUT
,
Camera.CAMERA_MOVELEFT
,
Camera.CAMERA_MOVERIGHT
public boolean checkCameraCollision(int mode, float moveSpeed, boolean slideMode)
mode
- the direction (relative to its orientation)moveSpeed
- the number of units the camera should moveslideMode
- indicates if the camera should slide or just stand still in
case of collision
Camera.CAMERA_MOVEDOWN
,
Camera.CAMERA_MOVEUP
,
Camera.CAMERA_MOVEIN
,
Camera.CAMERA_MOVEOUT
,
Camera.CAMERA_MOVELEFT
,
Camera.CAMERA_MOVERIGHT
,
Camera.SLIDE
,
Camera.DONT_SLIDE
public boolean checkCameraCollision(int mode, float moveSpeed, float distance, boolean slideMode)
mode
- the direction (relative to its orientation)moveSpeed
- the number of units the camera should movedistance
- 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
Camera.CAMERA_MOVEDOWN
,
Camera.CAMERA_MOVEUP
,
Camera.CAMERA_MOVEIN
,
Camera.CAMERA_MOVEOUT
,
Camera.CAMERA_MOVELEFT
,
Camera.CAMERA_MOVERIGHT
,
Camera.SLIDE
,
Camera.DONT_SLIDE
public boolean checkCameraCollision(SimpleVector direction, float moveSpeed, float distance, boolean slideMode)
direction
- the direction (should be a normalized vector (i.e. a length of
1))moveSpeed
- the number of units the camera should movedistance
- 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
Camera.SLIDE
,
Camera.DONT_SLIDE
public java.lang.Object[] calcMinDistanceAndObject3D(SimpleVector orig, SimpleVector dir, float ignoreIfLarger)
orig
- a SimpleVector containing the x,y,z-coordinates of the
position vectordir
- 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
Object3D.COLLISION_NONE
public float calcMinDistance(SimpleVector orig, SimpleVector dir, float ignoreIfLarger)
orig
- a SimpleVector containing the x,y,z-coordinates of the
position vectordir
- 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
Object3D.COLLISION_NONE
public boolean checkCameraCollisionSpherical(int mode, float radius, float moveSpeed, boolean slideMode)
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 moveslideMode
- indicates if the camera should slide or just stand still in
case of collision
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
public boolean checkCameraCollisionSpherical(SimpleVector direction, float radius, float moveSpeed, boolean slideMode)
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 moveslideMode
- indicates if the camera should slide or just stand still in
case of collision
Camera.SLIDE
,
Camera.DONT_SLIDE
public boolean checkCameraCollisionEllipsoid(int mode, SimpleVector ellipsoid, float moveSpeed, int recursionDepth)
mode
- the direction (relative to its orientation)ellipsoid
- the radius of the epplisoid in x,y and z directionmoveSpeed
- the number of units the camera should moverecursionDepth
- 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.
Camera.CAMERA_MOVEDOWN
,
Camera.CAMERA_MOVEUP
,
Camera.CAMERA_MOVEIN
,
Camera.CAMERA_MOVEOUT
,
Camera.CAMERA_MOVELEFT
,
Camera.CAMERA_MOVERIGHT
,
Camera.CAMERA_DONT_MOVE
public boolean checkCameraCollisionEllipsoid(SimpleVector direction, SimpleVector ellipsoid, float moveSpeed, int recursionDepth)
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 directionmoveSpeed
- the number of units the camera should moverecursionDepth
- 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.
public void buildAllObjects()
Object3D.build()
public void prewarmCompiledObjects(FrameBuffer buffer)
buffer
- the current FrameBufferpublic void createTriangleStrips()
Object3D.createTriangleStrips()
,
Config.glTriangleStrips
,
Config.useMultipassStriping
public void renderScene(FrameBuffer buffer)
buffer
- the framebuffer that should be used for renderingdraw(com.threed.jpct.FrameBuffer)
public void draw(FrameBuffer buffer)
buffer
- the framebuffer that should be used for renderingrenderScene(com.threed.jpct.FrameBuffer)
public void draw(FrameBuffer buffer, int start, int end)
buffer
- the framebuffer that should be used for renderingstart
- the index of the first polygon to draw (in the VisList)end
- the index of the last polygon to draw (in the VisList)renderScene(com.threed.jpct.FrameBuffer)
public void drawWireframe(FrameBuffer buffer, java.awt.Color color)
buffer
- the framebuffer that should be used for renderingcolor
- the wireframe's colorpublic long getFrameCounter()
public java.util.Enumeration getObjects()
public void setObjectsVisibility(boolean visible)
visible
- visible or not?public void removeAll()
public void removeAllObjects()
public void removeAllLights()
public void addPolyline(Polyline line)
line
- the Polylinepublic void removePolyline(Polyline line)
line
- the linepublic void removeAllPolylines()
public static void setDefaultThread(java.lang.Thread def)
def
- the "default" threadpublic static java.lang.Thread getDefaultThread()
public void setGlobalShader(GLSLShader globalShader)
globalShader
- the global shaderpublic GLSLShader getGlobalShader()
public void setClippingPlanes(float near, float far)
near
- the near planefar
- the far planeConfig.farPlane
,
Config.nearPlane
,
Camera.setClippingPlanes(float, float)
public float[] getBounds(boolean visibleOnly)
visibleOnly
- if true, only visible objects will be taken into account. If
false, all objects will.
public java.lang.String toXML()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |