Exemple #1
0
qboolean G2API_GetBoltMatrix_SPMethod(g2handle_t g2h, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles,
							 const vec3_t position, const int frameNum, const qhandle_t *modelList, const vec3_t scale )
{
	CGhoul2Info_v *ghoul2 = G2API_GetGhoul2Model(g2h);

	if (ghoul2 && (unsigned)modelIndex < ghoul2->size())
	{
		CGhoul2Info &ghlInfo = (*ghoul2)[modelIndex];

		//assert(boltIndex < ghlInfo->mBltlist.size());

		if ((unsigned)boltIndex < ghlInfo.mBltlist.size())
		{
			// make sure we have transformed the skeleton
			if (ghlInfo.mSkelFrameNum != frameNum)
			{
				// make sure it's initialized even if noreconstruct is on
				if (!gG2_GBMNoReconstruct || ghlInfo.mSkelFrameNum == -1)
				{
					G2_ConstructGhoulSkeleton(*ghoul2, frameNum, modelList, true, angles, position, scale, false);
				}
			}

			gG2_GBMNoReconstruct = qfalse;

			mdxaBone_t scaled;
			mdxaBone_t *use;
			use = &ghlInfo.mBltlist[boltIndex].position;

			if (scale[0]||scale[1]||scale[2])
			{
				scaled=*use;
				use=&scaled;

				// scale the bolt position by the scale factor for this model since at this point its still in model space
				if (scale[0])
				{
					scaled.matrix[0][3] *= scale[0];
				}
				if (scale[1])
				{
					scaled.matrix[1][3] *= scale[1];
				}
				if (scale[2])
				{
					scaled.matrix[2][3] *= scale[2];
				}
			}
			// pre generate the world matrix
			G2_GenerateWorldMatrix(angles, position);

			VectorNormalize((float*)use->matrix[0]);
			VectorNormalize((float*)use->matrix[1]);
			VectorNormalize((float*)use->matrix[2]);

			Multiply_3x4Matrix(matrix, &worldMatrix, use);
			return qtrue;
		}
	}
	return qfalse;
}
Exemple #2
0
qboolean G2API_GetBoltMatrix(g2handle_t g2h, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, const qhandle_t *modelList, const vec3_t scale )
{
	if (gG2_GBMUseSPMethod)
	{
		gG2_GBMUseSPMethod = qfalse;
		return G2API_GetBoltMatrix_SPMethod(g2h, modelIndex, boltIndex, matrix, angles, position, frameNum, modelList, scale);
	}

	CGhoul2Info_v *ghoul2 = G2API_GetGhoul2Model(g2h);

	if (ghoul2 && (unsigned)modelIndex < ghoul2->size())
	{
		CGhoul2Info &ghlInfo = (*ghoul2)[modelIndex];

		//assert(boltIndex < ghlInfo->mBltlist.size());

		if ((unsigned)boltIndex < ghlInfo.mBltlist.size())
		{
			// make sure we have transformed the skeleton
			if (ghlInfo.mSkelFrameNum != frameNum)
			{
				// make sure it's initialized even if noreconstruct is on
				if (!gG2_GBMNoReconstruct || ghlInfo.mSkelFrameNum == -1)
				{
					G2_ConstructGhoulSkeleton(*ghoul2, frameNum, modelList, true, angles, position, scale, false);
				}
			}

			gG2_GBMNoReconstruct = qfalse;

			mdxaBone_t scaled;
			mdxaBone_t *use;
			use = &ghlInfo.mBltlist[boltIndex].position;

			if (scale[0]||scale[1]||scale[2])
			{
				scaled=*use;
				use=&scaled;

				// scale the bolt position by the scale factor for this model since at this point its still in model space
				if (scale[0])
				{
					scaled.matrix[0][3] *= scale[0];
				}
				if (scale[1])
				{
					scaled.matrix[1][3] *= scale[1];
				}
				if (scale[2])
				{
					scaled.matrix[2][3] *= scale[2];
				}
			}
			// pre generate the world matrix
			G2_GenerateWorldMatrix(angles, position);

			// for some reason we get the end matrix rotated by 90 degrees
			mdxaBone_t	rotMat, tempMatrix;
			vec3_t		newangles = {0,270,0};
			Create_Matrix(newangles, &rotMat);
			// make the model space matrix we have for this bolt into a world matrix
//			Multiply_3x4Matrix(matrix, &worldMatrix,use);
			Multiply_3x4Matrix(&tempMatrix, &worldMatrix,use);
			vec3_t origin;
			origin[0] = tempMatrix.matrix[0][3];
			origin[1] = tempMatrix.matrix[1][3];
			origin[2] = tempMatrix.matrix[2][3];
			tempMatrix.matrix[0][3] = tempMatrix.matrix[1][3] = tempMatrix.matrix[2][3] = 0;
			Multiply_3x4Matrix(matrix, &tempMatrix, &rotMat);
			matrix->matrix[0][3] = origin[0];
			matrix->matrix[1][3] = origin[1];
			matrix->matrix[2][3] = origin[2];
			return qtrue;

		}
	}

	return qfalse;
}
Exemple #3
0
qboolean G2API_GetBoltMatrix(CGhoul2Info_v &ghoul2, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, qhandle_t *modelList, vec3_t scale )
{
	assert(ghoul2.size() > modelIndex);

	if ((int)&ghoul2 && (ghoul2.size() > modelIndex))
	{
		CGhoul2Info *ghlInfo = &ghoul2[modelIndex];

		//assert(boltIndex < ghlInfo->mBltlist.size());

		if (ghlInfo && (boltIndex < ghlInfo->mBltlist.size()) && boltIndex >= 0 )
		{
			// make sure we have transformed the skeleton
			if (!gG2_GBMNoReconstruct)
			{
				G2_ConstructGhoulSkeleton(ghoul2, frameNum, modelList, true, angles, position, scale, false);
			}

			gG2_GBMNoReconstruct = qfalse;

			mdxaBone_t scaled;
			mdxaBone_t *use;
			use=&ghlInfo->mBltlist[boltIndex].position;

			if (scale[0]||scale[1]||scale[2])
			{
				scaled=*use;
				use=&scaled;

				// scale the bolt position by the scale factor for this model since at this point its still in model space
				if (scale[0])
				{
					scaled.matrix[0][3] *= scale[0];
				}
				if (scale[1])
				{
					scaled.matrix[1][3] *= scale[1];
				}
				if (scale[2])
				{
					scaled.matrix[2][3] *= scale[2];
				}
			}
			// pre generate the world matrix
			G2_GenerateWorldMatrix(angles, position);

			// for some reason we get the end matrix rotated by 90 degrees
			mdxaBone_t	rotMat, tempMatrix;
			vec3_t		newangles = {0,270,0};
			Create_Matrix(newangles, &rotMat);
			// make the model space matrix we have for this bolt into a world matrix
//			Multiply_3x4Matrix(matrix, &worldMatrix,use);
			Multiply_3x4Matrix(&tempMatrix, &worldMatrix,use);	
			vec3_t origin;
			origin[0] = tempMatrix.matrix[0][3];
			origin[1] = tempMatrix.matrix[1][3];
			origin[2] = tempMatrix.matrix[2][3];
			tempMatrix.matrix[0][3] = tempMatrix.matrix[1][3] = tempMatrix.matrix[2][3] = 0;
			Multiply_3x4Matrix(matrix, &tempMatrix, &rotMat);
			matrix->matrix[0][3] = origin[0];
			matrix->matrix[1][3] = origin[1];
			matrix->matrix[2][3] = origin[2];
			return qtrue;
			
		}
	}

	return qfalse;
}