Пример #1
0
MFMatrix& MFMatrix::SetRotationYPR(float yaw, float pitch, float roll)
{
	float cosy = MFCos(yaw);
	float siny = MFSin(yaw);
	float cosp = MFCos(pitch);
	float sinp = MFSin(pitch);
	float cosr = MFCos(roll);
	float sinr = MFSin(roll);

	m[0] =  cosr * cosy + sinp * sinr * siny;
	m[1] =  cosp * sinr;
	m[2] =  cosy * sinp * sinr - cosr * siny;

	m[4] = -cosy * sinr + cosr * sinp * siny;
	m[5] =  cosp * cosr;
	m[6] =  cosr * cosy * sinp + sinr * siny;

	m[8] =  cosp * siny;
	m[9] = -sinp;
	m[10] =  cosp * cosy;

	m[3] = m[7] = m[11] = m[12] = m[13] = m[14] = 0.0f;
	m[15] = 1.0f;

	return *this;
}
Пример #2
0
MFVector MD3DecodeNormal(unsigned short code)
{
	float latitude = ((float)(code & 0xFF)) * (2 * MFPI) / ((float)255);
	float longtitude = ((float)((code >> 8) & 0xFF)) * (2 * MFPI) / ((float)255);

	return MakeVector(-(float)(MFCos(latitude) * MFSin(longtitude)), -(float)(MFSin(latitude) * MFSin(longtitude)), -(float)(MFCos(longtitude)));
}
Пример #3
0
MFMatrix& MFMatrix::SetRotation(const MFVector &axis, float angle)
{
	float c,s,t;

	// do the trig
	s = MFSin(angle);
	c = MFCos(angle);
	t = 1.0f-c;

	// build the rotation matrix
	m[0] = t*axis.x*axis.x + c;
	m[4] = t*axis.x*axis.y - s*axis.z;
	m[8] = t*axis.x*axis.z + s*axis.y;

	m[1] = t*axis.x*axis.y + s*axis.z;
	m[5] = t*axis.y*axis.y + c;
	m[9] = t*axis.y*axis.z - s*axis.x;

	m[2] = t*axis.x*axis.z - s*axis.y;
	m[6] = t*axis.y*axis.z + s*axis.x;
	m[10] = t*axis.z*axis.z + c;

	m[12] = m[13] = m[14] = m[3]= m[7] = m[11] = 0.0f;
	m[15] = 1.0f;

	return *this;
}
Пример #4
0
MFMatrix& MFMatrix::SetPerspective(float fov, float near, float far, float aspectRatio)
{
	// construct perspective projection
	float zn = near;
	float zf = far;

	float a = fov * 0.5f;

	float h = MFCos(a) / MFSin(a);
	float w = h / aspectRatio;

	float zd = zf-zn;
	float zs = zf/zd;

#if defined(_OPENGL_CLIP_SPACE)
	m[0] = w;		m[1] = 0.0f;	m[2] = 0.0f;			m[3] = 0.0f;
	m[4] = 0.0f;	m[5] = h;		m[6] = 0.0f;			m[7] = 0.0f;
	m[8] = 0.0f;	m[9] = 0.0f;	m[10] = 2.0f*zs;		m[11] = 1.0f;
	m[12] = 0.0f;	m[13] = 0.0f;	m[14] = -2.0f*zn*zs-zf;	m[15] = 0.0f;
#else
	m[0] = w;		m[1] = 0.0f;	m[2] = 0.0f;			m[3] = 0.0f;
	m[4] = 0.0f;	m[5] = h;		m[6] = 0.0f;			m[7] = 0.0f;
	m[8] = 0.0f;	m[9] = 0.0f;	m[10] = zs;				m[11] = 1.0f;
	m[12] = 0.0f;	m[13] = 0.0f;	m[14] = -zn*zs;			m[15] = 0.0f;
#endif

	return *this;
}
Пример #5
0
MFMatrix& MFMatrix::SetRotationZ(float angle)
{
	m[0] = MFCos(angle);
	m[1] = MFSin(angle);
	m[2] = 0.0f;
	m[4] = -MFSin(angle);
	m[5] = MFCos(angle);
	m[6] = 0.0f;
	m[8] = 0.0f;
	m[9] = 0.0f;
	m[10] = 1.0f;
	m[12] = m[13] = m[14] = 0.0f;
	m[15] = 1.0f;

	return *this;
}
Пример #6
0
void MFParticleSystem_DrawRotating(MFParticleSystem *pParticleSystem, const MFMatrix &ltv)
{
	int numParticles = pParticleSystem->particles.GetLength();
	if(!numParticles)
		return;

	float fadeStart = pParticleSystem->params.life - pParticleSystem->params.fadeDelay;

	MFMaterial_SetMaterial(pParticleSystem->pMaterial);

	MFPrimitive(PT_TriList, 0);
	MFBegin(numParticles * 6);

	MFParticle **ppI = pParticleSystem->particles.Begin();

	while(*ppI)
	{
		MFParticle *pParticle = *ppI;

		float dt = MFSystem_TimeDelta();

		pParticle->rot += pParticleSystem->params.rotationRate * dt;
		pParticle->size += pParticleSystem->params.scaleRate * dt;
		pParticle->velocity += pParticleSystem->params.force * dt;
		pParticle->pos += pParticle->velocity * dt;

		float t = pParticle->size * 0.5f;
		float rad = MFSqrt(t*t*2);
		float xoff = MFCos(-pParticle->rot + 0.7853981f)*rad;
		float yoff = MFSin(-pParticle->rot + 0.7853981f)*rad;
		float alpha = MFMin(pParticle->life / fadeStart, 1.0f);

		MFVector pos = ApplyMatrixH(pParticle->pos, ltv);

		MFSetColourV(MakeVector(pParticle->colour, pParticle->colour.w * alpha));
		MFSetTexCoord1(1, 0);
		MFSetPosition(pos.x + xoff, pos.y + yoff, pos.z);
		MFSetTexCoord1(0, 1);
		MFSetPosition(pos.x - xoff, pos.y - yoff, pos.z);
		MFSetTexCoord1(0, 0);
		MFSetPosition(pos.x - yoff, pos.y + xoff, pos.z);
		MFSetTexCoord1(1, 0);
		MFSetPosition(pos.x + xoff, pos.y + yoff, pos.z);
		MFSetTexCoord1(1, 1);
		MFSetPosition(pos.x + yoff, pos.y - xoff, pos.z);
		MFSetTexCoord1(0, 1);
		MFSetPosition(pos.x - xoff, pos.y - yoff, pos.z);

		pParticle->life -= dt;
		if(pParticle->life < 0.0f)
			pParticleSystem->particles.Destroy(ppI);

		ppI++;
	}

	MFEnd();
}
Пример #7
0
void CalcNormTable()
{
	float pitch;
	float yaw;

	for(int i=0; i<256; ++i)
	{
		pitch = (i/255.0f)*MFPI;

		for(int j = 0; j<256; ++j)
		{
			yaw = (j/255.0f)*(MFPI*2);

			gNormTable[i][j].x = (float)(MFSin(yaw) * MFSin(pitch));
			gNormTable[i][j].y = (float)MFCos(pitch);
			gNormTable[i][j].z = (float)(MFCos(yaw) * MFSin(pitch));
		}
	}
}