DragContext Class Reference

The JavaScript class for converting position from one coordinate system to another. Obtain it as a parameter to the WidgetBase drag signals. More...

Public Slots

QObject dragPoint ()
 Return the picking point in world coordinates. More...
 
QObject projectToModelPlane (QObject worldPoint3d)
 Project a given point in world coordinates to the screen and then back to the model plane. More...
 
QObject transformFromWorldToModel (QObject worldPoint3d)
 Transform a given point in world coordinates to the model space. More...
 
QObject transformModelMatrix (Matrix4x4 transformationMatrix)
 Transform the camera chain model matrix. More...
 
QObject multiplyByPostMatrix (QObject modelPoint3d)
 Multiply by the matrix of transformations associated with the script widgets registered after the current one. More...
 

Detailed Description

The JavaScript class for converting position from one coordinate system to another. Obtain it as a parameter to the WidgetBase drag signals.

var drag_offset = new Vector3d;
function onDragStart(context)
{
var projectedPoint = context.projectToModelPlane(context.dragPoint());
var modelPickingPoint = context.multiplyByPostMatrix(projectedPoint);
var modelOriginPoint = scene.toOGL(Point3d(getPosX(), getPosY(), getPosZ()));
drag_offset = modelOriginPoint.minus(modelPickingPoint);
}
var drag_offsetZ = new Vector3d;
function onDragStartZ(context)
{
var planeRotation = new Matrix4x4;
planeRotation.rotateDegrees(90, Vector3d(0, 1, 0));
context.transformModelMatrix(planeRotation);
var projectedPoint = context.projectToModelPlane(context.dragPoint());
var inversePlaneRotation = new Matrix4x4;
inversePlaneRotation.rotateDegrees(-90, Vector3d(0, 1, 0));
context.transformModelMatrix(inversePlaneRotation);
var modelPickingPoint = context.multiplyByPostMatrix(planeRotation.multiply(Point3d(projectedPoint.x, projectedPoint.y, 0)));
var modelOriginPoint = scene.toOGL(Point3d(getPosX(), getPosY(), getPosZ()));
drag_offsetZ = modelOriginPoint.minus(modelPickingPoint);
}

Member Function Documentation

◆ dragPoint

QObject DragContext::dragPoint ( )
slot

Return the picking point in world coordinates.

Returns
A Point3d at the picking point in world coordinates.

◆ multiplyByPostMatrix

QObject DragContext::multiplyByPostMatrix ( QObject  modelPoint3d)
slot

Multiply by the matrix of transformations associated with the script widgets registered after the current one.

Parameters
modelPoint3dA Point3d in the context node model coordinates
Returns
The context node model Point3d multiplied by the post transformation matrix

◆ projectToModelPlane

QObject DragContext::projectToModelPlane ( QObject  worldPoint3d)
slot

Project a given point in world coordinates to the screen and then back to the model plane.

Parameters
worldPoint3dA Point3d or Point2d (Point2d will have their z at 0) in world coordinates
Returns
A Point2d that represents the given point projected on the context node model plane.

◆ transformFromWorldToModel

QObject DragContext::transformFromWorldToModel ( QObject  worldPoint3d)
slot

Transform a given point in world coordinates to the model space.

Apply the model matrix of the camera chain to the world 3d point given as a parameter.If the input is a 2d point, its z value is set to 0.

Parameters
worldPoint3dA Point2d or Point3d in world coordinates
Returns
A Point3d in the context node model coordinates. If the model is 2D, you will need to project it on the 2D plane in order to have a meaningful value.

◆ transformModelMatrix

QObject DragContext::transformModelMatrix ( Matrix4x4  transformationMatrix)
slot

Transform the camera chain model matrix.

Parameters
transformationMatrixThe Matrix4x4 to apply to the model matrix.
Returns
The new Matrix4x4 model matrix equivalent to the previous model matrix multiplied by the given matrix.