Beispiel #1
0
Matrix Quat::ToMatrix() const
{
	Quat nq = GetNormalized();
	float xx = 2.f * nq.x * nq.x;
	float yy = 2.f * nq.y * nq.y;
	float zz = 2.f * nq.z * nq.z;
	float xy = 2.f * nq.x * nq.y;
	float xz = 2.f * nq.x * nq.z;
	float wx = 2.f * nq.w * nq.x;
	float wz = 2.f * nq.w * nq.z;
	float wy = 2.f * nq.w * nq.y;
	float yz = 2.f * nq.y * nq.z;

	// http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q54
	return Matrix(
		1.f - ( yy + zz ),	xy + wz,			xz - wy,			0.f,
		xy - wz,			1.f - ( xx + zz ),	yz + wx,			0.f,
		xz + wy,			yz - wx,			1.f - ( xx + yy ),	0.f,
		0.f,				0.f,				0.f,				1.f );
}
Beispiel #2
0
double IParam::GetNormalized()
{
  return GetNormalized(mValue);
}
Beispiel #3
0
float JParam::GetNormalized() const
{
  return GetNormalized(mValue);
}
Beispiel #4
0
		const direction2 ToUnit(const direction2& dir)
		{
			return direction2(GetNormalized(dir.vec));
		}
Beispiel #5
0
	void Frustum::Update(const Matrix44<float>& aCameraOrientation, float aAspectRatio, float aFov)
	{
		float Hnear = 2.f * tan(aFov / 2.f) * myNear;
		float Wnear = Hnear * aAspectRatio;

		myPosition = aCameraOrientation.GetTranslation();
		Vector3f rightVector = GetNormalized(aCameraOrientation.GetRightVector());
		Vector3f forwardVector = GetNormalized(aCameraOrientation.GetForwardVector());
		Vector3f upVector = GetNormalized(aCameraOrientation.GetUpVector());
		
		Vector3f nc = myPosition + forwardVector * myNear;

		Vector3f ntl = nc + (upVector * Hnear / 2.f) - (rightVector * Wnear / 2.f);
		Vector3f ntr = nc + (upVector * Hnear / 2.f) + (rightVector * Wnear / 2.f);
		Vector3f nbl = nc - (upVector * Hnear / 2.f) - (rightVector * Wnear / 2.f);
		Vector3f nbr = nc - (upVector * Hnear / 2.f) + (rightVector * Wnear / 2.f);

		float Hfar = 2.f * tan(aFov / 2.f) * myFar;
		float Wfar = Hfar * aAspectRatio;

		Vector3f fc = myPosition + forwardVector * myFar;

		Vector3f ftl = fc + (upVector * Hfar / 2.f) - (rightVector * Wfar / 2.f);
		Vector3f ftr = fc + (upVector * Hfar / 2.f) + (rightVector * Wfar / 2.f);
		Vector3f fbl = fc - (upVector * Hfar / 2.f) - (rightVector * Wfar / 2.f);
		Vector3f fbr = fc - (upVector * Hfar / 2.f) + (rightVector * Wfar / 2.f);

		myPointPositions[0] = ntl;
		myPointPositions[1] = ntr;
		myPointPositions[2] = nbl;
		myPointPositions[3] = nbr;
		myPointPositions[4] = ftl;
		myPointPositions[5] = ftr;
		myPointPositions[6] = fbl;
		myPointPositions[7] = fbr;

		Plane<float> plane;
		plane.InitWith3Points(myPosition, nbr, ntr);
		myPlanes[int(eFRUSTUMSIDES::eRIGHT)] = plane;

		plane.InitWith3Points(myPosition, ntl, nbl);
		myPlanes[int(eFRUSTUMSIDES::eLEFT)] = plane;

		plane.InitWith3Points(myPosition, ntr, ntl);
		myPlanes[int(eFRUSTUMSIDES::eUP)] = plane;

		plane.InitWith3Points(myPosition, nbl, nbr);
		myPlanes[int(eFRUSTUMSIDES::eDOWN)] = plane;

		plane.InitWithPointAndNormal(myPosition + (forwardVector * myFar), forwardVector);
		myPlanes[int(eFRUSTUMSIDES::eFAR)] = plane;

		plane.InitWithPointAndNormal(myPosition + (forwardVector * myNear), (forwardVector * -1.f));
		myPlanes[int(eFRUSTUMSIDES::eNEAR)] = plane;

		myPosition += forwardVector * (myFar / 2.f);

		myLines.RemoveAll();

		//Near Plane

		myLines.Add(CU::RenderCommandLine(ntl, ntr));
		myLines.Add(CU::RenderCommandLine(ntr, nbr));
		myLines.Add(CU::RenderCommandLine(nbr, nbl));
		myLines.Add(CU::RenderCommandLine(nbl, ntl));

		//Far plane

		myLines.Add(CU::RenderCommandLine(ftl, ftr));
		myLines.Add(CU::RenderCommandLine(ftr, fbr));
		myLines.Add(CU::RenderCommandLine(fbr, fbl));
		myLines.Add(CU::RenderCommandLine(fbl, ftl));

		//Sides

		myLines.Add(CU::RenderCommandLine(ntl, ftl));
		myLines.Add(CU::RenderCommandLine(ntr, ftr));
		myLines.Add(CU::RenderCommandLine(nbr, fbr));
		myLines.Add(CU::RenderCommandLine(nbl, fbl));
	}