Esempio n. 1
0
void FPSCamera::LoadMatrix() const
{
	// load identity matrix
	glLoadIdentity();

	MultMatrix();
}
void DrawJSONMesh(PP_Resource context,
                  PPB_OpenGLES2* gl,
                  Transformations* psMatrices,
                  int iNumVertices,
                  int iNumIndices,
                  GLuint uiVBO,
                  GLuint uiIBO)
{
    float afTransform[4][4];//The final matrix
    float modelview[4][4];

    gl->UseProgram(context, psDemoContext->hDisplacementMapShader);

    Identity(afTransform);

    Identity(modelview);
    MultMatrix(modelview, psMatrices->rot, psMatrices->camera);
    MultMatrix(modelview, psMatrices->scale, modelview);
    MultMatrix(modelview, psMatrices->xform, modelview);
    MultMatrix(afTransform,  modelview, psMatrices->projection);


    gl->UniformMatrix4fv(context, gl->GetUniformLocation(context, psDemoContext->hDisplacementMapShader, "Transform"), 1, GL_FALSE, (float*)&afTransform[0][0]);
    gl->Uniform1i(context, gl->GetUniformLocation(context, psDemoContext->hDisplacementMapShader, "TextureBase"), 0);

    gl->Uniform1i(context, gl->GetUniformLocation(context, psDemoContext->hDisplacementMapShader, "DispMap"), 1);

    gl->Uniform1f(context, gl->GetUniformLocation(context, psDemoContext->hDisplacementMapShader, "DISPLACEMENT_COEFFICIENT"), psDemoContext->fDispCoeff);

    gl->ActiveTexture(context, GL_TEXTURE0+1);
    gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sDisplacementMap.hTextureGL);
    gl->ActiveTexture(context, GL_TEXTURE0);
    gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sBaseMap.hTextureGL);

    gl->BindBuffer(context, GL_ARRAY_BUFFER, uiVBO);
    gl->BindBuffer(context, GL_ELEMENT_ARRAY_BUFFER, uiIBO);

    gl->EnableVertexAttribArray(context, VA_POSITION_INDEX);
    gl->EnableVertexAttribArray(context, VA_TEXCOORD_INDEX);
    gl->EnableVertexAttribArray(context, VA_NORMAL_INDEX);

    gl->VertexAttribPointer(context, VA_POSITION_INDEX, 3, GL_FLOAT, GL_FALSE, 0, 0);
    gl->VertexAttribPointer(context, VA_TEXCOORD_INDEX, 3, GL_FLOAT, GL_FALSE, 0, (char*)(sizeof(GLfloat)*(iNumVertices*3)));
    gl->VertexAttribPointer(context, VA_NORMAL_INDEX, 3, GL_FLOAT, GL_FALSE, 0, (char*)(sizeof(GLfloat)*(iNumVertices*6)));

    gl->DrawElements(context, GL_TRIANGLES, iNumIndices, GL_UNSIGNED_SHORT, 0);
}
Esempio n. 3
0
	void MatrixStack::Scale(float x, float y, float z)
	{
		MultMatrix(Matrix4Df
			(x,	   0.0f, 0.0f, 0.0f,
			 0.0f, y,	 0.0f, 0.0f,
			 0.0f, 0.0f, z,	   0.0f,
			 0.0f, 0.0f, 0.0f, 1.0f));
	}
Esempio n. 4
0
void nuiDrawContext::Translate(nuiSize X, nuiSize Y, nuiSize Z)
{
  if (X == 0 && Y == 0 && Z == 0)
    return;
  
  nuiMatrix m;
  m.SetTranslation(X, Y, Z);
  MultMatrix(m);
}
Esempio n. 5
0
void nuiDrawContext::Scale(nuiSize X, nuiSize Y, nuiSize Z)
{
  if (X == 1.0 && Y == 1.0 && Z == 1.0)
    return;
  
  nuiMatrix m;
  m.SetScaling(X, Y, Z);
  MultMatrix(m);
}
Esempio n. 6
0
void main(){
	//0,0不能为0
	TriSeqMatrix M,N,Q;
	CreateMatrix(&M);
	PrintMatrix(M);
	CreateMatrix(&N);
	PrintMatrix(N);
	printf("矩阵M和N的乘积为:\n");
	MultMatrix(M,N,&Q);
	PrintMatrix(Q);
	system("pause");
}
Esempio n. 7
0
void SGCanvasMouseHandler::LoadMatrix() const
{
    glLoadIdentity();

    if (canvas->GetFrame()->IsChecked(Id::ViewPerspective))
    {
        glTranslatef(0.0f, 0.0f, SGCanvas::CameraZ - 1.0f);
    }
    else
    {
        glTranslatef(0.0f, 0.0f, SGCanvas::CameraZ);
    }

    glRotatef(20.0f, 1.0f, 0.0f, 0.0f);
    MultMatrix();
}
Esempio n. 8
0
/*------------------------------------------------*/
int main(int argc,int** argv)
{
    int i,j,k,l;
    int length,width;
    float tau_L;
    float tau_H;
    float p_H;
    float sigma;
	
    /* Entrer des valeurs */
    printf("Entrez la valeur de tau_L: ");
    scanf("%f",&tau_L);
    printf("Entrez la valeur de tau_H: ");
    scanf("%f",&tau_H);
    printf("Entrez l'ecart type du filter Gaussien: ");
    scanf("%f",&sigma);
  
    // Chargement de l'image
    float** MatriceImgR=LoadImagePgm(NAME_IMG_IN,&length,&width);
    float** MatriceImgI=fmatrix_allocate_2d(length,width);
    float** gaussMaskI=fmatrix_allocate_2d(length,width);

    // Initialisation a zero de la partie imaginaire
    for(i=0;i<length;i++) 
    {
        for(j=0;j<width;j++) 
        {
	        MatriceImgI[i][j]=0.0;
	        gaussMaskI[i][j]=0.0;
        }
    }

    /* Implementer detecteur de Canny */
    int halfMaskWidth = 16;
    int maskSize = halfMaskWidth*2 + 1;

    ////////////////////////////////////////////
    // Etape 1: application d'un filtre Gaussien
    //
    float** mask = gaussianMask(halfMaskWidth, sigma);
    float** gaussMaskR = padWithZeros(mask, maskSize, maskSize, length, width);

    // Convolution
    float** convR = fmatrix_allocate_2d(length,width);
    float** convI = fmatrix_allocate_2d(length,width);
    FFTDD(MatriceImgR,MatriceImgI,length,width);
    FFTDD(gaussMaskR,gaussMaskI,length,width);
    MultMatrix(convR,convI,MatriceImgR,MatriceImgI,gaussMaskR,gaussMaskI,length,width);
    IFFTDD(convR,convI,length,width);

    // Sauvegarde de l'image filtree
    SaveImagePgm(NAME_IMG_CANNY,convR,length,width);

    /////////////////////////////////////////////
    // Etape 2: calcul du gradient a chaque pixel
    //
    float** gradientX = fmatrix_allocate_2d(length,width);
    float** gradientY = fmatrix_allocate_2d(length,width);
    float** gradientMagn = fmatrix_allocate_2d(length,width);
    float** gradientAngles = fmatrix_allocate_2d(length,width);
    float** contourAngles = fmatrix_allocate_2d(length,width);

    gradient(convR, gradientX, gradientY, length, width);
    gradientMagnitude(gradientX, gradientY, gradientMagn, length, width);
    gradientAngle(gradientX, gradientY, gradientAngles, contourAngles, length, width);

    // Sauvegarde de l'image du gradient
    SaveImagePgm(NAME_IMG_GRADIENT,gradientMagn,length,width);

    // Suppression des non-maximums
    deleteNonMaximums(gradientMagn,contourAngles,length,width);

    // Sauvegarde de l'image des non-maximum supprimes
    SaveImagePgm(NAME_IMG_SUPPRESSION,gradientMagn,length,width);

  /* Sauvegarder les images 
     TpIFT6150-2-gradient.pgm
     TpIFT6150-2-suppression.pgm
     TpIFT6150-2-canny.pgm */

    printf("Entrez la valeur de p_H: ");
    scanf("%f",&p_H);
 
   /* Implementer detecteur de Canny semi-automatique */
  
   /* Sauvegarder l'image TpIFT6150-2-cannySemiAuto.pgm */
   
   /*retour sans probleme*/  
 
  printf("\n C'est fini ... \n\n\n");
  return 0; 	 
}
Esempio n. 9
0
void MultMatrix2(float m0[4][4], float m1[4][4])
{
    float dst[4][4];
    MultMatrix(m0, m1, dst);
    memcpy( m0, dst, sizeof(float) * 16 );
}
Esempio n. 10
0
	void MatrixStack::Translate(float x, float y, float z)
	{
		MultMatrix(Matrix4Df(x, y, z));
	}
Esempio n. 11
0
void LoadMeshDataFromDisk( const char* fileName,  SlabSubsection_Stack* allocater, MeshGeometryData* storage, Armature* armature ) {
	tinyxml2::XMLDocument colladaDoc;
	colladaDoc.LoadFile( fileName );
	//if( colladaDoc == NULL ) {
		//printf( "Could not load mesh: %s\n", fileName );
		//return;
	//}

	tinyxml2::XMLElement* meshNode = colladaDoc.FirstChildElement( "COLLADA" )->FirstChildElement( "library_geometries" )
	->FirstChildElement( "geometry" )->FirstChildElement( "mesh" );

	char* colladaTextBuffer = NULL;
	size_t textBufferLen = 0;

	uint16 vCount = 0;
	uint16 nCount = 0;
	uint16 uvCount = 0;
	uint16 indexCount = 0;
	float* rawColladaVertexData;
	float* rawColladaNormalData;
	float* rawColladaUVData;
	float* rawIndexData;
	///Basic Mesh Geometry Data
	{
		tinyxml2::XMLNode* colladaVertexArray = meshNode->FirstChildElement( "source" );
		tinyxml2::XMLElement* vertexFloatArray = colladaVertexArray->FirstChildElement( "float_array" );
		tinyxml2::XMLNode* colladaNormalArray = colladaVertexArray->NextSibling();
		tinyxml2::XMLElement* normalFloatArray = colladaNormalArray->FirstChildElement( "float_array" );
		tinyxml2::XMLNode* colladaUVMapArray = colladaNormalArray->NextSibling();
		tinyxml2::XMLElement* uvMapFloatArray = colladaUVMapArray->FirstChildElement( "float_array" );
		tinyxml2::XMLElement* meshSrc = meshNode->FirstChildElement( "polylist" );
		tinyxml2::XMLElement* colladaIndexArray = meshSrc->FirstChildElement( "p" );

		int count;
		const char* colladaVertArrayVal = vertexFloatArray->FirstChild()->Value();
		vertexFloatArray->QueryAttribute( "count", &count );
		vCount = count;
		const char* colladaNormArrayVal = normalFloatArray->FirstChild()->Value();
		normalFloatArray->QueryAttribute( "count", &count );
		nCount = count;
		const char* colladaUVMapArrayVal = uvMapFloatArray->FirstChild()->Value();
		uvMapFloatArray->QueryAttribute( "count", &count );
		uvCount = count;
		const char* colladaIndexArrayVal = colladaIndexArray->FirstChild()->Value();
		meshSrc->QueryAttribute( "count", &count );
		//Assume this is already triangulated
		indexCount = count * 3 * 3;

		///TODO: replace this with fmaxf?
		std::function< size_t (size_t, size_t) > sizeComparison = []( size_t size1, size_t size2 ) -> size_t {
			if( size1 >= size2 ) return size1;
			return size2;
		};

		textBufferLen = strlen( colladaVertArrayVal );
		textBufferLen = sizeComparison( strlen( colladaNormArrayVal ), textBufferLen );
		textBufferLen = sizeComparison( strlen( colladaUVMapArrayVal ), textBufferLen );
		textBufferLen = sizeComparison( strlen( colladaIndexArrayVal ), textBufferLen );
		colladaTextBuffer = (char*)alloca( textBufferLen );
		memset( colladaTextBuffer, 0, textBufferLen );
		rawColladaVertexData = (float*)alloca( sizeof(float) * vCount );
		rawColladaNormalData = (float*)alloca( sizeof(float) * nCount );
		rawColladaUVData = (float*)alloca( sizeof(float) * uvCount );
		rawIndexData = (float*)alloca( sizeof(float) * indexCount );

		memset( rawColladaVertexData, 0, sizeof(float) * vCount );
		memset( rawColladaNormalData, 0, sizeof(float) * nCount );
		memset( rawColladaUVData, 0, sizeof(float) * uvCount );
		memset( rawIndexData, 0, sizeof(float) * indexCount );

		//Reading Vertex position data
		strcpy( colladaTextBuffer, colladaVertArrayVal );
		TextToNumberConversion( colladaTextBuffer, rawColladaVertexData );

	    //Reading Normals data
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, colladaNormArrayVal );
		TextToNumberConversion( colladaTextBuffer, rawColladaNormalData );

	    //Reading UV map data
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, colladaUVMapArrayVal );
		TextToNumberConversion( colladaTextBuffer, rawColladaUVData );

	    //Reading index data
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, colladaIndexArrayVal );
		TextToNumberConversion( colladaTextBuffer, rawIndexData );
	}

	float* rawBoneWeightData = NULL;
	float* rawBoneIndexData = NULL;
	//Skinning Data
	{
		tinyxml2::XMLElement* libControllers = colladaDoc.FirstChildElement( "COLLADA" )->FirstChildElement( "library_controllers" );
		if( libControllers == NULL ) goto skinningExit;
		tinyxml2::XMLElement* controllerElement = libControllers->FirstChildElement( "controller" );
		if( controllerElement == NULL ) goto skinningExit;

		tinyxml2::XMLNode* vertexWeightDataArray = controllerElement->FirstChild()->FirstChild()->NextSibling()->NextSibling()->NextSibling();
		tinyxml2::XMLNode* vertexBoneIndexDataArray = vertexWeightDataArray->NextSibling()->NextSibling();
		tinyxml2::XMLNode* vCountArray = vertexBoneIndexDataArray->FirstChildElement( "vcount" );
		tinyxml2::XMLNode* vArray = vertexBoneIndexDataArray->FirstChildElement( "v" );
		const char* boneWeightsData = vertexWeightDataArray->FirstChild()->FirstChild()->Value();
		const char* vCountArrayData = vCountArray->FirstChild()->Value();
		const char* vArrayData = vArray->FirstChild()->Value();

		float* colladaBoneWeightData = NULL;
		float* colladaBoneIndexData = NULL;
		float* colladaBoneInfluenceCounts = NULL;
		///This is overkill, Collada stores ways less data usually, plus this still doesn't account for very complex models 
		///(e.g, lots of verts with more than MAXBONESPERVERT influencing position )
		colladaBoneWeightData = (float*)alloca( sizeof(float) * MAXBONESPERVERT * vCount );
		colladaBoneIndexData = (float*)alloca( sizeof(float) * MAXBONESPERVERT * vCount );
		colladaBoneInfluenceCounts = (float*)alloca( sizeof(float) * MAXBONESPERVERT * vCount );

		//Read bone weights data
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, boneWeightsData );
		TextToNumberConversion( colladaTextBuffer, colladaBoneWeightData );

		//Read bone index data
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, vArrayData );
		TextToNumberConversion( colladaTextBuffer, colladaBoneIndexData );

		//Read bone influence counts
		memset( colladaTextBuffer, 0, textBufferLen );
		strcpy( colladaTextBuffer, vCountArrayData );
		TextToNumberConversion( colladaTextBuffer, colladaBoneInfluenceCounts );

		rawBoneWeightData = (float*)alloca( sizeof(float) * MAXBONESPERVERT * vCount );
		rawBoneIndexData = (float*)alloca( sizeof(float) * MAXBONESPERVERT * vCount );
		memset( rawBoneWeightData, 0, sizeof(float) * MAXBONESPERVERT * vCount );
		memset( rawBoneIndexData, 0, sizeof(float) * MAXBONESPERVERT * vCount );

		int colladaIndexIndirection = 0;
		int verticiesInfluenced = 0;
		vCountArray->Parent()->ToElement()->QueryAttribute( "count", &verticiesInfluenced );
		for( uint16 i = 0; i < verticiesInfluenced; i++ ) {
			uint8 influenceCount = colladaBoneInfluenceCounts[i];
			for( uint16 j = 0; j < influenceCount; j++ ) {
				uint16 boneIndex = colladaBoneIndexData[ colladaIndexIndirection++ ];
				uint16 weightIndex = colladaBoneIndexData[ colladaIndexIndirection++ ];
				rawBoneWeightData[ i * MAXBONESPERVERT + j ] = colladaBoneWeightData[ weightIndex ];
				rawBoneIndexData[ i * MAXBONESPERVERT + j ] = boneIndex;
			}
		}
	}
	skinningExit:

	//Armature
	if( armature != NULL ) {
		tinyxml2::XMLElement* visualScenesNode = colladaDoc.FirstChildElement( "COLLADA" )->FirstChildElement( "library_visual_scenes" )
		->FirstChildElement( "visual_scene" )->FirstChildElement( "node" );
		tinyxml2::XMLElement* armatureNode = NULL;

		//Step through scene heirarchy until start of armature is found
		while( visualScenesNode != NULL ) {
			if( visualScenesNode->FirstChildElement( "node" ) != NULL && 
				visualScenesNode->FirstChildElement( "node" )->Attribute( "type", "JOINT" ) != NULL ) {
				armatureNode = visualScenesNode;
			    break;
			} else {
				visualScenesNode = visualScenesNode->NextSibling()->ToElement();
			}
		}
		if( armatureNode == NULL ) return;

		//Parsing basic bone data from XML
		std::function< Bone* ( tinyxml2::XMLElement*, Armature*, Bone*  ) > ParseColladaBoneData = 
		[&]( tinyxml2::XMLElement* boneElement, Armature* armature, Bone* parentBone ) -> Bone* {
			Bone* bone = &armature->bones[ armature->boneCount ];
			bone->parent = parentBone;
			bone->currentTransform = &armature->boneTransforms[ armature->boneCount ];
			SetToIdentity( bone->currentTransform );
			bone->boneIndex = armature->boneCount;
			armature->boneCount++;

			strcpy( &bone->name[0], boneElement->Attribute( "sid" ) );

			float matrixData[16];
			char matrixTextData [512];
			tinyxml2::XMLNode* matrixElement = boneElement->FirstChildElement("matrix");
			strcpy( &matrixTextData[0], matrixElement->FirstChild()->ToText()->Value() );
			TextToNumberConversion( matrixTextData, matrixData );
			//Note: this is only local transform data, but its being saved in bind matrix for now
			Mat4 m;
			memcpy( &m.m[0][0], &matrixData[0], sizeof(float) * 16 );
			bone->bindPose = TransposeMatrix( m );

			if( parentBone == NULL ) {
				armature->rootBone = bone;
			} else {
				bone->bindPose = MultMatrix( parentBone->bindPose, bone->bindPose );
			}

			bone->childCount = 0;
			tinyxml2::XMLElement* childBoneElement = boneElement->FirstChildElement( "node" );
			while( childBoneElement != NULL ) {
				Bone* childBone = ParseColladaBoneData( childBoneElement, armature, bone );
				bone->children[ bone->childCount++ ] = childBone;
				tinyxml2::XMLNode* siblingNode = childBoneElement->NextSibling();
				if( siblingNode != NULL ) {
					childBoneElement = siblingNode->ToElement();
				} else {
					childBoneElement = NULL;
				}
			};

			return bone;
		};
		armature->boneCount = 0;
		tinyxml2::XMLElement* boneElement = armatureNode->FirstChildElement( "node" );
		ParseColladaBoneData( boneElement, armature, NULL );

		//Parse inverse bind pose data from skinning section of XML
		{
			tinyxml2::XMLElement* boneNamesSource = colladaDoc.FirstChildElement( "COLLADA" )->FirstChildElement( "library_controllers" )
			->FirstChildElement( "controller" )->FirstChildElement( "skin" )->FirstChildElement( "source" );
			tinyxml2::XMLElement* boneBindPoseSource = boneNamesSource->NextSibling()->ToElement();

			char* boneNamesLocalCopy = NULL;
			float* boneMatriciesData = (float*)alloca( sizeof(float) * 16 * armature->boneCount );
			const char* boneNameArrayData = boneNamesSource->FirstChild()->FirstChild()->Value();
			const char* boneMatrixTextData = boneBindPoseSource->FirstChild()->FirstChild()->Value();
			size_t nameDataLen = strlen( boneNameArrayData );
			size_t matrixDataLen = strlen( boneMatrixTextData );
			boneNamesLocalCopy = (char*)alloca( nameDataLen + 1 );
			memset( boneNamesLocalCopy, 0, nameDataLen + 1 );
			assert( textBufferLen > matrixDataLen );
			memcpy( boneNamesLocalCopy, boneNameArrayData, nameDataLen );
			memcpy( colladaTextBuffer, boneMatrixTextData, matrixDataLen );
			TextToNumberConversion( colladaTextBuffer, boneMatriciesData );
			char* nextBoneName = &boneNamesLocalCopy[0];
			for( uint8 matrixIndex = 0; matrixIndex < armature->boneCount; matrixIndex++ ) {
				Mat4 matrix;
				memcpy( &matrix.m[0], &boneMatriciesData[matrixIndex * 16], sizeof(float) * 16 );

				char boneName [32];
				char* boneNameEnd = nextBoneName;
				do {
					boneNameEnd++;
				} while( *boneNameEnd != ' ' && *boneNameEnd != 0 );
				size_t charCount = boneNameEnd - nextBoneName;
				memset( boneName, 0, sizeof( char ) * 32 );
				memcpy( boneName, nextBoneName, charCount );
				nextBoneName = boneNameEnd + 1;

				Bone* targetBone = NULL;
				for( uint8 boneIndex = 0; boneIndex < armature->boneCount; boneIndex++ ) {
					Bone* bone = &armature->bones[ boneIndex ];
					if( strcmp( bone->name, boneName ) == 0 ) {
						targetBone = bone;
						break;
					}
				}

				Mat4 correction;
				correction.m[0][0] = 1.0f; correction.m[0][1] = 0.0f; correction.m[0][2] = 0.0f; correction.m[0][3] = 0.0f;
				correction.m[1][0] = 0.0f; correction.m[1][1] = 0.0f; correction.m[1][2] = 1.0f; correction.m[1][3] = 0.0f;
				correction.m[2][0] = 0.0f; correction.m[2][1] = -1.0f; correction.m[2][2] = 0.0f; correction.m[2][3] = 0.0f;
				correction.m[3][0] = 0.0f; correction.m[3][1] = 0.0f; correction.m[3][2] = 0.0f; correction.m[3][3] = 1.0f;
				targetBone->invBindPose = TransposeMatrix( matrix );
				targetBone->invBindPose = MultMatrix( correction, targetBone->invBindPose );
			}
		}
	}

	//output to my version of storage
	storage->dataCount = 0;
	uint16 counter = 0;

	const uint32 vertCount = indexCount / 3;
	storage->vData = (Vec3*)AllocOnSubStack_Aligned( allocater, vertCount * sizeof( Vec3 ), 16 );
	storage->uvData = (float*)AllocOnSubStack_Aligned( allocater, vertCount * 2 * sizeof( float ), 4 );
	storage->normalData = (Vec3*)AllocOnSubStack_Aligned( allocater, vertCount * sizeof( Vec3 ), 4 );
	storage->iData = (uint32*)AllocOnSubStack_Aligned( allocater, vertCount * sizeof( uint32 ), 4 );
	if( rawBoneWeightData != NULL ) {
		storage->boneWeightData = (float*)AllocOnSubStack_Aligned( allocater, sizeof(float) * vertCount * MAXBONESPERVERT, 4 );
		storage->boneIndexData = (uint32*)AllocOnSubStack_Aligned( allocater, sizeof(uint32) * vertCount * MAXBONESPERVERT, 4 );
	} else {
		storage->boneWeightData = NULL;
		storage->boneIndexData = NULL;
	}

	while( counter < indexCount ) {
		Vec3 v, n;
		float uv_x, uv_y;

		uint16 vertIndex = rawIndexData[ counter++ ];
		uint16 normalIndex = rawIndexData[ counter++ ];
		uint16 uvIndex = rawIndexData[ counter++ ];

		v.x = rawColladaVertexData[ vertIndex * 3 + 0 ];
		v.z = -rawColladaVertexData[ vertIndex * 3 + 1 ];
		v.y = rawColladaVertexData[ vertIndex * 3 + 2 ];

		n.x = rawColladaNormalData[ normalIndex * 3 + 0 ];
		n.z = -rawColladaNormalData[ normalIndex * 3 + 1 ];
		n.y = rawColladaNormalData[ normalIndex * 3 + 2 ];

		uv_x = rawColladaUVData[ uvIndex * 2 ];
		uv_y = rawColladaUVData[ uvIndex * 2 + 1 ];

		///TODO: check for exact copies of data, use to index to first instance instead
		uint32 storageIndex = storage->dataCount;
		storage->vData[ storageIndex ] = v;
		storage->normalData[ storageIndex ] = n;
		storage->uvData[ storageIndex * 2 ] = uv_x;
		storage->uvData[ storageIndex * 2 + 1 ] = uv_y;
		if( rawBoneWeightData != NULL ) {
			uint16 boneDataIndex = storage->dataCount * MAXBONESPERVERT;
			uint16 boneVertexIndex = vertIndex * MAXBONESPERVERT;
			for( uint8 i = 0; i < MAXBONESPERVERT; i++ ) {
				storage->boneWeightData[ boneDataIndex + i ] = rawBoneWeightData[ boneVertexIndex + i ];
				storage->boneIndexData[ boneDataIndex + i ] = rawBoneIndexData[ boneVertexIndex + i ];
			}
		}
		storage->iData[ storageIndex ] = storageIndex;
		storage->dataCount++;
	};
}
Esempio n. 12
0
void TTrackball::LoadMatrix() const
{
    SetMatrix();
    MultMatrix();
}
Esempio n. 13
0
void DemoRender(NaCLContext* psNaCLContext)
{
    PP_Resource context = psNaCLContext->hRenderContext;
    PPB_OpenGLES2* gl = psNaCLContext->psGL;

    float rotY[4][4];
    float rotX[4][4];

    uint64_t ui64ElapsedTime = GetElapsedTimeMS();
    uint64_t ui64DeltaTimeMS = ui64ElapsedTime - psDemoContext->ui64BaseTimeMS;

    gl->Viewport(context, 0, 0, psNaCLContext->i32PluginWidth, psNaCLContext->i32PluginHeight);

    gl->Enable(context, GL_DEPTH_TEST);

    psDemoContext->ui64BaseTimeMS = ui64ElapsedTime;

    if(!psDemoContext->sDownloadBaseTexture.iDownloaded ||
       !psDemoContext->sDownloadMesh.iDownloaded)
    {
        gl->ClearColor(context, 0.0, 0.0, 1.0, 1.0f);
        gl->Clear(context, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

#ifdef ENABLE_LOADING_ICON
        if(psDemoContext->sDownloadLoadingTexture.iDownloaded == 1)
        {
            unsigned char* jpeg = 0;
            int jpegWidth = 0;
            int jpegHeight = 0;
            int iNumComponents = 0;
            GLenum eFormat;

            gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sLoadingMap.hTextureGL);

            jpeg = jpgd::decompress_jpeg_image_from_memory((unsigned char*)psDemoContext->sDownloadLoadingTexture.data.c_str(),
                psDemoContext->sDownloadLoadingTexture.data.length(), 
                &jpegWidth,
                &jpegHeight,
                &iNumComponents,
                3);

            if(!jpeg)
            {
                DBG_LOG(DBG_LOG_PREFIX"Bad jpeg texture");
                return;
            }

            switch(iNumComponents)
            {
                case 3:
                {
                    eFormat = GL_RGB;
                    break;
                }
                case 4:
                {
                    eFormat = GL_RGBA;
                    break;
                }
                default:
                {
                    eFormat = GL_LUMINANCE;
                    break;
                }
            }

            gl->TexImage2D(context, GL_TEXTURE_2D, 0, eFormat, jpegWidth, jpegHeight, 0, eFormat, GL_UNSIGNED_BYTE, jpeg);

            gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

            psDemoContext->sDownloadLoadingTexture.iDownloaded = 2;
        }

        if(psDemoContext->sDownloadLoadingTexture.iDownloaded == 2)
        {
            DrawQuad(context,
                gl,
                psDemoContext->sQuad.iVtxCount,
                psDemoContext->sQuad.iIdxCount,
                psDemoContext->sQuad.hVBO,
                psDemoContext->sQuad.hIBO);
        }
#endif
        return;
    }

    if(psDemoContext->sDownloadMesh.iDownloaded == 1)
    {
        LoadJSONMesh(context,
        gl,
        psDemoContext->sDownloadMesh.data.c_str(),
        &psDemoContext->sMeshTransform,
        &psDemoContext->sMesh.iIdxCount,
        &psDemoContext->sMesh.iVtxCount,
        &psDemoContext->sMesh.hVBO,
        &psDemoContext->sMesh.hIBO);

        psDemoContext->sDownloadMesh.iDownloaded = 2;
    }

    if(psDemoContext->sDownloadBaseTexture.iDownloaded == 1)
    {
        unsigned char* jpeg = 0;
        int jpegWidth = 0;
        int jpegHeight = 0;
        int iNumComponents = 0;
        GLenum eFormat;

        gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sBaseMap.hTextureGL);

        jpeg = jpgd::decompress_jpeg_image_from_memory((unsigned char*)psDemoContext->sDownloadBaseTexture.data.c_str(),
            psDemoContext->sDownloadBaseTexture.data.length(), 
            &jpegWidth,
            &jpegHeight,
            &iNumComponents,
            3);

        if(!jpeg)
        {
            DBG_LOG(DBG_LOG_PREFIX"Bad jpeg texture");
            return;
        }

        switch(iNumComponents)
        {
            case 3:
            {
                eFormat = GL_RGB;
                break;
            }
            case 4:
            {
                eFormat = GL_RGBA;
                break;
            }
            default:
            {
                eFormat = GL_LUMINANCE;
                break;
            }
        }

        gl->TexImage2D(context, GL_TEXTURE_2D, 0, eFormat, jpegWidth, jpegHeight, 0, eFormat, GL_UNSIGNED_BYTE, jpeg);

        gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        gl->TexParameteri(context, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        psDemoContext->sDownloadBaseTexture.iDownloaded = 2;
    }
    gl->ClearColor(context, 0.5, 0.5, 0.5, 1.0f);
    gl->Clear(context, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    Identity(psDemoContext->sMeshTransform.rot);

    Identity(rotX);
    Identity(rotY);

    psDemoContext->fAngleY += psDemoContext->fAngleModY * ui64DeltaTimeMS;
    psDemoContext->fAngleX += psDemoContext->fAngleModX * ui64DeltaTimeMS;

    Rotate(rotY, 0.f,1.f,0.f, psDemoContext->fAngleY);

    Rotate(rotX, 1.f,0.f,0.f, psDemoContext->fAngleX);

    MultMatrix(psDemoContext->sMeshTransform.rot, rotY, rotX);

    gl->BindTexture(context, GL_TEXTURE_2D, psDemoContext->sDisplacementMap.hTextureGL);
    gl->UseProgram(context, psDemoContext->hDisplacementMapShader);

    gl->Uniform1f(context, gl->GetUniformLocation(context, psDemoContext->hDisplacementMapShader, "HighlightEnabled"), psDemoContext->iHighlightEnabled);

    DrawJSONMesh(context,
        gl,
        &psDemoContext->sMeshTransform,
        psDemoContext->sMesh.iVtxCount,
        psDemoContext->sMesh.iIdxCount,
        psDemoContext->sMesh.hVBO,
        psDemoContext->sMesh.hIBO);
}
Esempio n. 14
0
	void MatrixStack::RotateRad(float radians, float x, float y, float z)
	{
		MultMatrix(Matrix4Df(radians, x, y, z));
	}
Esempio n. 15
0
	void RotateZ( float degrees )
	{
		RageMatrix m;
		RageMatrixRotationZ( &m, degrees );
		MultMatrix( m );
	}
Esempio n. 16
0
/////////////////////////////////
// cv3dTrackerCalibrateCameras //
/////////////////////////////////
CV_IMPL CvBool cv3dTrackerCalibrateCameras(int num_cameras,
                   const Cv3dTrackerCameraIntrinsics camera_intrinsics[], // size is num_cameras
                   CvSize etalon_size,
                   float square_size,
                   IplImage *samples[],                                   // size is num_cameras
                   Cv3dTrackerCameraInfo camera_info[])                   // size is num_cameras
{
    CV_FUNCNAME("cv3dTrackerCalibrateCameras");
    const int num_points = etalon_size.width * etalon_size.height;
    int cameras_done = 0;        // the number of cameras whose positions have been determined
    CvPoint3D32f *object_points = NULL; // real-world coordinates of checkerboard points
    CvPoint2D32f *points = NULL; // 2d coordinates of checkerboard points as seen by a camera
    IplImage *gray_img = NULL;   // temporary image for color conversion
    IplImage *tmp_img = NULL;    // temporary image used by FindChessboardCornerGuesses
    int c, i, j;

    if (etalon_size.width < 3 || etalon_size.height < 3)
        CV_ERROR(CV_StsBadArg, "Chess board size is invalid");

    for (c = 0; c < num_cameras; c++)
    {
        // CV_CHECK_IMAGE is not available in the cvaux library
        // so perform the checks inline.

        //CV_CALL(CV_CHECK_IMAGE(samples[c]));

        if( samples[c] == NULL )
            CV_ERROR( CV_HeaderIsNull, "Null image" );

        if( samples[c]->dataOrder != IPL_DATA_ORDER_PIXEL && samples[c]->nChannels > 1 )
            CV_ERROR( CV_BadOrder, "Unsupported image format" );

        if( samples[c]->maskROI != 0 || samples[c]->tileInfo != 0 )
            CV_ERROR( CV_StsBadArg, "Unsupported image format" );

        if( samples[c]->imageData == 0 )
            CV_ERROR( CV_BadDataPtr, "Null image data" );

        if( samples[c]->roi &&
            ((samples[c]->roi->xOffset | samples[c]->roi->yOffset
              | samples[c]->roi->width | samples[c]->roi->height) < 0 ||
             samples[c]->roi->xOffset + samples[c]->roi->width > samples[c]->width ||
             samples[c]->roi->yOffset + samples[c]->roi->height > samples[c]->height ||
             (unsigned) (samples[c]->roi->coi) > (unsigned) (samples[c]->nChannels)))
            CV_ERROR( CV_BadROISize, "Invalid ROI" );

        // End of CV_CHECK_IMAGE inline expansion

        if (samples[c]->depth != IPL_DEPTH_8U)
            CV_ERROR(CV_BadDepth, "Channel depth of source image must be 8");

        if (samples[c]->nChannels != 3 && samples[c]->nChannels != 1)
            CV_ERROR(CV_BadNumChannels, "Source image must have 1 or 3 channels");
    }

    CV_CALL(object_points = (CvPoint3D32f *)cvAlloc(num_points * sizeof(CvPoint3D32f)));
    CV_CALL(points = (CvPoint2D32f *)cvAlloc(num_points * sizeof(CvPoint2D32f)));

    // fill in the real-world coordinates of the checkerboard points
    FillObjectPoints(object_points, etalon_size, square_size);

    for (c = 0; c < num_cameras; c++)
    {
        CvSize image_size = cvSize(samples[c]->width, samples[c]->height);
        IplImage *img;

        // The input samples are not required to all have the same size or color
        // format. If they have different sizes, the temporary images are
        // reallocated as necessary.
        if (samples[c]->nChannels == 3)
        {
            // convert to gray
            if (gray_img == NULL || gray_img->width != samples[c]->width ||
                gray_img->height != samples[c]->height )
            {
                if (gray_img != NULL)
                    cvReleaseImage(&gray_img);
                CV_CALL(gray_img = cvCreateImage(image_size, IPL_DEPTH_8U, 1));
            }
            
            CV_CALL(cvCvtColor(samples[c], gray_img, CV_BGR2GRAY));

            img = gray_img;
        }
        else
        {
            // no color conversion required
            img = samples[c];
        }

        if (tmp_img == NULL || tmp_img->width != samples[c]->width ||
            tmp_img->height != samples[c]->height )
        {
            if (tmp_img != NULL)
                cvReleaseImage(&tmp_img);
            CV_CALL(tmp_img = cvCreateImage(image_size, IPL_DEPTH_8U, 1));
        }

        int count = num_points;
        bool found = cvFindChessBoardCornerGuesses(img, tmp_img, 0,
                                                   etalon_size, points, &count) != 0;
        if (count == 0)
            continue;
        
        // If found is true, it means all the points were found (count = num_points).
        // If found is false but count is non-zero, it means that not all points were found.

        cvFindCornerSubPix(img, points, count, cvSize(5,5), cvSize(-1,-1),
                    cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 10, 0.01f));

        // If the image origin is BL (bottom-left), fix the y coordinates
        // so they are relative to the true top of the image.
        if (samples[c]->origin == IPL_ORIGIN_BL)
        {
            for (i = 0; i < count; i++)
                points[i].y = samples[c]->height - 1 - points[i].y;
        }

        if (found)
        {
            // Make sure x coordinates are increasing and y coordinates are decreasing.
            // (The y coordinate of point (0,0) should be the greatest, because the point
            // on the checkerboard that is the origin is nearest the bottom of the image.)
            // This is done after adjusting the y coordinates according to the image origin.
            if (points[0].x > points[1].x)
            {
                // reverse points in each row
                for (j = 0; j < etalon_size.height; j++)
                {
                    CvPoint2D32f *row = &points[j*etalon_size.width];
                    for (i = 0; i < etalon_size.width/2; i++)
                        std::swap(row[i], row[etalon_size.width-i-1]);
                }
            }

            if (points[0].y < points[etalon_size.width].y)
            {
                // reverse points in each column
                for (i = 0; i < etalon_size.width; i++)
                {
                    for (j = 0; j < etalon_size.height/2; j++)
                        std::swap(points[i+j*etalon_size.width],
                                  points[i+(etalon_size.height-j-1)*etalon_size.width]);
                }
            }
        }

        DrawEtalon(samples[c], points, count, etalon_size, found);

        if (!found)
            continue;

        float rotVect[3];
        float rotMatr[9];
        float transVect[3];

        cvFindExtrinsicCameraParams(count,
                                    image_size,
                                    points,
                                    object_points,
                                    const_cast<float *>(camera_intrinsics[c].focal_length),
                                    camera_intrinsics[c].principal_point,
                                    const_cast<float *>(camera_intrinsics[c].distortion),
                                    rotVect,
                                    transVect);

        // Check result against an arbitrary limit to eliminate impossible values.
        // (If the chess board were truly that far away, the camera wouldn't be able to
        // see the squares.)
        if (transVect[0] > 1000*square_size
            || transVect[1] > 1000*square_size
            || transVect[2] > 1000*square_size)
        {
            // ignore impossible results
            continue;
        }

        CvMat rotMatrDescr = cvMat(3, 3, CV_32FC1, rotMatr);
        CvMat rotVectDescr = cvMat(3, 1, CV_32FC1, rotVect);

        /* Calc rotation matrix by Rodrigues Transform */
        cvRodrigues2( &rotVectDescr, &rotMatrDescr );

        //combine the two transformations into one matrix
        //order is important! rotations are not commutative
        float tmat[4][4] = { { 1.f, 0.f, 0.f, 0.f },
                             { 0.f, 1.f, 0.f, 0.f },
                             { 0.f, 0.f, 1.f, 0.f },
                             { transVect[0], transVect[1], transVect[2], 1.f } };
        
        float rmat[4][4] = { { rotMatr[0], rotMatr[1], rotMatr[2], 0.f },
                             { rotMatr[3], rotMatr[4], rotMatr[5], 0.f },
                             { rotMatr[6], rotMatr[7], rotMatr[8], 0.f },
                             { 0.f, 0.f, 0.f, 1.f } };


        MultMatrix(camera_info[c].mat, tmat, rmat);

        // change the transformation of the cameras to put them in the world coordinate 
        // system we want to work with.

        // Start with an identity matrix; then fill in the values to accomplish
        // the desired transformation.
        float smat[4][4] = { { 1.f, 0.f, 0.f, 0.f },
                             { 0.f, 1.f, 0.f, 0.f },
                             { 0.f, 0.f, 1.f, 0.f },
                             { 0.f, 0.f, 0.f, 1.f } };

        // First, reflect through the origin by inverting all three axes.
        smat[0][0] = -1.f;
        smat[1][1] = -1.f;
        smat[2][2] = -1.f;
        MultMatrix(tmat, camera_info[c].mat, smat);

        // Scale x and y coordinates by the focal length (allowing for non-square pixels
        // and/or non-symmetrical lenses).
        smat[0][0] = 1.0f / camera_intrinsics[c].focal_length[0];
        smat[1][1] = 1.0f / camera_intrinsics[c].focal_length[1];
        smat[2][2] = 1.0f;
        MultMatrix(camera_info[c].mat, smat, tmat);

        camera_info[c].principal_point = camera_intrinsics[c].principal_point;
        camera_info[c].valid = true;

        cameras_done++;
    }

exit:
    cvReleaseImage(&gray_img);
    cvReleaseImage(&tmp_img);
    cvFree(&object_points);
    cvFree(&points);

    return cameras_done == num_cameras;
}
Esempio n. 17
0
	// Right multiply the current matrix with the computed scale
	// matrix. (transformation is about the current world origin)
	void Scale( float x, float y, float z )
 	{
		RageMatrix m;
		RageMatrixScaling( &m, x, y, z );
		MultMatrix( m );
	}
Esempio n. 18
0
void SpinCamera::LoadMatrix()
{
	glLoadIdentity();

	MultMatrix();
}
Esempio n. 19
0
	// Right multiply the current matrix with the computed translation
	// matrix. (transformation is about the current world origin)
	void Translate( float x, float y, float z )
 	{
		RageMatrix m;
		RageMatrixTranslation( &m, x, y, z );
		MultMatrix( m );
	}
Esempio n. 20
0
void LoadAnimationDataFromCollada( const char* fileName, ArmatureKeyFrame* keyframe, Armature* armature ) {
	tinyxml2::XMLDocument colladaDoc;
	colladaDoc.LoadFile( fileName );

	tinyxml2::XMLNode* animationNode = colladaDoc.FirstChildElement( "COLLADA" )->FirstChildElement( "library_animations" )->FirstChild();
	while( animationNode != NULL ) {
		//Desired data: what bone, and what local transform to it occurs
		Mat4 boneLocalTransform;
		Bone* targetBone = NULL;

		//Parse the target attribute from the XMLElement for channel, and get the bone it corresponds to
		const char* transformName = animationNode->FirstChildElement( "channel" )->Attribute( "target" );
		size_t nameLen = strlen( transformName );
		char* transformNameCopy = (char*)alloca( nameLen );
		strcpy( transformNameCopy, transformName );
		char* nameEnd = transformNameCopy;
		while( *nameEnd != '/' && *nameEnd != 0 ) {
			nameEnd++;
		}
		memset( transformNameCopy, 0, nameLen );
		nameLen = nameEnd - transformNameCopy;
		memcpy( transformNameCopy, transformName, nameLen );
		for( uint8 boneIndex = 0; boneIndex < armature->boneCount; boneIndex++ ) {
			if( strcmp( armature->bones[ boneIndex ].name, transformNameCopy ) == 0 ) {
				targetBone = &armature->bones[ boneIndex ];
				break;
			}
		}

		//Parse matrix data, and extract first keyframe data
		tinyxml2::XMLNode* transformMatrixElement = animationNode->FirstChild()->NextSibling();
		const char* matrixTransformData = transformMatrixElement->FirstChild()->FirstChild()->Value();
		size_t transformDataLen = strlen( matrixTransformData ) + 1;
		char* transformDataCopy = (char*)alloca( transformDataLen * sizeof( char ) );
		memset( transformDataCopy, 0, transformDataLen );
		memcpy( transformDataCopy, matrixTransformData, transformDataLen );
		int count = 0; 
		transformMatrixElement->FirstChildElement()->QueryAttribute( "count", &count );
		float* rawTransformData = (float*)alloca(  count * sizeof(float) );
		memset( rawTransformData, 0, count * sizeof(float) );
		TextToNumberConversion( transformDataCopy, rawTransformData );
		memcpy( &boneLocalTransform.m[0][0], &rawTransformData[0], 16 * sizeof(float) );

		//Save data in BoneKeyFrame struct
		boneLocalTransform = TransposeMatrix( boneLocalTransform );
		if( targetBone == armature->rootBone ) {
			Mat4 correction;
			correction.m[0][0] = 1.0f; correction.m[0][1] = 0.0f; correction.m[0][2] = 0.0f; correction.m[0][3] = 0.0f;
			correction.m[1][0] = 0.0f; correction.m[1][1] = 0.0f; correction.m[1][2] = -1.0f; correction.m[1][3] = 0.0f;
			correction.m[2][0] = 0.0f; correction.m[2][1] = 1.0f; correction.m[2][2] = 0.0f; correction.m[2][3] = 0.0f;
			correction.m[3][0] = 0.0f; correction.m[3][1] = 0.0f; correction.m[3][2] = 0.0f; correction.m[3][3] = 1.0f;
			boneLocalTransform = MultMatrix( boneLocalTransform, correction );
		}
		BoneKeyFrame* key = &keyframe->targetBoneTransforms[ targetBone->boneIndex ];
		key->combinedMatrix = boneLocalTransform;
		DecomposeMat4( boneLocalTransform, &key->scale, &key->rotation, &key->translation );
		Mat4 m = Mat4FromComponents( key->scale, key->rotation, key->translation );

		animationNode = animationNode->NextSibling();
	}

	//Pre multiply bones with parents to save doing it during runtime
	struct {
		ArmatureKeyFrame* keyframe;
		void PremultiplyKeyFrame( Bone* target, Mat4 parentTransform ) {
			BoneKeyFrame* boneKey = &keyframe->targetBoneTransforms[ target->boneIndex ];
			Mat4 netMatrix = MultMatrix( boneKey->combinedMatrix, parentTransform );

			for( uint8 boneIndex = 0; boneIndex < target->childCount; boneIndex++ ) {
				PremultiplyKeyFrame( target->children[ boneIndex ], netMatrix );
			}
			boneKey->combinedMatrix = netMatrix;
			DecomposeMat4( boneKey->combinedMatrix, &boneKey->scale, &boneKey->rotation, &boneKey->translation );
		}
	}LocalRecursiveScope;
	LocalRecursiveScope.keyframe = keyframe;
	Mat4 i; SetToIdentity( &i );
	LocalRecursiveScope.PremultiplyKeyFrame( armature->rootBone, i );
}
void LocationSelect:: Draw () {

  Matrix transformation;
  local_transformation.to_matrix(transformation);
  
  GFXLoadIdentity(MODEL);
  GFXMultMatrixModel (transformation);
  /*
    GFXEnable(DEPTHWRITE);
    GFXEnable(DEPTHTEST);
    GFXDisable(TEXTURE0);
    GFXDisable(TEXTURE1);
    GFXDisable(LIGHTING);
    GFXPushBlendMode();
    //  GFXBlendMode(SRCALPHA,INVSRCALPHA);
    //GFXColor4f (parentScene->HUDColor.r, parentScene->HUDColor.g, parentScene->HUDColor.b, parentScene->HUDColor.a);

    GFXColor4f (0,.5,0,.3);
*/
#ifdef DELTA_MOVEMENT
  if (vert) {
    LocalPosition.k=0;
    
  }
  vert=false;

  if (DeltaPosition.k) {
    LocalPosition.k-=DeltaPosition.k*.3;
    DeltaPosition.k=0;
  }
#endif

  if (changed||vert) {
    Matrix t,m;
    Matrix v;

    GFXGetMatrixView (v);

    GFXGetMatrixModel (m);
    MultMatrix(t,v,m);

    //following translates 'z'...not sure it's necessary
    //    Translate (v,0,0,LocalPosition.k);
    //    MultMatrix (m,t,v);

    //the location in camera coordinates of the beginning of the location select
    Vector tLocation (t.p.Cast());
    Vector tP (t.getP());//the p vector of the plane being selected on
    Vector tQ (t.getQ());//the q vector of the plane being selected on
    ///unused    Vector tR (t[8],t[9],t[10]);//the q vector of the plane being selected on
    //VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[0],t[1],t[2]);
    //VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[4],t[5],t[6]);
    //VSFileSystem::Fprintf (stderr,"<%f,%f,%f>",t[8],t[9],t[10]);
#ifdef DELTA_MOVEMENT
    float zvalueXY = tLocation.k+LocalPosition.i*tP.k+LocalPosition.j*tQ.k; // z val of the parallelogram
#else
    float zvalueXY = tLocation.k+LocalPosition.i*tP.k+LocalPosition.j*tQ.k+LocalPosition.k*tR.k; //zvalue of the cursor
#endif

    if (changed&&!vert) {    //planar movement
    
    if (zvalueXY >1000)  /// zfar
      zvalueXY = 1000;
    if (zvalueXY<-1000)
      zvalueXY = -1000;

      LocalPosition.i= fabs(zvalueXY)*(((2*DeltaPosition.i/g_game.x_resolution - 1)*g_game.MouseSensitivityX*GFXGetXInvPerspective()*tP.i)-(1-(2*DeltaPosition.j/g_game.y_resolution)*g_game.MouseSensitivityY*GFXGetYInvPerspective()*tP.j));
      LocalPosition.j= fabs(zvalueXY)*(((2*DeltaPosition.i/g_game.x_resolution - 1)*g_game.MouseSensitivityX*GFXGetXInvPerspective()*tQ.i)-(1-(2*DeltaPosition.j/g_game.y_resolution)*tQ.j*g_game.MouseSensitivityY*GFXGetYInvPerspective()));
      DeltaPosition= Vector(0,0,0);
      //    Vector TransPQR (t[0]*i+t[4]*LocalPosition.j+t[8]*LocalPosition.k+t[12],t[1]*LocalPosition.i+t[5]*LocalPosition.j+t[9]*LocalPosition.k+t[13],t[2]*LocalPosition.i+t[6]*LocalPosition.j+t[10]*LocalPosition.k+t[14]);
      changed=false;
    }
#ifndef DELTA_MOVEMENT 
    else { //vertical movement

    if (zvalueXY >1000)  /// zfar
      zvalueXY = 1000;
    if (zvalueXY<-1000)
      zvalueXY = -1000;

      LocalPosition.k= fabs(zvalueXY)*(((2*DeltaPosition.i/g_game.x_resolution - 1)*g_game.MouseSensitivityX*GFXGetXInvPerspective()*tR.i)-((2*DeltaPosition.j/g_game.y_resolution -1)*g_game.MouseSensitivityY*GFXGetYInvPerspective()*tR.j));
      if (DeltaPosition.k) {
	LocalPosition.k=0;
	DeltaPosition.k=0;
      }
      vert =false;
      changed=false;
    }
#endif
  }

  //draw the animation
  LocSelUpAni.SetPosition (QVector (LocalPosition.i,LocalPosition.j,0));
  LocSelUpAni.Draw();
  LocSelAni.SetPosition(LocalPosition);
  LocSelAni.Draw();
  

  /*
  GFXBegin(TRIANGLES);
  if (fabs(LocalPosition.k-CrosshairSize)>CrosshairSize) {
    int tmp;
    if (LocalPosition.k>=0)
      tmp =1;
    else
      tmp =-1;
    GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
    GFXVertex3f (LocalPosition.i,LocalPosition.j+CrosshairSize*.125,0);
    GFXVertex3f (LocalPosition.i,LocalPosition.j-CrosshairSize*.125,0);

    GFXVertex3f (LocalPosition.i,LocalPosition.j-CrosshairSize*.125,0);
    GFXVertex3f (LocalPosition.i,LocalPosition.j+CrosshairSize*.125,0);
    GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);

    GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
    GFXVertex3f (LocalPosition.i+.125*CrosshairSize,LocalPosition.j,0);
    GFXVertex3f (LocalPosition.i-CrosshairSize*.125,LocalPosition.j,0);

    GFXVertex3f (LocalPosition.i-CrosshairSize*.125,LocalPosition.j,0);
    GFXVertex3f (LocalPosition.i+CrosshairSize*.125,LocalPosition.j,0);
    GFXVertex3f (LocalPosition.i,LocalPosition.j,LocalPosition.k-tmp*CrosshairSize);
  }
  if (fabs(LocalPosition.i)+fabs(LocalPosition.j)>CrosshairSize) {
    GFXVertex3f (0,0,0);
    GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*.125);
    GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*-.125);
    
    GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*-.125);
    GFXVertex3f (LocalPosition.i,LocalPosition.j,CrosshairSize*.125);
    GFXVertex3f (0,0,0);
  }	
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (1,.1,.1);	
  POSITION_GFXVertex (1,.1,-.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (1,-.1,-.1);	
  POSITION_GFXVertex (1,-.1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (1,-.1,.1);
  POSITION_GFXVertex (1,.1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (1,.1,-.1);
  POSITION_GFXVertex (1,-.1,-.1);//one of the arrows to point
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-1,.1,-.1);	
  POSITION_GFXVertex (-1,.1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-1,-.1,.1);	
  POSITION_GFXVertex (-1,-.1,-.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-1,.1,.1);
  POSITION_GFXVertex (-1,-.1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-1,-.1,-.1);
  POSITION_GFXVertex (-1,.1,-.1);//one of the arrows to point

  //vertical
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,.1,1);	
  POSITION_GFXVertex (.1,-.1,1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,-.1,1);	
  POSITION_GFXVertex (-.1,.1,1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,.1,1);
  POSITION_GFXVertex (.1,.1,1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,-.1,1);
  POSITION_GFXVertex(-.1,-.1,1);//one of the arrows to point
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,-.1,-1);	
  POSITION_GFXVertex (.1,.1,-1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,.1,-1);	
  POSITION_GFXVertex (-.1,-.1,-1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,.1,-1);
  POSITION_GFXVertex (-.1,.1,-1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,-.1,-1);
  POSITION_GFXVertex (.1,-.1,-1);//one of the arrows to point


  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,-1,.1);	
  POSITION_GFXVertex (.1,-1,-.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,-1,-.1);	
  POSITION_GFXVertex (-.1,-1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,-1,.1);
  POSITION_GFXVertex (.1,-1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,-1,-.1);
  POSITION_GFXVertex (-.1,-1,-.1);//one of the arrows to point
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,1,-.1);	
  POSITION_GFXVertex (.1,1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,1,.1);	
  POSITION_GFXVertex (-.1,1,-.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (.1,1,.1);
  POSITION_GFXVertex (-.1,1,.1);
  POSITION_GFXVertex (0,0,0);
  POSITION_GFXVertex (-.1,1,-.1);
  POSITION_GFXVertex (.1,1,-.1);//one of the arrows to point


 GFXEnd();
  GFXBegin (QUADS);
  //GFXColor4f (parentScene->HUDColor.r, parentScene->HUDColor.g, parentScene->HUDColor.b, 1.5*parentScene->HUDColor.a);

  GFXVertex3f(.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
  GFXVertex3f(LocalPosition.i,.5*CrosshairSize+LocalPosition.j,0);
  GFXVertex3f(-.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
  GFXVertex3f(LocalPosition.i,-.5*CrosshairSize+LocalPosition.j,0);

  GFXVertex3f(LocalPosition.i,-.5*CrosshairSize+LocalPosition.j,0);
  GFXVertex3f(-.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);
  GFXVertex3f(LocalPosition.i,.5*CrosshairSize+LocalPosition.j,0);
  GFXVertex3f(.5*CrosshairSize +LocalPosition.i,LocalPosition.j,0);

  GFXColor4f (0,.5,0,.5);
  POSITION_GFXVertex (1,.1,.1); //cap
  POSITION_GFXVertex (1,-.1,.1);
  POSITION_GFXVertex (1,-.1,-.1);
  POSITION_GFXVertex (1,.1,-.1);

  POSITION_GFXVertex (-1,.1,-.1);
  POSITION_GFXVertex (-1,-.1,-.1);
  POSITION_GFXVertex (-1,-.1,.1);
  POSITION_GFXVertex (-1,.1,.1); //cap


  POSITION_GFXVertex (.1,-1,.1); //cap
  POSITION_GFXVertex (-.1,-1,.1);
  POSITION_GFXVertex (-.1,-1,-.1);
  POSITION_GFXVertex (.1,-1,-.1);

  POSITION_GFXVertex (.1,1,-.1);
  POSITION_GFXVertex (-.1,1,-.1);
  POSITION_GFXVertex (-.1,1,.1);
  POSITION_GFXVertex (.1,1,.1); //cap


  POSITION_GFXVertex (.1,.1,1); //cap
  POSITION_GFXVertex (-.1,.1,1);
  POSITION_GFXVertex (-.1,-.1,1);
  POSITION_GFXVertex (.1,-.1,1);

  POSITION_GFXVertex (.1,-.1,-1);
  POSITION_GFXVertex (-.1,-.1,-1);
  POSITION_GFXVertex (-.1,.1,-1);
  POSITION_GFXVertex (.1,.1,-1); //cap



  GFXEnd();
*/

  GFXPopBlendMode();


}