com.threed.jpct
Class Interact2D

java.lang.Object
  extended bycom.threed.jpct.Interact2D

public final class Interact2D
extends java.lang.Object

Interact2D offers some static methods for interacting with objects in camera-space. Its main purpose is to allow object-picking with the mouse (or with whatever). Everything within here has to be called after calling World.renderScene(...), because the current visibility list is required.


Field Summary
static int EXCLUDE_NOT_SELECTABLE
          Constant for pickPolygon(...) to exclude unselectable objects from picking.
static int EXCLUDE_TRANSPARENT
          Constant for pickPolygon(...) to exclude transparent objects from picking.
 
Method Summary
static int getObjectID(int[] res)
          Gets the ID of a picked object out of the result array.
static int getPolygonID(int[] res)
          Gets the ID of a picked polygon out of the result array.
static int[] pickPolygon(VisList visList, SimpleVector dr)
          Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and lies in the given direction.
static int[] pickPolygon(VisList visList, SimpleVector dr, int exclude)
          Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and lies in the given direction.
static int[] pickPolygon(VisList visList, SimpleVector rp1, SimpleVector rp2)
          Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and that is hit by the ray casted from some position vector into the scene.
static int[] pickPolygon(VisList visList, SimpleVector rp1, SimpleVector rp2, int exclude)
          Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and that is hit by the ray casted from some position vector into the scene.
static SimpleVector project3D2D(Camera camera, FrameBuffer buffer, SimpleVector vertex)
          Projects a vertex from world space into screen space.
static SimpleVector project3D2D(Camera camera, FrameBuffer buffer, SimpleVector vertex, SimpleVector toFill)
          Projects a vertex from world space into screen space.
static SimpleVector projectCenter3D2D(Camera camera, FrameBuffer buffer, Object3D obj)
          Gets the center of the object in screen-coordinates (2D) by transforming and projecting it from 3D objectspace into 2D screenspace.
static SimpleVector projectCenter3D2D(FrameBuffer buffer, Object3D obj)
          Gets the center of the object in screen-coordinates (2D) by transforming and projecting it from 3D objectspace into 2D screenspace.
static SimpleVector reproject2D3D(Camera camera, FrameBuffer buffer, int x, int y)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (camera space).
static SimpleVector reproject2D3D(Camera camera, FrameBuffer buffer, int x, int y, float z)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D with a given z (in 3D).
static SimpleVector reproject2D3D(Camera camera, FrameBuffer buffer, int x, int y, float z, SimpleVector toFill)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D with a given z (in 3D).
static SimpleVector reproject2D3D(Camera camera, FrameBuffer buffer, int x, int y, SimpleVector toFill)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (camera space).
static SimpleVector reproject2D3DWS(Camera camera, FrameBuffer buffer, int x, int y)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space).
static SimpleVector reproject2D3DWS(Camera camera, FrameBuffer buffer, int x, int y, float z)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space).
static SimpleVector reproject2D3DWS(Camera camera, FrameBuffer buffer, int x, int y, float z, SimpleVector toFill)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space).
static SimpleVector reproject2D3DWS(Camera camera, FrameBuffer buffer, int x, int y, SimpleVector toFill)
          Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCLUDE_TRANSPARENT

public static final int EXCLUDE_TRANSPARENT
Constant for pickPolygon(...) to exclude transparent objects from picking. They won't even act as a block to the picking ray any longer.

See Also:
Constant Field Values

EXCLUDE_NOT_SELECTABLE

public static final int EXCLUDE_NOT_SELECTABLE
Constant for pickPolygon(...) to exclude unselectable objects from picking. They won't even act as a block to the picking ray any longer.

See Also:
Constant Field Values
Method Detail

reproject2D3D

public static SimpleVector reproject2D3D(Camera camera,
                                         FrameBuffer buffer,
                                         int x,
                                         int y)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (camera space). The Z-value is assumed to be 1. Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
Returns:
the reprojected vector in camera space

reproject2D3D

public static SimpleVector reproject2D3D(Camera camera,
                                         FrameBuffer buffer,
                                         int x,
                                         int y,
                                         SimpleVector toFill)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (camera space). The Z-value is assumed to be 1. Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
toFill - a SimpleVector that will be filled with the result
Returns:
the reprojected vector in camera space

reproject2D3DWS

public static SimpleVector reproject2D3DWS(Camera camera,
                                           FrameBuffer buffer,
                                           int x,
                                           int y)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space). The Z-value is assumed to be 1. Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
Returns:
the direction vector from the camera to the position in world space

reproject2D3DWS

public static SimpleVector reproject2D3DWS(Camera camera,
                                           FrameBuffer buffer,
                                           int x,
                                           int y,
                                           SimpleVector toFill)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space). The Z-value is assumed to be 1. Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
toFill - a SimpleVector that will be filled with the result
Returns:
the direction vector from the camera to the position in world space

reproject2D3DWS

public static SimpleVector reproject2D3DWS(Camera camera,
                                           FrameBuffer buffer,
                                           int x,
                                           int y,
                                           float z)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space). Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
z - the z position in camera space
Returns:
the direction vector from the camera to the position in world space

reproject2D3DWS

public static SimpleVector reproject2D3DWS(Camera camera,
                                           FrameBuffer buffer,
                                           int x,
                                           int y,
                                           float z,
                                           SimpleVector toFill)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D (world space). Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
z - the z position in camera space
toFill - a SimpleVector that will be filled with the result
Returns:
the direction vector from the camera to the position in world space

reproject2D3D

public static SimpleVector reproject2D3D(Camera camera,
                                         FrameBuffer buffer,
                                         int x,
                                         int y,
                                         float z)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D with a given z (in 3D). Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
z - the z position of the "picking plane" (in 3D)
Returns:
the reprojected vector in camera space

reproject2D3D

public static SimpleVector reproject2D3D(Camera camera,
                                         FrameBuffer buffer,
                                         int x,
                                         int y,
                                         float z,
                                         SimpleVector toFill)
Reprojects a 2D vector (a screen/framebuffer coordinate in most cases) back into 3D with a given z (in 3D). Please note that the actual framebuffer coordinates are being scaled (compared to the size of the output buffer) when using oversampling. This method assumes the given coordinates to be real framebuffer coordinates. (Example: If you are implementing mouse-picking and are using 2x2 oversampling for your framebuffer, the coordinates this method needs are 2* your actual mouse-coordinates (in x as well as in y direction.))

Parameters:
camera - the camera used to render the scene
buffer - the framebuffer containing the rendered image
x - the x position in 2D
y - the y position in 2D
z - the z position of the "picking plane" (in 3D)
toFill - a SimpleVector that will be filled with the result
Returns:
the reprojected vector in camera space

project3D2D

public static SimpleVector project3D2D(Camera camera,
                                       FrameBuffer buffer,
                                       SimpleVector vertex)
Projects a vertex from world space into screen space.

Parameters:
camera - the Camera used for the projection
buffer - the Framebuffer
vertex - the vertex in world space
Returns:
a SimpleVector containing the x- and y-coordinates in screenspace in the x and y components and the (rather uninteresting) w-coordinate in the z component of the SimpleVector. All coordinates are returned as floats to allow for the higher accuracy when post-processing them. Returns null if the transformation can't be done (i.e. the vertex is behind the viewplane). Negative values are possible. The coordinates are given in backbuffer coordinates, i.e. if over- or undersampling is used, it's up to you to correct them in a way that they correspond with your framebuffer's output dimension (for example: Using 1.5 oversampling, you have to divide the returned coordinates by 1.5 to get the actual screen coordinates you want).

project3D2D

public static SimpleVector project3D2D(Camera camera,
                                       FrameBuffer buffer,
                                       SimpleVector vertex,
                                       SimpleVector toFill)
Projects a vertex from world space into screen space. This variant takes a SimpleVector to fill instead of creating a new one for each call.

Parameters:
camera - the Camera used for the projection
buffer - the Framebuffer
vertex - the vertex in world space
toFill - the SimpleVector that will be filled with the result
Returns:
a SimpleVector containing the x- and y-coordinates in screenspace in the x and y components and the (rather uninteresting) w-coordinate in the z component of the SimpleVector. All coordinates are returned as floats to allow for the higher accuracy when post-processing them. Returns null if the transformation can't be done (i.e. the vertex is behind the viewplane). Negative values are possible.

projectCenter3D2D

public static SimpleVector projectCenter3D2D(FrameBuffer buffer,
                                             Object3D obj)
Gets the center of the object in screen-coordinates (2D) by transforming and projecting it from 3D objectspace into 2D screenspace. Useful to "attach" bitmaps to objects for example. This method uses the current camera of the World the object has been assigned to. The frontbuffer matrix of the camera will be used.

Parameters:
buffer - the framebuffer the object will be (or has been) rendered into
obj - the object itself
Returns:
a SimpleVector containing the x- and y-coordinates in screenspace in the x and y components and the (rather uninteresting) w-coordinate in the z component of the SimpleVector. All coordinates are returned as floats to allow for the higher accuracy when post-processing them. Returns null if the transformation can't be done (i.e. the center is behind the viewplane). Negative values are possible. The coordinates are given in backbuffer coordinates, i.e. if over- or undersampling is used, it's up to you to correct them in a way that they correspond with your framebuffer's output dimension (for example: Using 1.5 oversampling, you have to divide the returned coordinates by 1.5 to get the actual screen coordinates you want).

projectCenter3D2D

public static SimpleVector projectCenter3D2D(Camera camera,
                                             FrameBuffer buffer,
                                             Object3D obj)
Gets the center of the object in screen-coordinates (2D) by transforming and projecting it from 3D objectspace into 2D screenspace. Useful to "attach" bitmaps to objects for example.

Parameters:
camera - the camera that represents the worldspace->cameraspace transformation. The frontbuffer matrix of the camera will be used. If the camera is null, the one from the object's World will be used instead.
buffer - the framebuffer the object will be (or has been) rendered into
obj - the object itself
Returns:
a SimpleVector containing the x- and y-coordinates in screenspace in the x and y components and the (rather uninteresting) w-coordinate in the z component of the SimpleVector. All coordinates are returned as floats to allow for the higher accuracy when post-processing them. Returns null if the transformation can't be done (i.e. the center is behind the viewplane). Negative values are possible. The coordinates are given in backbuffer coordinates, i.e. if over- or undersampling is used, it's up to you to correct them in a way that they correspond with your framebuffer's output dimension (for example: Using 1.5 oversampling, you have to divide the returned coordinates by 1.5 to get the actual screen coordinates you want).

getObjectID

public static int getObjectID(int[] res)
Gets the ID of a picked object out of the result array.

Parameters:
res - the result array of a "pick" as returned by pickPolygon()
Returns:
the ID or -1 if res is not a valid result
See Also:
pickPolygon(com.threed.jpct.VisList, com.threed.jpct.SimpleVector), pickPolygon(com.threed.jpct.VisList, com.threed.jpct.SimpleVector, com.threed.jpct.SimpleVector)

getPolygonID

public static int getPolygonID(int[] res)
Gets the ID of a picked polygon out of the result array. This ID can be used get or set some properties of this particular polygon.

Parameters:
res - the result array of a "pick" as returned by pickPolygon()
Returns:
the polygon's number or -1 if res is not a valid result
See Also:
pickPolygon(com.threed.jpct.VisList, com.threed.jpct.SimpleVector), pickPolygon(com.threed.jpct.VisList, com.threed.jpct.SimpleVector, com.threed.jpct.SimpleVector)

pickPolygon

public static int[] pickPolygon(VisList visList,
                                SimpleVector dr)
Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and lies in the given direction. The direction is usually a direction vector like reproject2D3D() returns it (to be exact, reproject2D3D() doesn't return a direction but a position vector but because this method assumes that the ray casted into the scene starts at the origin, the position vector can be seen as a direction vector).
Picking doesn't work on compiled objects.

Parameters:
visList - the visibility list
dr - the direction vector (as returned by reproject2D3D())
Returns:
an int[2]-array containing the object and polygon number or null if no polygon has been picked

pickPolygon

public static int[] pickPolygon(VisList visList,
                                SimpleVector dr,
                                int exclude)
Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and lies in the given direction. The direction is usually a direction vector like reproject2D3D() returns it (to be exact, reproject2D3D() doesn't return a direction but a position vector but because this method assumes that the ray casted into the scene starts at the origin, the position vector can be seen as a direction vector).
Picking doesn't work on compiled objects.

Parameters:
visList - the visibility list
dr - the direction vector (as returned by reproject2D3D())
exclude - a flag that indicates what to exclude from picking. 0 means no exclusion. Values can be combined by OR.
Returns:
an int[2]-array containing the object and polygon number or null if no polygon has been picked
See Also:
EXCLUDE_TRANSPARENT, EXCLUDE_NOT_SELECTABLE

pickPolygon

public static int[] pickPolygon(VisList visList,
                                SimpleVector rp1,
                                SimpleVector rp2)
Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and that is hit by the ray casted from some position vector into the scene. This method is more flexible than the alternative pickPolygon()-method but this is not required for implementing picking on the viewplane (i.e. using screen coordinates)...anyway...
Picking doesn't work on compiled objects.

Parameters:
visList - the visibility list
rp1 - the origin of the ray casted into the scene (in camera-space)
rp2 - a point within the casted ray (any point will do)
Returns:
an int[2]-array containing the object and polygon number or null if no polygon has been picked

pickPolygon

public static int[] pickPolygon(VisList visList,
                                SimpleVector rp1,
                                SimpleVector rp2,
                                int exclude)
Picks the polygon that is closest to the camera (and belongs to a "selectable" object) and that is hit by the ray casted from some position vector into the scene. This method is more flexible than the alternative pickPolygon()-method but this is not required for implementing picking on the viewplane (i.e. using screen coordinates)...anyway...
Picking doesn't work on compiled objects.

Parameters:
visList - the visibility list
rp1 - the origin of the ray casted into the scene (in camera-space)
rp2 - a point within the casted ray (any point will do)
exclude - a flag that indicates what to exclude from picking. 0 means no exclusion. Values can be combined by OR.
Returns:
an int[2]-array containing the object and polygon number or null if no polygon has been picked
See Also:
EXCLUDE_TRANSPARENT, EXCLUDE_NOT_SELECTABLE