Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AMath.cpp File Reference


Detailed Description

Implements the 'math_' functions in AEngine.h.

Definition in file AMath.cpp.

#include "AEngine.h"
#include "AState.h"
#include "AConstants.h"
#include "ADevice.h"
#include "ASharedFunc.h"

Include dependency graph for AMath.cpp:

Include dependency graph

Go to the source code of this file.

Functions

Vec3D math_translateScreenToWorldPlane (const Vec2D pt, FLOAT z)
Vec2D math_translateWorldToScreen (const Vec3D pt)
Vec3D math_translateObjectToWorld (const Vec3D objPos, const Vec3D objDir, const Vec3D objPt)
 converts a point in object space, given the object's xform, to absolute world space i.e. if you want to know what's the world coordinate of the tip of the wing (x+50 off the jet center) dir is a direction vector of three components { theta, phi, roll }. currently only theta is used

FLOAT math_dist2D (const Vec2D &a, const Vec2D &b)
FLOAT math_dist3D (const Vec3D &a, const Vec3D &b)
FLOAT math_distPlanar3D (const Vec3D &a, const Vec3D &b)
FLOAT math_clipAngle (FLOAT degree)
FLOAT math_getDir (const Vec3D &from, const Vec3D &to)
FLOAT math_deltaDir (const FLOAT currentDir, const FLOAT newDir)


Function Documentation

FLOAT math_clipAngle FLOAT    degree
 

Definition at line 107 of file AMath.cpp.

Referenced by math_getDir(), and Jet::move().

00108 {
00109         if( degree < 0.0f )             return degree + 360.0f;
00110         if( degree >= 360.0f )  return degree - 360.0f;
00111         return degree;
00112 }

FLOAT math_deltaDir const FLOAT    currentDir,
const FLOAT    newDir
 

Definition at line 120 of file AMath.cpp.

Referenced by BattleGroup::fire(), BattleJets::fireAntiAirMissiles(), and BattleJets::fireAntiSurfaceMissiles().

00121 {
00122         FLOAT delta;
00123         if(newDir>currentDir)
00124         {
00125                 delta = newDir - currentDir;
00126                 if(delta>180.0f) delta = delta - 360.0f;
00127         }
00128         else
00129         {
00130                 delta = newDir - currentDir;
00131                 if(delta<-180.0f) delta = 360.0f - delta;
00132         }
00133         return delta;
00134 }

FLOAT math_dist2D const Vec2D   a,
const Vec2D   b
 

Definition at line 89 of file AMath.cpp.

References Vec2D.

Referenced by MilitaryUnit::around(), MilitaryUnit::contains(), City::contains(), Overhead::overhead_update(), Overhead::processOverheadInput(), and sendReinforcement().

00090 {
00091         Vec2D delta = a-b;
00092         return D3DXVec2Length(&delta);
00093 }

FLOAT math_dist3D const Vec3D   a,
const Vec3D   b
 

Definition at line 95 of file AMath.cpp.

References Vec3D.

Referenced by BattleGroup::acquireGroupTargets(), BattleEntry::contains(), BattleEntry::input(), BattleGroup::moveBattleGroup(), BattleGroup::moveUnits(), and Overhead::overheadRender().

00096 {
00097         Vec3D delta = a-b;
00098         return D3DXVec3Length(&delta);
00099 }

FLOAT math_distPlanar3D const Vec3D   a,
const Vec3D   b
 

Definition at line 101 of file AMath.cpp.

References Vec3D.

Referenced by BattleGroup::acquireGroupTargets(), MilitaryUnit::fightingCollision(), BattleGroup::fire(), BattleGroup::fireAntiAir(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), Overhead::getSurroundingUnits(), Jet::goal(), BattleEntry::input(), MilitaryUnit::nearEachOther(), BattleEntry::renderInterface(), BattleJets::takeHit(), and BattleJets::update().

00102 {
00103         Vec3D delta = a-b;
00104         return sqrtf( delta.x*delta.x + delta.y*delta.y );
00105 }

FLOAT math_getDir const Vec3D   from,
const Vec3D   to
 

Definition at line 114 of file AMath.cpp.

References math_clipAngle(), and Vec3D.

Referenced by BattleGroup::fire(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), and Jet::goal().

00115 {
00116         Vec3D targetVec = to - from;
00117         return math_clipAngle( 90-D3DXToDegree( atan2f( targetVec.x, targetVec.y ) ) );
00118 }

Vec3D math_translateObjectToWorld const Vec3D    objPos,
const Vec3D    objDir,
const Vec3D    objPt
 

converts a point in object space, given the object's xform, to absolute world space i.e. if you want to know what's the world coordinate of the tip of the wing (x+50 off the jet center) dir is a direction vector of three components { theta, phi, roll }. currently only theta is used

Definition at line 77 of file AMath.cpp.

References Matx, and Vec3D.

Referenced by BattleGroup::BattleGroup(), BattleGroup::drawOutlineBox(), BattleGroup::isContain2DPoint(), BattleGroup::moveUnits(), and BattleJets::render().

00078 {
00079         Matx matTrans, matTheta, matFinal;
00080         Vec3D result;
00081 
00082         D3DXMatrixTranslation( &matTrans, objPos[0], objPos[1], objPos[2] );
00083         D3DXMatrixRotationZ( &matTheta, D3DXToRadian(objDir[0]) );      
00084         matFinal = matTheta * matTrans;
00085         D3DXVec3TransformCoord( &result, &objPt, &matFinal );
00086         return result;
00087 }

Vec3D math_translateScreenToWorldPlane const Vec2D    pt,
FLOAT    z
 

Definition at line 31 of file AMath.cpp.

References Vec3D.

Referenced by BattleEntry::inputIssueGroupCommand(), BattleEntry::inputIssueJetsCommand(), Overhead::overheadRender(), Overhead::processOverheadInput(), and BattleEntry::renderInterface().

00032 {
00033         // Get screen space vector
00034         Vec3D v;
00035     v.x =  ( 2.0f*pt[0] - 1 ) / AS.camera_projMatrix._11;
00036     v.y = -( 2.0f*pt[1] - 1 ) / AS.camera_projMatrix._22;
00037     v.z =  1.0f;
00038 
00039         // Get the inverse view matrix
00040     D3DXMATRIX inv;
00041         D3DXMatrixInverse( &inv, NULL, &AS.camera_viewMatrix );
00042         
00043     // Transform to world space vector
00044         Vec3D pt1, pt2, dir;
00045     dir.x  = v.x*inv._11 + v.y*inv._21 + v.z*inv._31;
00046     dir.y  = v.x*inv._12 + v.y*inv._22 + v.z*inv._32;
00047     dir.z  = v.x*inv._13 + v.y*inv._23 + v.z*inv._33;
00048     pt1.x = inv._41;
00049     pt1.y = inv._42;
00050     pt1.z = inv._43;
00051         pt2 = pt1 + 10000.0f * dir;
00052 
00053         // construct a plane with specified height
00054         D3DXPLANE plane;
00055         Vec3D planePt(0,0,z), planeNormal(0,0,1);
00056         D3DXPlaneFromPointNormal( &plane, &planePt, &planeNormal );
00057 
00058         // find where the vector intersect with the plane
00059         Vec3D intersectPt;
00060         D3DXPlaneIntersectLine( &intersectPt, &plane, &pt1, &pt2 );
00061 
00062         return intersectPt;
00063 }

Vec2D math_translateWorldToScreen const Vec3D    pt
 

Definition at line 65 of file AMath.cpp.

References Vec2D, and Vec3D.

Referenced by MilitaryUnit::contains(), City::contains(), MilitaryUnit::drawColor(), BattleGroup::drawOutlineBox(), City::drawSelectBox(), BattleGroup::isContain2DPoint(), Overhead::overheadRender(), Overhead::processOverheadInput(), BattleGroup::render(), BattleEntry::renderGroups(), and BattleEntry::renderInterface().

00066 {       
00067         Vec3D scrPt;
00068         D3DXVec3TransformCoord( &scrPt, &pt, &AS.camera_world2projMatrix );
00069         if(scrPt.z > 1)                         // fix "off-screen line clipping bug"
00070         {
00071                 scrPt.x = -scrPt.x;
00072                 scrPt.y = -scrPt.y;
00073         }
00074         return Vec2D( 0.5f+0.5f*scrPt[0], 0.5f-0.5f*scrPt[1] );
00075 }


Generated on Wed Apr 23 05:50:29 2003 for Modern Warfare by doxygen1.3-rc2