示例#1
0
文件: robot.cpp 项目: paud/d2x-xl
//	-----------------------------------------------------------------------------------------------------------
//given an CObject and a gun number, return position in 3-space of gun
//fills in gun_point
int CalcGunPoint (CFixVector *vGunPoint, CObject *objP, int nGun)
{
	CPolyModel*	pm = gameData.models.polyModels [0] + objP->rType.polyObjInfo.nModel;
	tRobotInfo*	botInfoP;
	CFixVector*	vGunPoints, vGunPos, vRot;
	CFixMatrix	m;
	int			nSubModel;				//submodel number

Assert(objP->info.renderType == RT_POLYOBJ || objP->info.renderType == RT_MORPH);
//Assert(objP->info.nId < gameData.bots.nTypes [gameStates.app.bD1Data]);

botInfoP = &ROBOTINFO (objP->info.nId);
if (!(vGunPoints = GetGunPoints (objP, nGun)))
	return 0;
vGunPos = vGunPoints [nGun];
nSubModel = botInfoP->gunSubModels [nGun];
//instance up the tree for this gun
while (nSubModel != 0) {
	m = CFixMatrix::Create (objP->rType.polyObjInfo.animAngles [nSubModel]);
	CFixMatrix::Transpose (m);
	vRot = m * vGunPos;
	vGunPos = vRot + pm->SubModels ().offsets [nSubModel];
	nSubModel = pm->SubModels ().parents [nSubModel];
	}
//now instance for the entire CObject
//VmVecInc (&vGunPos, gameData.models.offsets + botInfoP->nModel);
*vGunPoint = *objP->View () * vGunPos;
*vGunPoint += objP->info.position.vPos;
return 1;
}
示例#2
0
//draw a polygon model
int DrawPolyModel (
	CObject*			objP,
	CFixVector*		pos,
	CFixMatrix*		orient,
	CAngleVector*	animAngles,
	int				nModel,
	int				flags,
	fix				light,
	fix*				glowValues,
	tBitmapIndex	altTextures [],
	tRgbaColorf*	colorP)
{
	CPolyModel*	modelP;
	int			nTextures, bHires = 0;

if ((gameStates.render.nShadowPass == 2) && !ObjectHasShadow (objP))
	return 1;
if (!(modelP = GetPolyModel (objP, pos, nModel, flags))) {
	if (!flags && (gameStates.render.nShadowPass != 2) && HaveHiresModel (nModel))
		bHires = 1;
	else
		return gameStates.render.nShadowPass == 2;
	}
if (gameStates.render.nShadowPass == 2) {
	if (!bHires) {
		G3SetModelPoints (gameData.models.polyModelPoints.Buffer ());
		G3DrawPolyModelShadow (objP, modelP->Data (), animAngles, nModel);
		}
	return 1;
	}
#if 1//def _DEBUG
if (nModel == nDbgModel)
	nDbgModel = nDbgModel;
#endif
nTextures = bHires ? 0 : modelP->LoadTextures (altTextures);
gameStates.ogl.bUseTransform = 1;
G3SetModelPoints (gameData.models.polyModelPoints.Buffer ());
gameData.render.vertP = gameData.models.fPolyModelVerts.Buffer ();
if (!flags) {	//draw entire CObject
	if (gameStates.app.bNostalgia || !G3RenderModel (objP, nModel, -1, modelP, gameData.models.textures, animAngles, NULL, light, glowValues, colorP)) {
		if (bHires) {
			gameStates.ogl.bUseTransform = 0;
			return 0;
			}
		if (objP && (objP->info.nType == OBJ_POWERUP)) {
			if ((objP->info.nId == POW_SMARTMINE) || (objP->info.nId == POW_PROXMINE))
				gameData.models.vScale.Set (I2X (2), I2X (2), I2X (2));
			else
				gameData.models.vScale.Set (I2X (3) / 2, I2X (3) / 2, I2X (3) / 2);
			}
		gameStates.ogl.bUseTransform = 
			(gameStates.app.bEndLevelSequence < EL_OUTSIDE) && 
			!(SHOW_DYN_LIGHT && (gameOpts->ogl.bObjLighting || gameOpts->ogl.bLightObjects));
		transformation.Begin (*pos, *orient);
		G3DrawPolyModel (objP, modelP->Data (), gameData.models.textures, animAngles, NULL, light, glowValues, colorP, NULL, nModel);
		transformation.End ();
		}
	}
else {	
	CFixVector vOffset;

	for (int i = 0; flags > 0; flags >>= 1, i++) {
		if ((flags & 1) && (i < modelP->ModelCount ())) {
			//if submodel, rotate around its center point, not pivot point
			vOffset = CFixVector::Avg (modelP->SubModels ().mins [i], modelP->SubModels ().maxs [i]);
			vOffset.Neg ();
			if (!G3RenderModel (objP, nModel, i, modelP, gameData.models.textures, animAngles, &vOffset, light, glowValues, colorP)) {
				if (bHires) {
					gameStates.ogl.bUseTransform = 0;
					return 0;
					}
#if DBG
				G3RenderModel (objP, nModel, i, modelP, gameData.models.textures, animAngles, &vOffset, light, glowValues, colorP);
#endif
				transformation.Begin (vOffset);
				G3DrawPolyModel (objP, modelP->Data () + modelP->SubModels ().ptrs [i], gameData.models.textures,
									  animAngles, NULL, light, glowValues, colorP, NULL, nModel);
				transformation.End ();
				}
			}
		}
	}
gameStates.ogl.bUseTransform = 0;
gameData.render.vertP = NULL;
#if 0
{
	g3sPoint p0, p1;

transformation.Transform (&p0.p3_vec, &objP->info.position.vPos);
VmVecSub (&p1.p3_vec, &objP->info.position.vPos, &objP->mType.physInfo.velocity);
transformation.Transform (&p1.p3_vec, &p1.p3_vec);
glLineWidth (20);
glDisable (GL_TEXTURE_2D);
glBegin (GL_LINES);
glColor4d (1.0, 0.5, 0.0, 0.3);
OglVertex3x (p0.p3_vec [X], p0.p3_vec [Y], p0.p3_vec [Z]);
glColor4d (1.0, 0.5, 0.0, 0.1);
OglVertex3x (p1.p3_vec [X], p1.p3_vec [Y], p1.p3_vec [Z]);
glEnd ();
glLineWidth (1);
}
#endif
return 1;
}