/***************************************************************
* Function: applyEditorInfo()
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyEditorInfo(CAVEGeodeShape::EditorInfo **infoPtr)
{
    /* reset root offset only when the shape is moved */
    if ((*infoPtr)->getTypeMasking() == CAVEGeodeShape::EditorInfo::MOVE)
    {
	/* apply translations on 'mAccRootMat' */
	const Vec3 offset = (*infoPtr)->getMoveOffset();

	Matrixd transMat;
	transMat.makeTranslate(offset);
	mAccRootMat = mAccRootMat * transMat;
    }
    else if ((*infoPtr)->getTypeMasking() == CAVEGeodeShape::EditorInfo::ROTATE)
    {
	/* apply rotations on 'mAccRootMat' */
	const float angle = (*infoPtr)->getRotateAngle();
	const Vec3 axis = (*infoPtr)->getRotateAxis();

	Matrixf rotateMat;
	rotateMat.makeRotate(angle, axis);
	mAccRootMat = mAccRootMat * rotateMat;
    }
    else if ((*infoPtr)->getTypeMasking() == CAVEGeodeShape::EditorInfo::SCALE)
    {
	const Vec3f scaleVect = (*infoPtr)->getScaleVect();
	const Vec3f scaleCenter = (*infoPtr)->getScaleCenter();

	Matrixd scalingMat, transMat, revTransMat;
	scalingMat.makeScale(scaleVect);
	transMat.makeTranslate(scaleCenter);
	revTransMat.makeTranslate(-scaleCenter);

	mAccRootMat = mAccRootMat * scalingMat;
    }
}
Exemplo n.º 2
0
void Quat::get(Matrixf& matrix) const
{
    matrix.makeRotate(*this);
}
Exemplo n.º 3
0
/***************************************************************
* Function: applyEditorInfo()
***************************************************************/
void CAVEGeodeShape::applyEditorInfo(Vec3Array **vertexArrayPtr, Vec3Array **normalArrayPtr, 
		Vec3Array **udirArrayPtr, Vec3Array **vdirArrayPtr, Vec2Array **texcoordArrayPtr,
		const Vec3Array *refVertexArrayPtr, const Vec3Array *refNormalArrayPtr, 
		const Vec3Array *refUDirArrayPtr, const Vec3Array *refVDirArrayPtr, const Vec2Array *refTexcoordArrayPtr,
		const int &nVerts, EditorInfo **infoPtr, const VertexMaskingVector &vertMaskingVector)
{
    /* access target and source data pointers */
    Vec3 *geodeVertexDataPtr, *geodeNormalDataPtr, *geodeUDirDataPtr, *geodeVDirDataPtr;
    Vec2 *geodeTexcoordDataPtr;
    const Vec3 *refGeodeVertexDataPtr, *refGeodeNormalDataPtr, *refGeodeUDirDataPtr, *refGeodeVDirDataPtr;
    const Vec2 *refGeodeTexcoordDataPtr;

    geodeVertexDataPtr = (Vec3*) ((*vertexArrayPtr)->getDataPointer());
    geodeNormalDataPtr = (Vec3*) ((*normalArrayPtr)->getDataPointer());
    geodeUDirDataPtr = (Vec3*) ((*udirArrayPtr)->getDataPointer());
    geodeVDirDataPtr = (Vec3*) ((*vdirArrayPtr)->getDataPointer());
    geodeTexcoordDataPtr = (Vec2*) ((*texcoordArrayPtr)->getDataPointer());

    refGeodeVertexDataPtr = (const Vec3*) (refVertexArrayPtr->getDataPointer());
    refGeodeNormalDataPtr = (const Vec3*) (refNormalArrayPtr->getDataPointer());
    refGeodeUDirDataPtr =  (const Vec3*) (refUDirArrayPtr->getDataPointer());
    refGeodeVDirDataPtr =  (const Vec3*) (refVDirArrayPtr->getDataPointer());
    refGeodeTexcoordDataPtr = (const Vec2*) (refTexcoordArrayPtr->getDataPointer());

    /* implement vertex & normal updates with respect to all ActiveTypeMasking
       texture coordinates are only changed in 'MOVE' and 'SCALE' operations,
       texture directional vectors are only changed in 'ROTATE' operations. 
    */
    if ((*infoPtr)->getTypeMasking() == EditorInfo::MOVE)
    {
	const Vec3 offset = (*infoPtr)->getMoveOffset();
	for (int i = 0; i < nVerts; i++)
	{
	    if (vertMaskingVector[i])
	    {
		/* apply offset values to vetex data vector */
		geodeVertexDataPtr[i] = refGeodeVertexDataPtr[i] + offset;

		/* apply offset values to texture coordinates, normal is not changed */
		Vec3 udir = refGeodeUDirDataPtr[i];
		Vec3 vdir = refGeodeVDirDataPtr[i];
		Vec2 texoffset = Vec2(udir * offset, vdir * offset) / gTextureTileSize;
		geodeTexcoordDataPtr[i] = refGeodeTexcoordDataPtr[i] + texoffset;
	    }
	}
    }
    else if ((*infoPtr)->getTypeMasking() == EditorInfo::ROTATE)
    {
	const Vec3 center = (*infoPtr)->getRotateCenter();
	const Vec3 axis = (*infoPtr)->getRotateAxis();
	const float angle = (*infoPtr)->getRotateAngle();

	Matrixf rotMat;
	rotMat.makeRotate(angle, axis);

	for (int i = 0; i < nVerts; i++)
	{
	    if (vertMaskingVector[i])
	    {
		/* update vertex list: 'translation' -> 'rotation' -> 'reversed translation' */
		Vec3 pos = refGeodeVertexDataPtr[i];
		geodeVertexDataPtr[i] = (pos - center) * rotMat + center;

		/* update normal and u, v-direction vectors with single rotations */
		Vec3 norm = refGeodeNormalDataPtr[i];
		Vec3 udir = refGeodeUDirDataPtr[i];
		Vec3 vdir = refGeodeVDirDataPtr[i];
		geodeNormalDataPtr[i] = norm * rotMat;
		geodeUDirDataPtr[i] = udir * rotMat;
		geodeVDirDataPtr[i] = vdir * rotMat;
	    }
	}
    }
    else if ((*infoPtr)->getTypeMasking() == EditorInfo::SCALE)
    {
	const Vec3 center = (*infoPtr)->getScaleCenter();
	const Vec3 scale = (*infoPtr)->getScaleVect();

	Matrixf scaleMat;
	scaleMat.makeScale(scale);

	for (int i = 0; i < nVerts; i++)
	{
	    if (vertMaskingVector[i])
	    {
		/* update vertex list: 'translation' -> 'scaling' -> 'reversed translation' */
		Vec3 pos = refGeodeVertexDataPtr[i];
		geodeVertexDataPtr[i] = (pos - center) * scaleMat + center;
		Vec3 offset = geodeVertexDataPtr[i] - pos;

		/* update texture coordinates 'u', 'v', normal and u, v-direction vectors are not changed  */
		Vec3 udir = refGeodeUDirDataPtr[i];
		Vec3 vdir = refGeodeVDirDataPtr[i];
		Vec2 texoffset = Vec2(udir * offset, vdir * offset) / gTextureTileSize;
		geodeTexcoordDataPtr[i] = refGeodeTexcoordDataPtr[i] + texoffset;
	    }
	}
    }
    else return;
}