org::scilab::modules::renderer::utils::CoordinateTransformation Class Reference

Collaboration diagram for org::scilab::modules::renderer::utils::CoordinateTransformation:

Collaboration graph
[legend]

Public Member Functions

 CoordinateTransformation ()
void set2dMode (boolean is2d)
Matrix4D getCompleteProjectionMatrix ()
Matrix4D getModelViewMatrix ()
Matrix4D getUnprojectMatrix ()
double[] getViewPort ()
void setAdditionalTranslation (Vector3D trans)
Vector3D getAdditionalTranslation ()
Vector3D getAdditionalTranslationPix (GL gl)
void update (GL gl)
Vector3D getCanvasCoordinates (GL gl, Vector3D pos)
Vector3D project (GL gl, Vector3D pos)
Vector3D unProject (GL gl, Vector3D canvasPos)
Vector3D[] getCanvasCoordinates (GL gl, Vector3D[] positions)
Vector3D getCanvasDirection (GL gl, Vector3D direction)
Vector3D retrieveSceneCoordinates (GL gl, Vector3D canvasPos)
Vector3D getCanvasCoordinates3D (GL gl, Vector3D dir)
Vector3D retrieveSceneCoordinates3D (GL gl, Vector3D canvasDir)
String toString ()
void setDepthRange (double zNear, double zFar)
void drawFront (GL gl)
void drawBack (GL gl)
void drawMiddle (GL gl)
void pushPolygonsBack (GL gl, FillDrawerGL drawer)
void endPushPolygonsBack (GL gl, FillDrawerGL drawer)
void pushPolygonsBack (GL gl)
void endPushPolygonsBack (GL gl)

Static Public Attributes

static final int MATRIX_4X4_SIZE = 16
static final int VIEW_PORT_SIZE = 4

Private Member Functions

double getFrontEndDepth ()
double getBackStartDepth ()

Private Attributes

Matrix4D projectionMatrix
Matrix4D modelViewMatrix
Matrix4D completeProjectMatrix
Matrix4D unprojectMatrix
double[] viewPort
Vector3D additionalTranslation
Vector3D additionalTranslationPix
double zNear
double zFar
boolean is2dMode

Static Private Attributes

static final double START_BACK_DEPTH = 0.95
static final double END_FRONT_DEPTH = 0.05

Detailed Description

Class containing functions to switch between user and window coordinates. This is a singleton class.
Author:
Jean-Baptiste Silvy

Definition at line 30 of file CoordinateTransformation.java.


Constructor & Destructor Documentation

org::scilab::modules::renderer::utils::CoordinateTransformation::CoordinateTransformation (  )  [inline]

default constructor

Definition at line 61 of file CoordinateTransformation.java.

References additionalTranslation, additionalTranslationPix, completeProjectMatrix, is2dMode, modelViewMatrix, projectionMatrix, unprojectMatrix, VIEW_PORT_SIZE, viewPort, zFar, and zNear.

00061                                           {
00062                 completeProjectMatrix = null;
00063                 unprojectMatrix = null;
00064                 projectionMatrix = new Matrix4D();
00065                 modelViewMatrix = new Matrix4D();
00066                 viewPort = new double[VIEW_PORT_SIZE];
00067                 additionalTranslation = null;
00068                 additionalTranslationPix = null;
00069                 zNear = 0.0;
00070                 zFar = 1.0;
00071                 is2dMode = false;
00072         }


Member Function Documentation

void org::scilab::modules::renderer::utils::CoordinateTransformation::set2dMode ( boolean  is2d  )  [inline]

Parameters:
is2d specify if the drawing is 2d or not

Definition at line 78 of file CoordinateTransformation.java.

Referenced by org::scilab::modules::renderer::subwinDrawing::DrawableSubwinGL::setIs2d().

00078                                             {
00079                 this.is2dMode = is2d;
00080         }

Here is the caller graph for this function:

Matrix4D org::scilab::modules::renderer::utils::CoordinateTransformation::getCompleteProjectionMatrix (  )  [inline]

Returns:
current projection matrix

Definition at line 85 of file CoordinateTransformation.java.

References completeProjectMatrix.

Referenced by org::scilab::modules::renderer::subwinDrawing::CameraGL::placeCamera().

00085                                                       {
00086                 return completeProjectMatrix;
00087         }

Here is the caller graph for this function:

Matrix4D org::scilab::modules::renderer::utils::CoordinateTransformation::getModelViewMatrix (  )  [inline]

Returns:
current model view matrix

Definition at line 92 of file CoordinateTransformation.java.

References modelViewMatrix.

00092                                              {
00093                 return modelViewMatrix;
00094         }

Matrix4D org::scilab::modules::renderer::utils::CoordinateTransformation::getUnprojectMatrix (  )  [inline]

Returns:
current inverse of projection matrix

Definition at line 99 of file CoordinateTransformation.java.

References unprojectMatrix.

Referenced by org::scilab::modules::renderer::subwinDrawing::CameraGL::placeCamera().

00099                                              {
00100                 return unprojectMatrix;
00101         }

Here is the caller graph for this function:

double [] org::scilab::modules::renderer::utils::CoordinateTransformation::getViewPort (  )  [inline]

Returns:
current viewPort

Definition at line 106 of file CoordinateTransformation.java.

References viewPort.

Referenced by org::scilab::modules::renderer::subwinDrawing::CameraGL::getViewPort(), and org::scilab::modules::renderer::utils::glTools::GLTools::usePixelCoordinates().

00106                                       {
00107                 return viewPort;
00108         }

Here is the caller graph for this function:

void org::scilab::modules::renderer::utils::CoordinateTransformation::setAdditionalTranslation ( Vector3D  trans  )  [inline]

Parameters:
trans translation to apply

Definition at line 113 of file CoordinateTransformation.java.

Referenced by org::scilab::modules::renderer::DrawableObjectGL::endTranslate(), and org::scilab::modules::renderer::DrawableObjectGL::translate().

00113                                                              {
00114                 this.additionalTranslation = trans;
00115                 this.additionalTranslationPix = null; // not up to date
00116                 
00117         }

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::getAdditionalTranslation (  )  [inline]

Returns:
additional translation

Definition at line 122 of file CoordinateTransformation.java.

References additionalTranslation.

Referenced by org::scilab::modules::renderer::utils::glTools::GLTools::endPixelCoordinates().

00122                                                    {
00123                 return additionalTranslation;
00124         }

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::getAdditionalTranslationPix ( GL  gl  )  [inline]

Parameters:
gl current OpenGL pipeline
Returns:
additional translation

Definition at line 130 of file CoordinateTransformation.java.

References additionalTranslation, additionalTranslationPix, and getCanvasDirection().

Referenced by org::scilab::modules::renderer::utils::glTools::GLTools::usePixelCoordinates().

00130                                                            {
00131                 if (additionalTranslation == null) {
00132                         return null;
00133                 } else if (additionalTranslationPix == null) {
00134                         additionalTranslationPix = getCanvasDirection(gl, additionalTranslation);
00135                         return additionalTranslationPix;
00136                 } else {
00137                         return additionalTranslationPix;
00138                 }
00139         }

Here is the call graph for this function:

Here is the caller graph for this function:

void org::scilab::modules::renderer::utils::CoordinateTransformation::update ( GL  gl  )  [inline]

Update the projection data of the coordinates.

Parameters:
gl current Gl pipeline

Definition at line 145 of file CoordinateTransformation.java.

References completeProjectMatrix, org::scilab::modules::renderer::utils::geom3D::Matrix4D::getInverse(), MATRIX_4X4_SIZE, modelViewMatrix, org::scilab::modules::renderer::utils::geom3D::Matrix4D::mult(), projectionMatrix, org::scilab::modules::renderer::utils::geom3D::Matrix4D::setFromOpenGLRepresentation(), unprojectMatrix, and viewPort.

Referenced by org::scilab::modules::renderer::subwinDrawing::CameraGL::backTo3DCoordinates(), org::scilab::modules::renderer::utils::glTools::UnitaryCubeGL::getCubeScreenExtent(), org::scilab::modules::renderer::subwinDrawing::CameraGL::showCamera(), and org::scilab::modules::renderer::subwinDrawing::CameraGL::switchTo2DCoordinates().

00145                                   {
00146                 // get OpenGL transformation matrices
00147                 double[] oglModelViewMatrix = new double[MATRIX_4X4_SIZE];
00148                 double[] oglProjectionMatrix = new double[MATRIX_4X4_SIZE];
00149                 gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, oglModelViewMatrix, 0);
00150                 gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, oglProjectionMatrix, 0);
00151                 gl.glGetDoublev(GL.GL_VIEWPORT, viewPort, 0);
00152                 // force values to 0 to be compatible when
00153                 // OpenGL pipeline is enable. The viewport position
00154                 // is modified. See http://www.javagaming.org/forums/index.php?topic=16414.0.
00155                 viewPort[0] = 0;
00156                 viewPort[1] = 0;
00157                 
00158                 // projection (without viewport is done by v' = P.M.v
00159                 // where v' is the canvas coordinates and v scene coordinates
00160                 projectionMatrix.setFromOpenGLRepresentation(oglProjectionMatrix);
00161                 modelViewMatrix.setFromOpenGLRepresentation(oglModelViewMatrix);
00162                 completeProjectMatrix = projectionMatrix.mult(modelViewMatrix);
00163                 
00164                 // unproject is done by v = (P.M)^-1.v'
00165                 unprojectMatrix = completeProjectMatrix.getInverse();
00166         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::getCanvasCoordinates ( GL  gl,
Vector3D  pos 
) [inline]

Get the coordinate of a 3D position in a canvas frame from its user coordinates.

Parameters:
gl current OpenGL pipeline
pos coordinates of the position.
Returns:
Vector the X, Y and Z positions in the canvas frame.

Definition at line 174 of file CoordinateTransformation.java.

References project().

Referenced by org::scilab::modules::renderer::textDrawing::TextContentDrawerGL::drawTextContent3D(), org::scilab::modules::renderer::subwinDrawing::TicksDrawerGL::drawTicks(), org::scilab::modules::renderer::textDrawing::TextContentDrawerGL::getBoundingRectangle2D(), getCanvasCoordinates(), getCanvasDirection(), org::scilab::modules::renderer::utils::glTools::UnitaryCubeGL::getCubeScreenExtent(), org::scilab::modules::renderer::utils::glTools::MovableClipPlane3D::pushPlane(), org::scilab::modules::renderer::drawers::ArrowHeadDrawerGL::redrawArrowHeads(), org::scilab::modules::renderer::drawers::MarkDrawerGL::redrawMarks(), and org::scilab::modules::renderer::drawers::ArrowHeadDrawerGL::setAxesBounds().

00174                                                                   {
00175                 // I first used gluProject, but it is slower since it will always perform matrices multiplications and inverse.
00176                 //return projectMatrix.mult(pos);
00177                 return project(gl, pos);
00178         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::project ( GL  gl,
Vector3D  pos 
) [inline]

Perform the same operation as gluProject.

Parameters:
gl unused
pos scene position
Returns:
pixel coordinate of the point.

Definition at line 186 of file CoordinateTransformation.java.

References completeProjectMatrix, org::scilab::modules::renderer::utils::geom3D::Vector3D::getX(), org::scilab::modules::renderer::utils::geom3D::Vector3D::getY(), org::scilab::modules::renderer::utils::geom3D::Vector3D::getZ(), org::scilab::modules::renderer::utils::geom3D::Matrix4D::mult(), org::scilab::modules::renderer::utils::geom3D::Vector3D::setX(), org::scilab::modules::renderer::utils::geom3D::Vector3D::setY(), org::scilab::modules::renderer::utils::geom3D::Vector3D::setZ(), VIEW_PORT_SIZE, and viewPort.

Referenced by getCanvasCoordinates().

00186                                                      {
00187                 Vector3D canvasCoord = completeProjectMatrix.mult(pos);
00188                 canvasCoord.setX(viewPort[0] + viewPort[2] * (canvasCoord.getX() + 1.0) / 2.0);
00189                 canvasCoord.setY(viewPort[1] + viewPort[VIEW_PORT_SIZE - 1] * (canvasCoord.getY() + 1.0) / 2.0);
00190                 canvasCoord.setZ((canvasCoord.getZ() + 1.0) / 2.0);
00191                 return canvasCoord;
00192         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::unProject ( GL  gl,
Vector3D  canvasPos 
) [inline]

Perform the same operation as gluUnproject.

Parameters:
gl unused
canvasPos canvas position
Returns:
scene coordinate of the point

Definition at line 200 of file CoordinateTransformation.java.

References org::scilab::modules::renderer::utils::geom3D::Vector3D::getX(), org::scilab::modules::renderer::utils::geom3D::Vector3D::getY(), org::scilab::modules::renderer::utils::geom3D::Vector3D::getZ(), org::scilab::modules::renderer::utils::geom3D::Matrix4D::mult(), unprojectMatrix, VIEW_PORT_SIZE, and viewPort.

Referenced by retrieveSceneCoordinates().

00200                                                              {
00201                 Vector3D sceneCoord 
00202                         = new Vector3D(2.0 * (canvasPos.getX() - viewPort[0]) / viewPort[2] - 1.0,
00203                                                    2.0 * (canvasPos.getY() - viewPort[1]) / viewPort[VIEW_PORT_SIZE - 1] - 1.0,
00204                                                    2.0 * canvasPos.getZ() - 1.0);
00205                 return unprojectMatrix.mult(sceneCoord);
00206                 
00207         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D [] org::scilab::modules::renderer::utils::CoordinateTransformation::getCanvasCoordinates ( GL  gl,
Vector3D[]  positions 
) [inline]

Convert several user coordinates to the canvas one

Parameters:
gl current OpenGL pipeline
positions coordinates of the different position (size n x 3).
Returns:
array of size n x 3 containing the X, Y and Z positions in the canvas frame corresponding to each

Definition at line 216 of file CoordinateTransformation.java.

References getCanvasCoordinates(), and i.

00216                                                                             {
00217                 int nbCoords = positions.length;
00218                 Vector3D[] canvasCoords = new Vector3D[nbCoords];
00219                 
00220                 for (int i = 0; i < nbCoords; i++) {
00221                         canvasCoords[i] = getCanvasCoordinates(gl, positions[i]);
00222                 }
00223                 return canvasCoords;
00224         }

Here is the call graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::getCanvasDirection ( GL  gl,
Vector3D  direction 
) [inline]

Convert a direction in pixels

Parameters:
gl current GL pipeline
direction direction to transform
Returns:
direcyion in pixels

Definition at line 232 of file CoordinateTransformation.java.

References getCanvasCoordinates(), res, and org::scilab::modules::renderer::utils::geom3D::Vector3D::substract().

Referenced by getAdditionalTranslationPix().

00232                                                                       {
00233                 Vector3D originPix = getCanvasCoordinates(gl, Vector3D.ORIGIN);
00234                 Vector3D res = getCanvasCoordinates(gl, direction);
00235                 return res.substract(originPix);
00236         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::retrieveSceneCoordinates ( GL  gl,
Vector3D  canvasPos 
) [inline]

Opposite transformation od getCanvasCoordinates. Compute back scene coordinates from window coordinates.

Parameters:
gl current OpengL pipeline
canvasPos coordinates of the point in the canvas frame
Returns:
coodinates in object frame

Definition at line 245 of file CoordinateTransformation.java.

References unProject().

Referenced by org::scilab::modules::renderer::subwinDrawing::TicksDrawerGL::drawLabels(), and org::scilab::modules::renderer::textDrawing::TextContentDrawerGL::drawTextContent3D().

00245                                                                             {
00246                 // I first used gluUnproject, but it is slower since it will always perform matrices multiplications and inverse.
00247                 
00248                 //return unprojectMatrix.mult(canvasPos);
00249                 return unProject(gl, canvasPos);
00250         }

Here is the call graph for this function:

Here is the caller graph for this function:

Vector3D org::scilab::modules::renderer::utils::CoordinateTransformation::getCanvasCoordinates3D ( GL  gl,
Vector3D  dir 
) [inline]

Transform a direction v