Пример #1
0
void SetCameraView(CAMERA *Cam, float AspectRatio)
{
	//kamerabeallitas :)

	MATRIX m;
	VECTOR3 u,dir;

	dir=V3_Normalize(V3_Sub(Cam->Target,Cam->Eye));
	M_Rotate(dir.x,dir.y,dir.z,(float)Cam->Roll*360.0f/255.0f*(float)radtheta,m);
	M_Xformd(m,Cam->Up,u); //itt keszul a rotated up vector (a rollhoz)

	Cam->i=V3_Normalize(V3_Cross(dir,u));
	Cam->j=V3_Normalize(V3_Cross(dir,Cam->i)); //kamera sikjaban egysegvektorok (billboardinghoz)

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(Cam->Fov,AspectRatio,0.1,2000.0);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	gluLookAt(Cam->Eye.x,Cam->Eye.y,Cam->Eye.z,
			  Cam->Target.x,Cam->Target.y,Cam->Target.z,
			  u.x,u.y,u.z);

}
void CalculateMapTransform(int MapXformType, int Color, MATRIX MXMatrix, OBJECT *MappedObject, VECTOR3 MoveVec, VECTOR3 ScaleVec, VECTOR3 AxisVec, float Angle)
{
	for (int x=0; x<MappedObject->VertexNum; x++)
		if (MappedObject->VertexList[x].Selected)
		{
			float weight;
			if (Color==0) weight=MappedObject->VertexList[x].Weight[0];
			if (Color==1) weight=MappedObject->VertexList[x].Weight[1];
			if (Color==2) weight=MappedObject->VertexList[x].Weight[2];
			if (Color==3) weight=MappedObject->VertexList[x].Weight[3];
			if (Color==4) weight=(MappedObject->VertexList[x].Weight[0]+MappedObject->VertexList[x].Weight[1]+MappedObject->VertexList[x].Weight[2])/3.0f;
			if (MapXformType==aDDict_SCALE)
			{//scale
				VECTOR3 SVec;
				SVec=V3_Mults(ScaleVec,weight);
				MappedObject->VertexList[x].MapTransformedPosition.x=MappedObject->VertexList[x].Position.x*(SVec.x+1);
				MappedObject->VertexList[x].MapTransformedPosition.y=MappedObject->VertexList[x].Position.y*(SVec.y+1);
				MappedObject->VertexList[x].MapTransformedPosition.z=MappedObject->VertexList[x].Position.z*(SVec.z+1);
			}
			if (MapXformType==aDDict_ROTATE)
			{//rotate

				MATRIX m;
				M_Rotate(AxisVec.x,AxisVec.y,AxisVec.z,Angle*weight,m);

				M_Xform3(m,MappedObject->VertexList[x].Position,MappedObject->VertexList[x].MapTransformedPosition);

			}
			if (MapXformType==aDDict_MOVE)
			{//move
				VECTOR3 MoveVector=V3_Mults(MoveVec,weight);

				MappedObject->VertexList[x].MapTransformedPosition=V3_Add(MappedObject->VertexList[x].Position,MoveVector);
			}

		}
		else MappedObject->VertexList[x].MapTransformedPosition=MappedObject->VertexList[x].Position;
}