From 9f784e81f81651bed087902f9f3afee113e56148 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Tue, 19 Jun 2012 20:11:47 +0200 Subject: Switched to new implementation of the rest of math module - changed structs from D3DVECTOR to Math::Vector and from D3DMATRIX to Math::Matrix - changed functions to new Math namespace functions - moved mainmovie module from graphics to object - added Get and Set to Math::Matrix --- src/graphics/common/blitz.cpp | 24 ++- src/graphics/common/blitz.h | 4 +- src/graphics/common/camera.cpp | 164 ++++++++-------- src/graphics/common/camera.h | 52 ++--- src/graphics/common/cloud.cpp | 28 ++- src/graphics/common/cloud.h | 4 +- src/graphics/common/light.cpp | 23 +-- src/graphics/common/light.h | 8 +- src/graphics/common/mainmovie.cpp | 247 ------------------------ src/graphics/common/mainmovie.h | 80 -------- src/graphics/common/model.cpp | 78 ++++---- src/graphics/common/model.h | 12 +- src/graphics/common/particule.cpp | 270 ++++++++++++++------------ src/graphics/common/particule.h | 40 ++-- src/graphics/common/planet.cpp | 12 +- src/graphics/common/pyro.cpp | 69 +++---- src/graphics/common/pyro.h | 18 +- src/graphics/common/terrain.cpp | 118 ++++++------ src/graphics/common/terrain.h | 56 +++--- src/graphics/common/text.cpp | 40 ++-- src/graphics/common/water.cpp | 59 +++--- src/graphics/common/water.h | 12 +- src/graphics/d3d/d3dengine.cpp | 393 ++++++++++++++++++++++++-------------- src/graphics/d3d/d3dengine.h | 68 +++---- 24 files changed, 853 insertions(+), 1026 deletions(-) delete mode 100644 src/graphics/common/mainmovie.cpp delete mode 100644 src/graphics/common/mainmovie.h (limited to 'src/graphics') diff --git a/src/graphics/common/blitz.cpp b/src/graphics/common/blitz.cpp index 9bf5a93..10c78e5 100644 --- a/src/graphics/common/blitz.cpp +++ b/src/graphics/common/blitz.cpp @@ -22,6 +22,7 @@ #include "common/struct.h" #include "math/const.h" #include "math/geometry.h" +#include "math/conv.h" #include "graphics/d3d/d3dengine.h" #include "math/old/d3dmath.h" #include "graphics/d3d/d3dutil.h" @@ -99,7 +100,7 @@ bool CBlitz::EventFrame(const Event &event) CObject* pObj; CAutoPara* automat; ObjectType type; - D3DVECTOR eye, pos; + Math::Vector eye, pos; float dist, deep, max; int i; @@ -153,7 +154,7 @@ bool CBlitz::EventFrame(const Event &event) } eye = m_engine->RetEyePt(); - dist = Length(m_pos, eye); + dist = Math::Distance(m_pos, eye); deep = m_engine->RetDeepView(); if ( dist < deep ) @@ -213,8 +214,8 @@ void CBlitz::Draw() { LPDIRECT3DDEVICE7 device; D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR corner[4], eye, n, p, p1, p2; - D3DMATRIX matrix; + Math::Vector corner[4], eye, n, p, p1, p2; + Math::Matrix matrix; Math::Point texInf, texSup, rot; float a; int i; @@ -225,8 +226,11 @@ void CBlitz::Draw() device = m_engine->RetD3DDevice(); device->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false); - D3DUtil_SetIdentityMatrix(matrix); - device->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + device->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } m_engine->SetTexture("effect00.tga"); m_engine->SetState(D3DSTATETTb); @@ -358,10 +362,10 @@ bool CBlitz::SetStatus(float sleep, float delay, float magnetic, float progress) // Seeking the object closest to the lightning. -CObject* CBlitz::SearchObject(D3DVECTOR pos) +CObject* CBlitz::SearchObject(Math::Vector pos) { CObject *pObj, *pBest, *pObjPara[100]; - D3DVECTOR oPos, pPos[100]; + Math::Vector oPos, pPos[100]; ObjectType type; float min, dist, detect; int i, nbPara; @@ -446,7 +450,7 @@ CObject* CBlitz::SearchObject(D3DVECTOR pos) if ( detect == 0.0f ) continue; oPos = pObj->RetPosition(0); - dist = Length2d(oPos, pos); + dist = Math::DistanceProjected(oPos, pos); if ( dist > detect ) continue; if ( dist < min ) { @@ -460,7 +464,7 @@ CObject* CBlitz::SearchObject(D3DVECTOR pos) oPos = pBest->RetPosition(0); for ( i=nbPara-1 ; i>=0 ; i-- ) { - dist = Length2d(oPos, pPos[i]); + dist = Math::DistanceProjected(oPos, pPos[i]); if ( dist <= BLITZPARA ) { return pObjPara[i]; diff --git a/src/graphics/common/blitz.h b/src/graphics/common/blitz.h index a4e47a6..c2cfe6c 100644 --- a/src/graphics/common/blitz.h +++ b/src/graphics/common/blitz.h @@ -59,7 +59,7 @@ public: protected: bool EventFrame(const Event &event); - CObject* SearchObject(D3DVECTOR pos); + CObject* SearchObject(Math::Vector pos); protected: CInstanceManager* m_iMan; @@ -76,7 +76,7 @@ protected: float m_time; float m_speed; float m_progress; - D3DVECTOR m_pos; + Math::Vector m_pos; Math::Point m_shift[BLITZMAX]; float m_width[BLITZMAX]; }; diff --git a/src/graphics/common/camera.cpp b/src/graphics/common/camera.cpp index 1298c3c..1de5d45 100644 --- a/src/graphics/common/camera.cpp +++ b/src/graphics/common/camera.cpp @@ -56,12 +56,12 @@ CCamera::CCamera(CInstanceManager* iMan) m_eyeDistance = 10.0f; m_initDelay = 0.0f; - m_actualEye = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_actualLookat = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_finalEye = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_finalLookat = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_normEye = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_normLookat = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_actualEye = Math::Vector(0.0f, 0.0f, 0.0f); + m_actualLookat = Math::Vector(0.0f, 0.0f, 0.0f); + m_finalEye = Math::Vector(0.0f, 0.0f, 0.0f); + m_finalLookat = Math::Vector(0.0f, 0.0f, 0.0f); + m_normEye = Math::Vector(0.0f, 0.0f, 0.0f); + m_normLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_focus = 1.0f; m_bRightDown = false; @@ -69,7 +69,7 @@ CCamera::CCamera(CInstanceManager* iMan) m_rightPosCenter = Math::Point(0.5f, 0.5f); m_rightPosMove = Math::Point(0.5f, 0.5f); - m_eyePt = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); m_directionH = 0.0f; m_directionV = 0.0f; m_heightEye = 20.0f; @@ -86,7 +86,7 @@ CCamera::CCamera(CInstanceManager* iMan) m_fixDirectionH = 0.0f; m_fixDirectionV = 0.0f; - m_visitGoal = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_visitGoal = Math::Vector(0.0f, 0.0f, 0.0f); m_visitDist = 0.0f; m_visitTime = 0.0f; m_visitType = CAMERA_NULL; @@ -114,13 +114,13 @@ CCamera::CCamera(CInstanceManager* iMan) m_centeringProgress = 0.0f; m_effectType = CE_NULL; - m_effectPos = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_effectPos = Math::Vector(0.0f, 0.0f, 0.0f); m_effectForce = 0.0f; m_effectProgress = 0.0f; - m_effectOffset = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); - m_scriptEye = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_scriptLookat = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_scriptEye = Math::Vector(0.0f, 0.0f, 0.0f); + m_scriptLookat = Math::Vector(0.0f, 0.0f, 0.0f); m_bEffect = true; m_bCameraScroll = true; @@ -168,9 +168,9 @@ float CCamera::RetMotorTurn() // Initializes the camera. -void CCamera::Init(D3DVECTOR eye, D3DVECTOR lookat, float delay) +void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) { - D3DVECTOR vUpVec; + Math::Vector vUpVec; m_initDelay = delay; @@ -181,7 +181,7 @@ void CCamera::Init(D3DVECTOR eye, D3DVECTOR lookat, float delay) m_eyePt = eye; m_directionH = Math::RotateAngle(eye.x-lookat.x, eye.z-lookat.z)+Math::PI/2.0f; - m_directionV = -Math::RotateAngle(Length2d(eye, lookat), eye.y-lookat.y); + m_directionV = -Math::RotateAngle(Math::DistanceProjected(eye, lookat), eye.y-lookat.y); m_eyeDistance = 10.0f; m_heightLookat = 10.0f; @@ -194,7 +194,7 @@ void CCamera::Init(D3DVECTOR eye, D3DVECTOR lookat, float delay) m_fixDirectionV = -Math::PI*0.10f; m_centeringPhase = CP_NULL; m_actualEye = m_eyePt; - m_actualLookat = LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); + m_actualLookat = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); m_finalEye = m_actualEye; m_finalLookat = m_actualLookat; m_scriptEye = m_actualEye; @@ -250,7 +250,7 @@ void CCamera::SetType(CameraType type) { CObject* pObj; ObjectType oType; - D3DVECTOR vUpVec; + Math::Vector vUpVec; int i; m_remotePan = 0.0f; @@ -287,39 +287,39 @@ void CCamera::SetType(CameraType type) m_engine->SetFocus(m_focus); // gives initial focus m_type = type; - vUpVec = D3DVECTOR(0.0f, 1.0f, 0.0f); + vUpVec = Math::Vector(0.0f, 1.0f, 0.0f); SetViewParams(m_normEye, m_normLookat, vUpVec); return; } if ( m_type == CAMERA_BACK && type == CAMERA_FREE ) // back -> free ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); } if ( m_type == CAMERA_BACK && type == CAMERA_EDIT ) // back -> edit ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -1.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -1.0f); } if ( m_type == CAMERA_ONBOARD && type == CAMERA_FREE ) // onboard -> free ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); } if ( m_type == CAMERA_ONBOARD && type == CAMERA_EDIT ) // onboard -> edit ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); } if ( m_type == CAMERA_ONBOARD && type == CAMERA_EXPLO ) // onboard -> explo ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); } if ( m_type == CAMERA_BACK && type == CAMERA_EXPLO ) // back -> explo ? { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, -20.0f); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -20.0f); } if ( type == CAMERA_FIX || @@ -483,7 +483,7 @@ float CCamera::RetRemoteZoom() // Start with a tour round the camera. -void CCamera::StartVisit(D3DVECTOR goal, float dist) +void CCamera::StartVisit(Math::Vector goal, float dist) { m_visitType = m_type; SetType(CAMERA_VISIT); @@ -504,10 +504,10 @@ void CCamera::StopVisit() // Returns the point of view of the camera. -void CCamera::RetCamera(D3DVECTOR &eye, D3DVECTOR &lookat) +void CCamera::RetCamera(Math::Vector &eye, Math::Vector &lookat) { eye = m_eyePt; - lookat = LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); + lookat = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); } @@ -595,12 +595,12 @@ void CCamera::FlushEffect() m_effectType = CE_NULL; m_effectForce = 0.0f; m_effectProgress = 0.0f; - m_effectOffset = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); } // Starts a special effect with the camera. -void CCamera::StartEffect(CameraEffect effect, D3DVECTOR pos, float force) +void CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) { if ( !m_bEffect ) return; @@ -621,7 +621,7 @@ void CCamera::EffectFrame(const Event &event) if ( m_effectType == CE_NULL ) return; - m_effectOffset = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); force = m_effectForce; if ( m_effectType == CE_TERRAFORM ) @@ -678,7 +678,7 @@ void CCamera::EffectFrame(const Event &event) m_effectOffset.z = (Math::Rand()-0.5f)*0.2f; } - dist = Length(m_eyePt, m_effectPos); + dist = Math::Distance(m_eyePt, m_effectPos); dist = Math::Norm((dist-100.f)/100.0f); force *= 1.0f-dist; @@ -715,7 +715,7 @@ void CCamera::SetOverBaseColor(D3DCOLORVALUE color) // Starts a layering effect in the foreground. -void CCamera::StartOver(OverEffect effect, D3DVECTOR pos, float force) +void CCamera::StartOver(OverEffect effect, Math::Vector pos, float force) { D3DCOLOR color; float dist, decay; @@ -725,7 +725,7 @@ void CCamera::StartOver(OverEffect effect, D3DVECTOR pos, float force) if ( m_overType == OE_BLITZ ) decay = 400.0f; else decay = 100.0f; - dist = Length(m_eyePt, pos); + dist = Math::Distance(m_eyePt, pos); dist = (dist-decay)/decay; if ( dist < 0.0f ) dist = 0.0f; if ( dist > 1.0f ) dist = 1.0f; @@ -898,11 +898,11 @@ void CCamera::FixCamera() // Specifies the location and direction of view to the 3D engine. -void CCamera::SetViewTime(const D3DVECTOR &vEyePt, - const D3DVECTOR &vLookatPt, +void CCamera::SetViewTime(const Math::Vector &vEyePt, + const Math::Vector &vLookatPt, float rTime) { - D3DVECTOR vUpVec, eye, lookat; + Math::Vector vUpVec, eye, lookat; float prog, dist, h; if ( m_type == CAMERA_INFO ) @@ -927,7 +927,7 @@ void CCamera::SetViewTime(const D3DVECTOR &vEyePt, m_finalLookat = lookat; } - dist = Length(m_finalEye, m_actualEye); + dist = Math::Distance(m_finalEye, m_actualEye); if ( m_smooth == CS_NONE ) prog = dist; if ( m_smooth == CS_NORM ) prog = powf(dist, 1.5f)*rTime*0.5f; if ( m_smooth == CS_HARD ) prog = powf(dist, 1.0f)*rTime*4.0f; @@ -942,7 +942,7 @@ void CCamera::SetViewTime(const D3DVECTOR &vEyePt, m_actualEye = (m_finalEye-m_actualEye)/dist*prog + m_actualEye; } - dist = Length(m_finalLookat, m_actualLookat); + dist = Math::Distance(m_finalLookat, m_actualLookat); if ( m_smooth == CS_NONE ) prog = dist; if ( m_smooth == CS_NORM ) prog = powf(dist, 1.5f)*rTime*2.0f; if ( m_smooth == CS_HARD ) prog = powf(dist, 1.0f)*rTime*4.0f; @@ -969,14 +969,14 @@ void CCamera::SetViewTime(const D3DVECTOR &vEyePt, lookat = m_effectOffset+m_actualLookat; } - vUpVec = D3DVECTOR(0.0f, 1.0f, 0.0f); + vUpVec = Math::Vector(0.0f, 1.0f, 0.0f); SetViewParams(eye, lookat, vUpVec); } // Avoid the obstacles. -bool CCamera::IsCollision(D3DVECTOR &eye, D3DVECTOR lookat) +bool CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) { if ( m_type == CAMERA_BACK ) return IsCollisionBack(eye, lookat); if ( m_type == CAMERA_FIX ) return IsCollisionFix(eye, lookat); @@ -986,11 +986,11 @@ bool CCamera::IsCollision(D3DVECTOR &eye, D3DVECTOR lookat) // Avoid the obstacles. -bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) +bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) { #if 0 CObject *pObj; - D3DVECTOR oPos, min, max, proj; + Math::Vector oPos, min, max, proj; ObjectType oType, iType; float oRadius, dpp, dpl, del, dist, len, prox; int i; @@ -1061,22 +1061,22 @@ bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) if ( iType == OBJECT_FACTORY ) { - dpl = Length(oPos, lookat); + dpl = Math::Distance(oPos, lookat); if ( dpl < oRadius ) continue; } proj = Projection(eye, lookat, oPos); - dpp = Length(proj, oPos); + dpp = Math::Distance(proj, oPos); if ( dpp > oRadius ) continue; - del = Length(eye, lookat); - len = Length(eye, proj); + del = Math::Distance(eye, lookat); + len = Math::Distance(eye, proj); if ( len > del ) continue; dist = sqrtf(oRadius*oRadius + dpp*dpp)-3.0f; if ( dist < 0.0f ) dist = 0.0f; proj = (lookat-eye)*dist/del + proj; - len = Length(eye, proj); + len = Math::Distance(eye, proj); if ( len < del-prox ) { @@ -1094,7 +1094,7 @@ bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) return false; #else CObject *pObj; - D3DVECTOR oPos, min, max, proj; + Math::Vector oPos, min, max, proj; ObjectType oType, iType; float oRadius, dpp, del, len, angle; int i; @@ -1168,7 +1168,7 @@ bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) oPos.z-oRadius > max.z ) continue; proj = Projection(m_actualEye, m_actualLookat, oPos); - dpp = Length(proj, oPos); + dpp = Math::Distance(proj, oPos); if ( dpp > oRadius ) continue; if ( oType == OBJECT_FACTORY ) @@ -1178,13 +1178,13 @@ bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) if ( fabs(angle) < 30.0f*Math::PI/180.0f ) continue; // in the gate? } - del = Length(m_actualEye, m_actualLookat); + del = Math::Distance(m_actualEye, m_actualLookat); if ( oType == OBJECT_FACTORY ) { del += oRadius; } - len = Length(m_actualEye, proj); + len = Math::Distance(m_actualEye, proj); if ( len > del ) continue; SetTransparency(pObj, 1.0f); // transparent object @@ -1196,10 +1196,10 @@ bool CCamera::IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat) // Avoid the obstacles. -bool CCamera::IsCollisionFix(D3DVECTOR &eye, D3DVECTOR lookat) +bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) { CObject *pObj; - D3DVECTOR oPos, proj; + Math::Vector oPos, proj; ObjectType type; float oRadius, dist; int i; @@ -1233,10 +1233,10 @@ bool CCamera::IsCollisionFix(D3DVECTOR &eye, D3DVECTOR lookat) pObj->GetGlobalSphere(oPos, oRadius); if ( oRadius == 0.0f ) continue; - dist = Length(eye, oPos); + dist = Math::Distance(eye, oPos); if ( dist < oRadius ) { - dist = Length(eye, lookat); + dist = Math::Distance(eye, lookat); proj = Projection(eye, lookat, oPos); eye = (lookat-eye)*oRadius/dist + proj; return false; @@ -1484,7 +1484,7 @@ D3DMouse CCamera::RetMouseDef(Math::Point pos) bool CCamera::EventFrameFree(const Event &event) { - D3DVECTOR pos, vLookatPt; + Math::Vector pos, vLookatPt; float factor; factor = m_heightEye*0.5f+30.0f; @@ -1495,22 +1495,22 @@ bool CCamera::EventFrameFree(const Event &event) } if ( m_mouseDirV != 0.0f ) { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV*event.rTime*factor*m_speed); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV*event.rTime*factor*m_speed); } // Up/Down. - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, event.axeY*event.rTime*factor*m_speed); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, event.axeY*event.rTime*factor*m_speed); // Left/Right. if ( event.keyState & KS_CONTROL ) { if ( event.axeX < 0.0f ) { - m_eyePt = LookatPoint(m_eyePt, m_directionH+Math::PI/2.0f, m_directionV, -event.axeX*event.rTime*factor*m_speed); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH+Math::PI/2.0f, m_directionV, -event.axeX*event.rTime*factor*m_speed); } if ( event.axeX > 0.0f ) { - m_eyePt = LookatPoint(m_eyePt, m_directionH-Math::PI/2.0f, m_directionV, event.axeX*event.rTime*factor*m_speed); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH-Math::PI/2.0f, m_directionV, event.axeX*event.rTime*factor*m_speed); } } else @@ -1552,7 +1552,7 @@ bool CCamera::EventFrameFree(const Event &event) } - vLookatPt = LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); + vLookatPt = Math::LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); if ( m_terrain->MoveOnFloor(vLookatPt, true) ) { @@ -1568,7 +1568,7 @@ bool CCamera::EventFrameFree(const Event &event) bool CCamera::EventFrameEdit(const Event &event) { - D3DVECTOR pos, vLookatPt; + Math::Vector pos, vLookatPt; float factor; factor = m_editHeight*0.5f+30.0f; @@ -1579,7 +1579,7 @@ bool CCamera::EventFrameEdit(const Event &event) } if ( m_mouseDirV != 0.0f ) { - m_eyePt = LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV*event.rTime*factor*m_speed); + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV*event.rTime*factor*m_speed); } if ( m_bCameraScroll ) @@ -1612,7 +1612,7 @@ bool CCamera::EventFrameEdit(const Event &event) } - vLookatPt = LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); + vLookatPt = Math::LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); if ( m_terrain->MoveOnFloor(vLookatPt, true) ) { @@ -1637,7 +1637,7 @@ bool CCamera::EventFrameBack(const Event &event) { CPhysics* physics; ObjectType type; - D3DVECTOR pos, vLookatPt; + Math::Vector pos, vLookatPt; Math::Point mouse; float centeringH, centeringV, centeringD, h, v, d, floor; @@ -1838,7 +1838,7 @@ bool CCamera::EventFrameBack(const Event &event) bool CCamera::EventFrameFix(const Event &event) { - D3DVECTOR pos, vLookatPt; + Math::Vector pos, vLookatPt; float h, v, d; // +/-. @@ -1898,7 +1898,7 @@ bool CCamera::EventFrameFix(const Event &event) bool CCamera::EventFrameExplo(const Event &event) { - D3DVECTOR pos, vLookatPt; + Math::Vector pos, vLookatPt; float factor; factor = m_heightEye*0.5f+30.0f; @@ -1926,7 +1926,7 @@ bool CCamera::EventFrameExplo(const Event &event) } - vLookatPt = LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); + vLookatPt = Math::LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f ); if ( m_terrain->MoveOnFloor(vLookatPt, true) ) { @@ -1942,7 +1942,7 @@ bool CCamera::EventFrameExplo(const Event &event) bool CCamera::EventFrameOnBoard(const Event &event) { - D3DVECTOR vLookatPt, vUpVec, eye, lookat, pos; + Math::Vector vLookatPt, vUpVec, eye, lookat, pos; if ( m_cameraObj != 0 ) { @@ -1962,8 +1962,8 @@ bool CCamera::EventFrameOnBoard(const Event &event) bool CCamera::EventFrameInfo(const Event &event) { - SetViewTime(D3DVECTOR(0.0f, 0.0f, 0.0f), - D3DVECTOR(0.0f, 0.0f, 1.0f), + SetViewTime(Math::Vector(0.0f, 0.0f, 0.0f), + Math::Vector(0.0f, 0.0f, 1.0f), event.rTime); return true; } @@ -1972,7 +1972,7 @@ bool CCamera::EventFrameInfo(const Event &event) bool CCamera::EventFrameVisit(const Event &event) { - D3DVECTOR eye; + Math::Vector eye; float angleH, angleV; m_visitTime += event.rTime; @@ -2027,12 +2027,12 @@ bool CCamera::EventFrameScript(const Event &event) return true; } -void CCamera::SetScriptEye(D3DVECTOR eye) +void CCamera::SetScriptEye(Math::Vector eye) { m_scriptEye = eye; } -void CCamera::SetScriptLookat(D3DVECTOR lookat) +void CCamera::SetScriptLookat(Math::Vector lookat) { m_scriptLookat = lookat; } @@ -2040,8 +2040,8 @@ void CCamera::SetScriptLookat(D3DVECTOR lookat) // Specifies the location and direction of view. -void CCamera::SetViewParams(const D3DVECTOR &eye, const D3DVECTOR &lookat, - const D3DVECTOR &up) +void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, + const Math::Vector &up) { bool bUnder; @@ -2055,16 +2055,16 @@ void CCamera::SetViewParams(const D3DVECTOR &eye, const D3DVECTOR &lookat, // Adjusts the camera not to enter the field. -D3DVECTOR CCamera::ExcludeTerrain(D3DVECTOR eye, D3DVECTOR lookat, +Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV) { - D3DVECTOR pos; + Math::Vector pos; float dist; pos = eye; if ( m_terrain->MoveOnFloor(pos) ) { - dist = Length2d(lookat, pos); + dist = Math::DistanceProjected(lookat, pos); pos.y += 2.0f+dist*0.1f; if ( pos.y > eye.y ) { @@ -2077,11 +2077,11 @@ D3DVECTOR CCamera::ExcludeTerrain(D3DVECTOR eye, D3DVECTOR lookat, // Adjusts the camera not to enter an object. -D3DVECTOR CCamera::ExcludeObject(D3DVECTOR eye, D3DVECTOR lookat, +Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV) { CObject* pObj; - D3DVECTOR oPos; + Math::Vector oPos; float oRad, dist; int i, j; @@ -2095,7 +2095,7 @@ return eye; j = 0; while ( pObj->GetCrashSphere(j++, oPos, oRad) ) { - dist = Length(oPos, eye); + dist = Math::Distance(oPos, eye); if ( dist < oRad+2.0f ) { eye.y = oPos.y+oRad+2.0f; diff --git a/src/graphics/common/camera.h b/src/graphics/common/camera.h index 433a458..21ff2c9 100644 --- a/src/graphics/common/camera.h +++ b/src/graphics/common/camera.h @@ -94,7 +94,7 @@ public: bool EventProcess(const Event &event); - void Init(D3DVECTOR eye, D3DVECTOR lookat, float delay); + void Init(Math::Vector eye, Math::Vector lookat, float delay); void SetObject(CObject* object); CObject* RetObject(); @@ -117,25 +117,25 @@ public: void SetRemoteZoom(float value); float RetRemoteZoom(); - void StartVisit(D3DVECTOR goal, float dist); + void StartVisit(Math::Vector goal, float dist); void StopVisit(); - void RetCamera(D3DVECTOR &eye, D3DVECTOR &lookat); + void RetCamera(Math::Vector &eye, Math::Vector &lookat); bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time); bool StopCentering(CObject *object, float time); void AbortCentering(); void FlushEffect(); - void StartEffect(CameraEffect effect, D3DVECTOR pos, float force); + void StartEffect(CameraEffect effect, Math::Vector pos, float force); void FlushOver(); void SetOverBaseColor(D3DCOLORVALUE color); - void StartOver(OverEffect effect, D3DVECTOR pos, float force); + void StartOver(OverEffect effect, Math::Vector pos, float force); void FixCamera(); - void SetScriptEye(D3DVECTOR eye); - void SetScriptLookat(D3DVECTOR lookat); + void SetScriptEye(Math::Vector eye); + void SetScriptLookat(Math::Vector lookat); void SetEffect(bool bEnable); void SetCameraScroll(bool bScroll); @@ -160,15 +160,15 @@ protected: bool EventFrameVisit(const Event &event); bool EventFrameScript(const Event &event); - void SetViewTime(const D3DVECTOR &vEyePt, const D3DVECTOR &vLookatPt, float rTime); - bool IsCollision(D3DVECTOR &eye, D3DVECTOR lookat); - bool IsCollisionBack(D3DVECTOR &eye, D3DVECTOR lookat); - bool IsCollisionFix(D3DVECTOR &eye, D3DVECTOR lookat); + void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime); + bool IsCollision(Math::Vector &eye, Math::Vector lookat); + bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat); + bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat); - D3DVECTOR ExcludeTerrain(D3DVECTOR eye, D3DVECTOR lookat, float &angleH, float &angleV); - D3DVECTOR ExcludeObject(D3DVECTOR eye, D3DVECTOR lookat, float &angleH, float &angleV); + Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); + Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); - void SetViewParams(const D3DVECTOR &eye, const D3DVECTOR &lookat, const D3DVECTOR &up); + void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up); void EffectFrame(const Event &event); void OverFrame(const Event &event); @@ -185,12 +185,12 @@ protected: float m_eyeDistance; // distance between the eyes float m_initDelay; // time of initial centering - D3DVECTOR m_actualEye; // current eye - D3DVECTOR m_actualLookat; // aim current - D3DVECTOR m_finalEye; // final eye - D3DVECTOR m_finalLookat; // aim final - D3DVECTOR m_normEye; // normal eye - D3DVECTOR m_normLookat; // aim normal + Math::Vector m_actualEye; // current eye + Math::Vector m_actualLookat; // aim current + Math::Vector m_finalEye; // final eye + Math::Vector m_finalLookat; // aim final + Math::Vector m_normEye; // normal eye + Math::Vector m_normLookat; // aim normal float m_focus; bool m_bRightDown; @@ -198,7 +198,7 @@ protected: Math::Point m_rightPosCenter; Math::Point m_rightPosMove; - D3DVECTOR m_eyePt; // CAMERA_FREE: eye + Math::Vector m_eyePt; // CAMERA_FREE: eye float m_directionH; // CAMERA_FREE: horizontal direction float m_directionV; // CAMERA_FREE: vertical direction float m_heightEye; // CAMERA_FREE: height above the ground @@ -215,7 +215,7 @@ protected: float m_fixDirectionH; // CAMERA_FIX: direction float m_fixDirectionV; // CAMERA_FIX: direction - D3DVECTOR m_visitGoal; // CAMERA_VISIT: target position + Math::Vector m_visitGoal; // CAMERA_VISIT: target position float m_visitDist; // CAMERA_VISIT: distance float m_visitTime; // CAMERA_VISIT: relative time CameraType m_visitType; // CAMERA_VISIT: initial type @@ -244,10 +244,10 @@ protected: float m_centeringProgress; CameraEffect m_effectType; - D3DVECTOR m_effectPos; + Math::Vector m_effectPos; float m_effectForce; float m_effectProgress; - D3DVECTOR m_effectOffset; + Math::Vector m_effectOffset; OverEffect m_overType; float m_overForce; @@ -258,8 +258,8 @@ protected: float m_overFadeIn; float m_overFadeOut; - D3DVECTOR m_scriptEye; - D3DVECTOR m_scriptLookat; + Math::Vector m_scriptEye; + Math::Vector m_scriptLookat; bool m_bEffect; // shocks if explosion? bool m_bCameraScroll; // scroll in the edges? diff --git a/src/graphics/common/cloud.cpp b/src/graphics/common/cloud.cpp index 507da66..67e2fe2 100644 --- a/src/graphics/common/cloud.cpp +++ b/src/graphics/common/cloud.cpp @@ -20,6 +20,8 @@ #include #include "common/struct.h" +#include "math/geometry.h" +#include "math/conv.h" #include "graphics/d3d/d3dengine.h" #include "math/old/d3dmath.h" #include "graphics/d3d/d3dutil.h" @@ -48,7 +50,7 @@ CCloud::CCloud(CInstanceManager* iMan, CD3DEngine* engine) m_terrain = 0; m_level = 0.0f; - m_wind = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_wind = Math::Vector(0.0f, 0.0f, 0.0f); m_subdiv = 8; m_filename[0] = 0; m_bEnable = true; @@ -91,7 +93,7 @@ bool CCloud::EventFrame(const Event &event) // Adjusts the position to normal, to imitate the clouds // at movement. -void CCloud::AdjustLevel(D3DVECTOR &pos, D3DVECTOR &eye, float deep, +void CCloud::AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep, Math::Point &uv1, Math::Point &uv2) { float dist, factor; @@ -104,7 +106,7 @@ void CCloud::AdjustLevel(D3DVECTOR &pos, D3DVECTOR &eye, float deep, uv2.x = 0.0f; uv2.y = 0.0f; - dist = Length2d(pos, eye); + dist = Math::DistanceProjected(pos, eye); factor = powf(dist/deep, 2.0f); pos.y -= m_level*factor*10.0f; } @@ -120,10 +122,10 @@ void CCloud::Draw() { LPDIRECT3DDEVICE7 device; D3DVERTEX2* vertex; - D3DMATRIX* matView; + Math::Matrix* matView; D3DMATERIAL7 material; - D3DMATRIX matrix; - D3DVECTOR n, pos, p, eye; + Math::Matrix matrix; + Math::Vector n, pos, p, eye; Math::Point uv1, uv2; float iDeep, deep, size, fogStart, fogEnd; int i, j, u; @@ -155,7 +157,10 @@ void CCloud::Draw() device->SetRenderState(D3DRENDERSTATE_FOGEND, F2DW(fogEnd)); matView = m_engine->RetMatView(); - device->SetTransform(D3DTRANSFORMSTATE_VIEW, matView); + { + D3DMATRIX mat = MAT_TO_D3DMAT(*matView); + device->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } ZeroMemory( &material, sizeof(D3DMATERIAL7) ); material.diffuse = m_diffuse; @@ -169,12 +174,15 @@ void CCloud::Draw() m_engine->SetState(D3DSTATETTb|D3DSTATEFOG|D3DSTATEWRAP); //? m_engine->SetState(D3DSTATEWRAP); - D3DUtil_SetIdentityMatrix(matrix); - device->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + device->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } size = m_size/2.0f; eye = m_engine->RetEyePt(); - n = D3DVECTOR(0.0f, -1.0f, 0.0f); + n = Math::Vector(0.0f, -1.0f, 0.0f); // Draws all the lines. for ( i=0 ; i= D3DMAXLIGHT ) return false; - m_lightTable[lightRank].light.dvPosition = pos; + m_lightTable[lightRank].light.dvPosition = VEC_TO_D3DVEC(pos); return true; } -D3DVECTOR CLight::RetLightPos(int lightRank) +Math::Vector CLight::RetLightPos(int lightRank) { - if ( lightRank < 0 || lightRank >= D3DMAXLIGHT ) return D3DVECTOR(0.0f, 0.0f, 0.0f); + if ( lightRank < 0 || lightRank >= D3DMAXLIGHT ) return Math::Vector(0.0f, 0.0f, 0.0f); - return m_lightTable[lightRank].light.dvPosition; + return D3DVEC_TO_VEC(m_lightTable[lightRank].light.dvPosition); } // Management direction of the light. -bool CLight::SetLightDir(int lightRank, D3DVECTOR dir) +bool CLight::SetLightDir(int lightRank, Math::Vector dir) { if ( lightRank < 0 || lightRank >= D3DMAXLIGHT ) return false; - m_lightTable[lightRank].light.dvDirection = dir; + m_lightTable[lightRank].light.dvDirection = VEC_TO_D3DVEC(dir); return true; } -D3DVECTOR CLight::RetLightDir(int lightRank) +Math::Vector CLight::RetLightDir(int lightRank) { - if ( lightRank < 0 || lightRank >= D3DMAXLIGHT ) return D3DVECTOR(0.0f, 0.0f, 0.0f); + if ( lightRank < 0 || lightRank >= D3DMAXLIGHT ) return Math::Vector(0.0f, 0.0f, 0.0f); - return m_lightTable[lightRank].light.dvDirection; + return D3DVEC_TO_VEC(m_lightTable[lightRank].light.dvDirection); } @@ -397,7 +398,7 @@ void CLight::AdaptLightColor(D3DCOLORVALUE color, float factor) void CLight::FrameLight(float rTime) { - D3DVECTOR dir; + Math::Vector dir; float angle; int i; diff --git a/src/graphics/common/light.h b/src/graphics/common/light.h index 2b20094..683f715 100644 --- a/src/graphics/common/light.h +++ b/src/graphics/common/light.h @@ -75,11 +75,11 @@ public: bool SetLightIncluType(int lightRank, D3DTypeObj type); bool SetLightExcluType(int lightRank, D3DTypeObj type); - bool SetLightPos(int lightRank, D3DVECTOR pos); - D3DVECTOR RetLightPos(int lightRank); + bool SetLightPos(int lightRank, Math::Vector pos); + Math::Vector RetLightPos(int lightRank); - bool SetLightDir(int lightRank, D3DVECTOR dir); - D3DVECTOR RetLightDir(int lightRank); + bool SetLightDir(int lightRank, Math::Vector dir); + Math::Vector RetLightDir(int lightRank); bool SetLightIntensitySpeed(int lightRank, float speed); bool SetLightIntensity(int lightRank, float value); diff --git a/src/graphics/common/mainmovie.cpp b/src/graphics/common/mainmovie.cpp deleted file mode 100644 index e890ae7..0000000 --- a/src/graphics/common/mainmovie.cpp +++ /dev/null @@ -1,247 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// mainmovie.cpp - - -#include -#include -#include - -#include "common/struct.h" -#include "graphics/d3d/d3dengine.h" -#include "common/global.h" -#include "common/event.h" -#include "common/iman.h" -#include "math/old/math3d.h" -#include "graphics/common/camera.h" -#include "object/object.h" -#include "object/motion/motion.h" -#include "object/motion/motionhuman.h" -#include "ui/interface.h" -#include "object/robotmain.h" -#include "sound/sound.h" -#include "graphics/common/mainmovie.h" - - - - -// Constructor of the application card. - -CMainMovie::CMainMovie(CInstanceManager* iMan) -{ - m_iMan = iMan; - m_iMan->AddInstance(CLASS_SHORT, this); - - m_interface = (CInterface*)m_iMan->SearchInstance(CLASS_INTERFACE); - m_event = (CEvent*)m_iMan->SearchInstance(CLASS_EVENT); - m_engine = (CD3DEngine*)m_iMan->SearchInstance(CLASS_ENGINE); - m_main = (CRobotMain*)m_iMan->SearchInstance(CLASS_MAIN); - m_camera = (CCamera*)m_iMan->SearchInstance(CLASS_CAMERA); - m_sound = (CSound*)m_iMan->SearchInstance(CLASS_SOUND); - - Flush(); -} - -// Destructor of the application card. - -CMainMovie::~CMainMovie() -{ -} - - -// Stops the current movie. - -void CMainMovie::Flush() -{ - m_type = MM_NONE; -} - - -// Start of a film. - -bool CMainMovie::Start(MainMovieType type, float time) -{ - D3DMATRIX* mat; - D3DVECTOR pos; - CObject* pObj; - CMotion* motion; - - m_type = type; - m_speed = 1.0f/time; - m_progress = 0.0f; - - if ( m_type == MM_SATCOMopen ) - { - pObj = m_main->SearchHuman(); - if ( pObj == 0 ) - { - m_type = MM_NONE; // it's over! - return true; - } - - motion = pObj->RetMotion(); - if ( motion != 0 ) - { - motion->SetAction(MHS_SATCOM, 0.5f); // reads the SatCom - } - - m_camera->RetCamera(m_initialEye, m_initialLookat); - m_camera->SetType(CAMERA_SCRIPT); - m_camera->SetSmooth(CS_HARD); - m_camera->SetScriptEye(m_initialEye); - m_camera->SetScriptLookat(m_initialLookat); - m_camera->FixCamera(); - - mat = pObj->RetWorldMatrix(0); - m_finalLookat[0] = Transform(*mat, D3DVECTOR( 1.6f, 1.0f, 1.2f)); - m_finalEye[0] = Transform(*mat, D3DVECTOR(-1.5f, 5.0f, 3.0f)); - m_finalLookat[1] = Transform(*mat, D3DVECTOR( 1.6f, 1.0f, 1.2f)); - m_finalEye[1] = Transform(*mat, D3DVECTOR( 0.8f, 3.0f, 0.8f)); - } - - if ( m_type == MM_SATCOMclose ) - { - pObj = m_main->SearchHuman(); - if ( pObj != 0 ) - { - motion = pObj->RetMotion(); - if ( motion != 0 ) - { - motion->SetAction(-1); // finishes reading SatCom - } - } - - m_camera->SetType(CAMERA_BACK); - m_type = MM_NONE; // it's already over! - } - - return true; -} - -// Stop a current movie. - -bool CMainMovie::Stop() -{ - CObject* pObj; - CMotion* motion; - - if ( m_type == MM_SATCOMopen ) - { - pObj = m_main->SearchHuman(); - if ( pObj != 0 ) - { - motion = pObj->RetMotion(); - if ( motion != 0 ) - { - motion->SetAction(-1); // finishes reading SatCom - } - } - } - - m_type = MM_NONE; - return true; -} - -// Indicates whether a film is in progress. - -bool CMainMovie::IsExist() -{ - return (m_type != MM_NONE); -} - - -// Processing an event. - -bool CMainMovie::EventProcess(const Event &event) -{ - D3DVECTOR initialEye, initialLookat, finalEye, finalLookat, eye, lookat; - float progress; - - if ( m_type == MM_NONE ) return true; - - m_progress += event.rTime*m_speed; - - if ( m_type == MM_SATCOMopen ) - { - if ( m_progress < 1.0f ) - { - progress = 1.0f-powf(1.0f-m_progress, 3.0f); - - if ( progress < 0.6f ) - { - progress = progress/0.6f; - initialEye = m_initialEye; - initialLookat = m_initialLookat; - finalEye = m_finalEye[0]; - finalLookat = m_finalLookat[0]; - } - else - { - progress = (progress-0.6f)/0.3f; - initialEye = m_finalEye[0]; - initialLookat = m_finalLookat[0]; - finalEye = m_finalEye[1]; - finalLookat = m_finalLookat[1]; - } - if ( progress > 1.0f ) progress = 1.0f; - - eye = (finalEye-initialEye)*progress+initialEye; - lookat = (finalLookat-initialLookat)*progress+initialLookat; - m_camera->SetScriptEye(eye); - m_camera->SetScriptLookat(lookat); -// m_camera->FixCamera(); - } - else - { - m_stopType = m_type; - Flush(); - return false; - } - } - - if ( m_type == MM_SATCOMclose ) - { - if ( m_progress < 1.0f ) - { - } - else - { - m_stopType = m_type; - Flush(); - return false; - } - } - - return true; -} - - -// Returns the type of the current movie. - -MainMovieType CMainMovie::RetType() -{ - return m_type; -} - -// Returns the type of movie stop. - -MainMovieType CMainMovie::RetStopType() -{ - return m_stopType; -} - - diff --git a/src/graphics/common/mainmovie.h b/src/graphics/common/mainmovie.h deleted file mode 100644 index ddc1b96..0000000 --- a/src/graphics/common/mainmovie.h +++ /dev/null @@ -1,80 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - -// mainmovie.h - -#pragma once - - -#include "common/event.h" -#include "graphics/d3d/d3dengine.h" - -class CInstanceManager; -class CEvent; -class CD3DEngine; -class CInterface; -class CRobotMain; -class CCamera; -class CSound; -class CObject; - - - - -enum MainMovieType -{ - MM_NONE, - MM_SATCOMopen, - MM_SATCOMclose, -}; - - - -class CMainMovie -{ -public: - CMainMovie(CInstanceManager* iMan); - ~CMainMovie(); - - void Flush(); - bool Start(MainMovieType type, float time); - bool Stop(); - bool IsExist(); - bool EventProcess(const Event &event); - MainMovieType RetType(); - MainMovieType RetStopType(); - -protected: - -protected: - CInstanceManager* m_iMan; - CEvent* m_event; - CD3DEngine* m_engine; - CInterface* m_interface; - CRobotMain* m_main; - CCamera* m_camera; - CSound* m_sound; - - MainMovieType m_type; - MainMovieType m_stopType; - float m_speed; - float m_progress; - D3DVECTOR m_initialEye; - D3DVECTOR m_initialLookat; - D3DVECTOR m_finalEye[2]; - D3DVECTOR m_finalLookat[2]; -}; - diff --git a/src/graphics/common/model.cpp b/src/graphics/common/model.cpp index 8fc6be3..b464244 100644 --- a/src/graphics/common/model.cpp +++ b/src/graphics/common/model.cpp @@ -752,22 +752,22 @@ bool CModel::EventProcess(const Event &event) break; case EVENT_BUTTON13: // +X ? - MoveSelect(D3DVECTOR(1.0f, 0.0f, 0.0f)); + MoveSelect(Math::Vector(1.0f, 0.0f, 0.0f)); break; case EVENT_BUTTON16: // -X ? - MoveSelect(D3DVECTOR(-1.0f, 0.0f, 0.0f)); + MoveSelect(Math::Vector(-1.0f, 0.0f, 0.0f)); break; case EVENT_BUTTON14: // +Y ? - MoveSelect(D3DVECTOR(0.0f, 1.0f, 0.0f)); + MoveSelect(Math::Vector(0.0f, 1.0f, 0.0f)); break; case EVENT_BUTTON17: // -Y ? - MoveSelect(D3DVECTOR(0.0f, -1.0f, 0.0f)); + MoveSelect(Math::Vector(0.0f, -1.0f, 0.0f)); break; case EVENT_BUTTON15: // +Z ? - MoveSelect(D3DVECTOR(0.0f, 0.0f, 1.0f)); + MoveSelect(Math::Vector(0.0f, 0.0f, 1.0f)); break; case EVENT_BUTTON18: // -Z ? - MoveSelect(D3DVECTOR(0.0f, 0.0f, -1.0f)); + MoveSelect(Math::Vector(0.0f, 0.0f, -1.0f)); break; } @@ -945,7 +945,7 @@ void CModel::SmoothSelect() int index[100]; int used, i, j, rank; D3DVERTEX2 vi, vj; - D3DVECTOR sum; + Math::Vector sum; used = m_modFile->RetTriangleUsed(); @@ -1008,7 +1008,7 @@ void CModel::SmoothSelect() void CModel::PlaneSelect() { - D3DVECTOR p1, p2, p3, n; + Math::Vector p1, p2, p3, n; int used, i; used = m_modFile->RetTriangleUsed(); @@ -1029,7 +1029,7 @@ void CModel::PlaneSelect() p3.y = m_triangleTable[i].p3.y; p3.z = m_triangleTable[i].p3.z; - n = ComputeNormal(p3, p2, p1); + n = Math::NormalToPlane(p3, p2, p1); m_triangleTable[i].p3.nx = n.x; m_triangleTable[i].p3.ny = n.y; @@ -1082,7 +1082,7 @@ void CModel::StateSelect() // Moves the selection. -void CModel::MoveSelect(D3DVECTOR move) +void CModel::MoveSelect(Math::Vector move) { if ( m_oper == 'Z' ) { @@ -1120,7 +1120,7 @@ void CModel::MoveSelect(D3DVECTOR move) // Moves the selection. -void CModel::OperSelect(D3DVECTOR move, char oper) +void CModel::OperSelect(Math::Vector move, char oper) { Math::Point rot; int used, i; @@ -1233,7 +1233,7 @@ void CModel::ReadScript(char *filename) char name[200]; char buffer[200]; int i, first, last; - D3DVECTOR move; + Math::Vector move; bool bFirst = true; file = fopen(filename, "r"); @@ -1290,7 +1290,7 @@ void CModel::ReadScript(char *filename) // Computes the bbox of selected triangles. -void CModel::BBoxCompute(D3DVECTOR &min, D3DVECTOR &max) +void CModel::BBoxCompute(Math::Vector &min, Math::Vector &max) { D3DVERTEX2 vertex; int used, i; @@ -1320,9 +1320,9 @@ void CModel::BBoxCompute(D3DVECTOR &min, D3DVECTOR &max) // Returns the gravity center of the selection. -D3DVECTOR CModel::RetSelectCDG() +Math::Vector CModel::RetSelectCDG() { - D3DVECTOR min, max, cdg; + Math::Vector min, max, cdg; BBoxCompute(min, max); @@ -1335,9 +1335,9 @@ D3DVECTOR CModel::RetSelectCDG() // Returns the normal vector of the selection. -D3DVECTOR CModel::RetSelectNormal() +Math::Vector CModel::RetSelectNormal() { - D3DVECTOR p1, p2, p3, n; + Math::Vector p1, p2, p3, n; p1.x = m_triangleTable[m_triangleSel1].p1.nx; p1.y = m_triangleTable[m_triangleSel1].p1.ny; @@ -1361,7 +1361,7 @@ D3DVECTOR CModel::RetSelectNormal() bool CModel::IsMappingSelectPlausible(D3DMaping D3Dmode) { D3DVERTEX2 vertex[3]; - D3DVECTOR min, max; + Math::Vector min, max; Math::Point a, b, ti, ts; float au, bu, av, bv; int used, i, j; @@ -1443,7 +1443,7 @@ void CModel::MappingSelect(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName) { D3DVERTEX2 vertex; - D3DVECTOR min, max; + Math::Vector min, max; Math::Point a, b; D3DMaping D3Dmode; float au, bu, av, bv; @@ -1562,7 +1562,7 @@ void CModel::MappingSelectSpherical(int mode, int rotate, bool bMirrorX, bool bM Math::Point ti, Math::Point ts, char *texName) { D3DVERTEX2 vertex; - D3DVECTOR min, max, center, dim, p; + Math::Vector min, max, center, dim, p; float radius, k, u, v; int used, i; @@ -1590,7 +1590,7 @@ void CModel::MappingSelectSpherical(int mode, int rotate, bool bMirrorX, bool bM p.y = vertex.y-center.y; p.z = vertex.z-center.z; - k = radius/Length(p); + k = radius/p.Length(); u = k*p.x; v = k*p.z; u = (u/dim.x*2.0f+1.0f)/2.0f; // 0..1 @@ -1607,10 +1607,10 @@ void CModel::MappingSelectSpherical(int mode, int rotate, bool bMirrorX, bool bM // Seeking the center of a group of points. -D3DVECTOR CModel::RetMappingCenter(D3DVECTOR pos, D3DVECTOR min) +Math::Vector CModel::RetMappingCenter(Math::Vector pos, Math::Vector min) { D3DVERTEX2 vertex; - D3DVECTOR center, p; + Math::Vector center, p; int used, i, nb; center.x = 0.0f; @@ -1653,7 +1653,7 @@ void CModel::MappingSelectCylindrical(int mode, int rotate, bool bMirrorX, bool Math::Point ti, Math::Point ts, char *texName) { D3DVERTEX2 vertex; - D3DVECTOR min, max, center, local, dim, p, pp, box; + Math::Vector min, max, center, local, dim, p, pp, box; float radius, u, v; int used, i; @@ -1755,7 +1755,7 @@ void CModel::MappingSelectFace(int mode, int rotate, bool bMirrorX, bool bMirror Math::Point ti, Math::Point ts, char *texName) { D3DVERTEX2 vertex[3]; - D3DVECTOR min, max, center, local, dim, p; + Math::Vector min, max, center, local, dim, p; float radius, u[3], v[3], m[3], avg; int used, i, j; @@ -1828,7 +1828,7 @@ void CModel::MappingSelect2(int texNum2, int subdiv, bool bMirrorX, bool bMirrorY) { D3DVERTEX2 vertex; - D3DVECTOR min, max, center, p; + Math::Vector min, max, center, p; float u ,v; int used, i; @@ -1871,7 +1871,7 @@ void CModel::MappingSelect2(int texNum2, int subdiv, p.z = vertex.z-center.z; u = Math::RotateAngle(p.x, p.z); - v = Math::RotateAngle(Length(p.x, p.z), p.y); + v = Math::RotateAngle(Math::Point(p.x, p.z).Length(), p.y); if ( p.x < 0.0f ) v += Math::PI; u = Math::NormAngle(u+(float)offsetU*Math::PI/180.0f); @@ -1904,7 +1904,7 @@ void CModel::MappingSelect2(int texNum2, int subdiv, void CModel::MappingSelectPlane2(int mode, bool bMirrorX, bool bMirrorY) { D3DVERTEX2 vertex; - D3DVECTOR min, max; + Math::Vector min, max; Math::Point ti, ts, a, b; float au, bu, av, bv; int used, i; @@ -1984,7 +1984,7 @@ void CModel::MappingSelectPlane2(int mode, bool bMirrorX, bool bMirrorY) void CModel::MappingSelectSpherical2(bool bMirrorX, bool bMirrorY) { D3DVERTEX2 vertex; - D3DVECTOR min, max, center, dim, p; + Math::Vector min, max, center, dim, p; Math::Point ti, ts; float radius, k, u, v; int used, i; @@ -2016,7 +2016,7 @@ void CModel::MappingSelectSpherical2(bool bMirrorX, bool bMirrorY) p.y = vertex.y-center.y; p.z = vertex.z-center.z; - k = radius/Length(p); + k = radius/p.Length(); u = k*p.x; v = k*p.z; u = (u/dim.x*2.0f+1.0f)/2.0f; // 0..1 @@ -2036,7 +2036,7 @@ void CModel::MappingSelectSpherical2(bool bMirrorX, bool bMirrorY) void CModel::MappingSelectMagic2(bool bMirrorX, bool bMirrorY) { D3DVERTEX2 vertex, v[3]; - D3DVECTOR min, max, au, bu, av, bv, n; + Math::Vector min, max, au, bu, av, bv, n; Math::Point ti, ts; int used, i, mode; @@ -2078,9 +2078,9 @@ void CModel::MappingSelectMagic2(bool bMirrorX, bool bMirrorY) if ( !GetVertex(i+1, v[1]) ) continue; if ( !GetVertex(i+2, v[2]) ) continue; - n = ComputeNormal(D3DVECTOR(v[0].x, v[0].y, v[0].z), - D3DVECTOR(v[1].x, v[1].y, v[1].z), - D3DVECTOR(v[2].x, v[2].y, v[2].z)); + n = Math::NormalToPlane(Math::Vector(v[0].x, v[0].y, v[0].z), + Math::Vector(v[1].x, v[1].y, v[1].z), + Math::Vector(v[2].x, v[2].y, v[2].z)); n.x = fabs(n.x); n.y = fabs(n.y); @@ -2142,7 +2142,7 @@ int CModel::SearchNext(int rank, int step) int CModel::SearchSamePlane(int first, int step) { - D3DVECTOR vFirst[3], vNext[3]; + Math::Vector vFirst[3], vNext[3]; int last, i; vFirst[0].x = m_triangleTable[first].p1.x; @@ -2424,7 +2424,7 @@ void CModel::InitView() void CModel::InitViewFromSelect() { #if 0 - D3DVECTOR n; + Math::Vector n; float h,v; n = RetSelectNormal(); @@ -2456,13 +2456,13 @@ void CModel::InitViewFromSelect() void CModel::UpdateView() { - D3DVECTOR eye, lookat, vUpVec; + Math::Vector eye, lookat, vUpVec; //? lookat = RetSelectCDG(); - lookat = D3DVECTOR(0.0f, m_viewHeight, 0.0f); + lookat = Math::Vector(0.0f, m_viewHeight, 0.0f); eye = RotateView(lookat, m_viewAngleH, m_viewAngleV, m_viewDist); - vUpVec = D3DVECTOR(0.0f, 1.0f, 0.0f); + vUpVec = Math::Vector(0.0f, 1.0f, 0.0f); m_engine->SetViewParams(eye, lookat, vUpVec, 10.0f); m_engine->SetRankView(0); } diff --git a/src/graphics/common/model.h b/src/graphics/common/model.h index 385f4e1..74914f0 100644 --- a/src/graphics/common/model.h +++ b/src/graphics/common/model.h @@ -51,20 +51,20 @@ protected: bool EventFrame(const Event &event); bool GetVertex(int rank, D3DVERTEX2 &vertex); bool SetVertex(int rank, D3DVERTEX2 &vertex); - D3DVECTOR RetSelectCDG(); - D3DVECTOR RetSelectNormal(); + Math::Vector RetSelectCDG(); + Math::Vector RetSelectNormal(); void SmoothSelect(); void PlaneSelect(); void ColorSelect(); void StateSelect(); - void MoveSelect(D3DVECTOR move); - void OperSelect(D3DVECTOR move, char oper); + void MoveSelect(Math::Vector move); + void OperSelect(Math::Vector move, char oper); void ReadScript(char *filename); - void BBoxCompute(D3DVECTOR &min, D3DVECTOR &max); + void BBoxCompute(Math::Vector &min, Math::Vector &max); bool IsMappingSelectPlausible(D3DMaping D3Dmode); void MappingSelect(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName); void MappingSelectSpherical(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName); - D3DVECTOR RetMappingCenter(D3DVECTOR pos, D3DVECTOR min); + Math::Vector RetMappingCenter(Math::Vector pos, Math::Vector min); void MappingSelectCylindrical(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName); void MappingSelectFace(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName); void MappingSelect2(int texNum2, int subdiv, int offsetU, int offsetV, bool bMirrorX, bool bMirrorY); diff --git a/src/graphics/common/particule.cpp b/src/graphics/common/particule.cpp index 6359ddf..0c63049 100644 --- a/src/graphics/common/particule.cpp +++ b/src/graphics/common/particule.cpp @@ -24,6 +24,7 @@ #include "common/struct.h" #include "math/const.h" #include "math/geometry.h" +#include "math/conv.h" #include "math/old/d3dmath.h" #include "graphics/d3d/d3dtextr.h" #include "graphics/d3d/d3dengine.h" @@ -249,7 +250,7 @@ void NameParticule(char *buffer, int num) // Creates a new particle. // Returns the channel of the particle created or -1 on error. -int CParticule::CreateParticule(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, +int CParticule::CreateParticule(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration, float mass, float windSensitivity, int sheet) @@ -273,7 +274,7 @@ int CParticule::CreateParticule(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, type != PARTIQUARTZ && !m_main->RetMovieLock() ) { - dist = Length(pos, m_engine->RetEyePt()); + dist = Math::Distance(pos, m_engine->RetEyePt()); if ( dist > 300.0f ) return -1; } #endif @@ -454,13 +455,13 @@ int CParticule::CreateParticule(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, // Creates a new triangular particle (debris). // Returns the channel of the particle created or -1 on error. -int CParticule::CreateFrag(D3DVECTOR pos, D3DVECTOR speed, +int CParticule::CreateFrag(Math::Vector pos, Math::Vector speed, D3DTriangle *triangle, ParticuleType type, float duration, float mass, float windSensitivity, int sheet) { - D3DVECTOR p1, p2, p3, n; + Math::Vector p1, p2, p3, n; float l1, l2, l3, dx, dy; int i, j, t; @@ -513,14 +514,14 @@ int CParticule::CreateFrag(D3DVECTOR pos, D3DVECTOR speed, p3.y = m_triangle[i].triangle[2].y; p3.z = m_triangle[i].triangle[2].z; - l1 = Length(p1, p2); - l2 = Length(p2, p3); - l3 = Length(p3, p1); + l1 = Math::Distance(p1, p2); + l2 = Math::Distance(p2, p3); + l3 = Math::Distance(p3, p1); dx = fabs(Math::Min(l1, l2, l3))*0.5f; dy = fabs(Math::Max(l1, l2, l3))*0.5f; - p1 = D3DVECTOR(-dx, dy, 0.0f); - p2 = D3DVECTOR( dx, dy, 0.0f); - p3 = D3DVECTOR(-dx, -dy, 0.0f); + p1 = Math::Vector(-dx, dy, 0.0f); + p2 = Math::Vector( dx, dy, 0.0f); + p3 = Math::Vector(-dx, -dy, 0.0f); m_triangle[i].triangle[0].x = p1.x; m_triangle[i].triangle[0].y = p1.y; @@ -534,7 +535,7 @@ int CParticule::CreateFrag(D3DVECTOR pos, D3DVECTOR speed, m_triangle[i].triangle[2].y = p3.y; m_triangle[i].triangle[2].z = p3.z; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); + n = Math::Vector(0.0f, 0.0f, -1.0f); m_triangle[i].triangle[0].nx = n.x; m_triangle[i].triangle[0].ny = n.y; @@ -562,7 +563,7 @@ int CParticule::CreateFrag(D3DVECTOR pos, D3DVECTOR speed, // Creates a new particle being a part of object. // Returns the channel of the particle created or -1 on error. -int CParticule::CreatePart(D3DVECTOR pos, D3DVECTOR speed, +int CParticule::CreatePart(Math::Vector pos, Math::Vector speed, ParticuleType type, float duration, float mass, float weight, float windSensitivity, int sheet) @@ -614,7 +615,7 @@ int CParticule::CreatePart(D3DVECTOR pos, D3DVECTOR speed, // Creates a new linear particle (radius). // Returns the channel of the particle created or -1 on error. -int CParticule::CreateRay(D3DVECTOR pos, D3DVECTOR goal, +int CParticule::CreateRay(Math::Vector pos, Math::Vector goal, ParticuleType type, Math::Point dim, float duration, int sheet) { @@ -646,7 +647,7 @@ int CParticule::CreateRay(D3DVECTOR pos, D3DVECTOR goal, m_particule[i].duration = duration; m_particule[i].pos = pos; m_particule[i].goal = goal; - m_particule[i].speed = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_particule[i].speed = Math::Vector(0.0f, 0.0f, 0.0f); m_particule[i].windSensitivity = 0.0f; m_particule[i].dim = dim; m_particule[i].zoom = 1.0f; @@ -677,7 +678,7 @@ int CParticule::CreateRay(D3DVECTOR pos, D3DVECTOR goal, // Creates a particle with a trail. // "length" is the length of the tail of drag (in seconds)! -int CParticule::CreateTrack(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, +int CParticule::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration, float mass, float length, float width) { @@ -713,8 +714,8 @@ int CParticule::CreateTrack(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, // Creates a tire mark. -void CParticule::CreateWheelTrace(const D3DVECTOR &p1, const D3DVECTOR &p2, - const D3DVECTOR &p3, const D3DVECTOR &p4, +void CParticule::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, + const Math::Vector &p3, const Math::Vector &p4, ParticuleType type) { int i, max; @@ -866,7 +867,7 @@ void CParticule::SetObjectFather(int channel, CObject *object) m_particule[channel].objFather = object; } -void CParticule::SetPosition(int channel, D3DVECTOR pos) +void CParticule::SetPosition(int channel, Math::Vector pos) { if ( !CheckChannel(channel) ) return; m_particule[channel].pos = pos; @@ -896,7 +897,7 @@ void CParticule::SetIntensity(int channel, float intensity) m_particule[channel].intensity = intensity; } -void CParticule::SetParam(int channel, D3DVECTOR pos, Math::Point dim, float zoom, +void CParticule::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) { if ( !CheckChannel(channel) ) return; @@ -917,7 +918,7 @@ void CParticule::SetPhase(int channel, ParticulePhase phase, float duration) // Returns the position of the particle. -bool CParticule::GetPosition(int channel, D3DVECTOR &pos) +bool CParticule::GetPosition(int channel, Math::Vector &pos) { if ( !CheckChannel(channel) ) return false; pos = m_particule[channel].pos; @@ -937,7 +938,7 @@ void CParticule::SetFrameUpdate(int sheet, bool bUpdate) void CParticule::FrameParticule(float rTime) { CObject* object; - D3DVECTOR eye, pos, speed, wind; + Math::Vector eye, pos, speed, wind; Math::Point ts, ti, dim; bool bPause; float progress, dp, h, duration, mass, amplitude; @@ -1417,7 +1418,7 @@ void CParticule::FrameParticule(float rTime) { if ( object->RetShieldRadius() > 0.0f ) // protected by shield? { - CreateParticule(m_particule[i].pos, D3DVECTOR(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); + CreateParticule(m_particule[i].pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); if ( m_lastTimeGunDel > 0.2f ) { m_lastTimeGunDel = 0.0f; @@ -1463,7 +1464,7 @@ void CParticule::FrameParticule(float rTime) { if ( object->RetShieldRadius() > 0.0f ) { - CreateParticule(m_particule[i].pos, D3DVECTOR(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); + CreateParticule(m_particule[i].pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f); if ( m_lastTimeGunDel > 0.2f ) { m_lastTimeGunDel = 0.0f; @@ -2144,12 +2145,12 @@ void CParticule::FrameParticule(float rTime) { m_particule[i].testTime = 0.0f; - D3DVECTOR pos, speed; + Math::Vector pos, speed; Math::Point dim; pos = m_particule[i].pos; //? speed = -m_particule[i].speed*0.5f; - speed = D3DVECTOR(0.0f, 0.0f, 0.0f); + speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = 1.0f*(Math::Rand()*0.8f+0.6f); dim.y = dim.x; CreateParticule(pos, speed, dim, PARTIGAS, 0.5f); @@ -2748,9 +2749,9 @@ void CParticule::FrameParticule(float rTime) // Moves a drag. // Returns true if the drag is finished. -bool CParticule::TrackMove(int i, D3DVECTOR pos, float progress) +bool CParticule::TrackMove(int i, Math::Vector pos, float progress) { - D3DVECTOR last; + Math::Vector last; int h, hh; if ( i < 0 || i >= MAXTRACK ) return true; @@ -2776,7 +2777,7 @@ bool CParticule::TrackMove(int i, D3DVECTOR pos, float progress) last = m_track[i].pos[hh]; } m_track[i].pos[h] = pos; - m_track[i].len[h] = Length(pos, last); + m_track[i].len[h] = Math::Distance(pos, last); m_track[i].head = h; @@ -2797,8 +2798,8 @@ bool CParticule::TrackMove(int i, D3DVECTOR pos, float progress) void CParticule::TrackDraw(int i, ParticuleType type) { D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR corner[4], p1, p2, p, n, eye; - D3DMATRIX matrix; + Math::Vector corner[4], p1, p2, p, n, eye; + Math::Matrix matrix; Math::Point texInf, texSup, rot; float lTotal, f1, f2, a; int counter, h; @@ -2812,8 +2813,11 @@ void CParticule::TrackDraw(int i, ParticuleType type) h --; if ( h < 0 ) h = MAXTRACKLEN-1; } - D3DUtil_SetIdentityMatrix(matrix); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } if ( type == PARTITRACK1 ) // explosion technique? { @@ -2967,8 +2971,8 @@ void CParticule::TrackDraw(int i, ParticuleType type) void CParticule::DrawParticuleTriangle(int i) { CObject* object; - D3DMATRIX matrix; - D3DVECTOR eye, pos, angle; + Math::Matrix matrix; + Math::Vector eye, pos, angle; if ( m_particule[i].zoom == 0.0f ) return; @@ -2981,15 +2985,18 @@ void CParticule::DrawParticuleTriangle(int i) pos += object->RetPosition(0); } - angle.x = -Math::RotateAngle(Length2d(pos, eye), pos.y-eye.y); + angle.x = -Math::RotateAngle(Math::DistanceProjected(pos, eye), pos.y-eye.y); angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x); angle.z = m_particule[i].angle; - MatRotateXZY(matrix, angle); - matrix._41 = pos.x; - matrix._42 = pos.y; - matrix._43 = pos.z; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + Math::LoadRotationXZYMatrix(matrix, angle); + matrix.Set(1, 4, pos.x); + matrix.Set(2, 4, pos.y); + matrix.Set(3, 4, pos.z); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX2, m_triangle[i].triangle, 3, NULL); @@ -3002,8 +3009,8 @@ void CParticule::DrawParticuleNorm(int i) { CObject* object; D3DVERTEX2 vertex[4]; // 2 triangles - D3DMATRIX matrix; - D3DVECTOR corner[4], eye, pos, n, angle; + Math::Matrix matrix; + Math::Vector corner[4], eye, pos, n, angle; Math::Point dim; float zoom; @@ -3020,7 +3027,7 @@ void CParticule::DrawParticuleNorm(int i) { pos = m_particule[i].pos; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); + n = Math::Vector(0.0f, 0.0f, -1.0f); dim.x = m_particule[i].dim.x * zoom; dim.y = m_particule[i].dim.y * zoom; @@ -3060,17 +3067,20 @@ void CParticule::DrawParticuleNorm(int i) pos += object->RetPosition(0); } - angle.x = -Math::RotateAngle(Length2d(pos, eye), pos.y-eye.y); + angle.x = -Math::RotateAngle(Math::DistanceProjected(pos, eye), pos.y-eye.y); angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x); angle.z = m_particule[i].angle; - MatRotateXZY(matrix, angle); - matrix._41 = pos.x; - matrix._42 = pos.y; - matrix._43 = pos.z; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + Math::LoadRotationXZYMatrix(matrix, angle); + matrix.Set(1, 4, pos.x); + matrix.Set(2, 4, pos.y); + matrix.Set(3, 4, pos.z); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } - n = D3DVECTOR(0.0f, 0.0f, -1.0f); + n = Math::Vector(0.0f, 0.0f, -1.0f); dim.x = m_particule[i].dim.x * zoom; dim.y = m_particule[i].dim.y * zoom; @@ -3107,8 +3117,8 @@ void CParticule::DrawParticuleFlat(int i) { CObject* object; D3DVERTEX2 vertex[4]; // 2 triangles - D3DMATRIX matrix; - D3DVECTOR corner[4], pos, n, angle, eye; + Math::Matrix matrix; + Math::Vector corner[4], pos, n, angle, eye; Math::Point dim; if ( m_particule[i].zoom == 0.0f ) return; @@ -3145,13 +3155,16 @@ void CParticule::DrawParticuleFlat(int i) } #endif - MatRotateXZY(matrix, angle); - matrix._41 = pos.x; - matrix._42 = pos.y; - matrix._43 = pos.z; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + Math::LoadRotationXZYMatrix(matrix, angle); + matrix.Set(1, 4, pos.x); + matrix.Set(2, 4, pos.y); + matrix.Set(3, 4, pos.z); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } - n = D3DVECTOR(0.0f, 0.0f, -1.0f); + n = Math::Vector(0.0f, 0.0f, -1.0f); dim.x = m_particule[i].dim.x * m_particule[i].zoom; dim.y = m_particule[i].dim.y * m_particule[i].zoom; @@ -3187,8 +3200,8 @@ void CParticule::DrawParticuleFog(int i) { CObject* object; D3DVERTEX2 vertex[4]; // 2 triangles - D3DMATRIX matrix; - D3DVECTOR corner[4], pos, n, angle, eye; + Math::Matrix matrix; + Math::Vector corner[4], pos, n, angle, eye; Math::Point dim, zoom; if ( !m_engine->RetFog() ) return; @@ -3244,13 +3257,16 @@ void CParticule::DrawParticuleFog(int i) angle.x = -Math::PI/2.0f; } - MatRotateXZY(matrix, angle); - matrix._41 = pos.x; - matrix._42 = pos.y; - matrix._43 = pos.z; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + Math::LoadRotationXZYMatrix(matrix, angle); + matrix.Set(1, 4, pos.x); + matrix.Set(2, 4, pos.y); + matrix.Set(3, 4, pos.z); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } - n = D3DVECTOR(0.0f, 0.0f, -1.0f); + n = Math::Vector(0.0f, 0.0f, -1.0f); corner[0].x = dim.x; corner[0].y = dim.y; @@ -3283,8 +3299,8 @@ void CParticule::DrawParticuleRay(int i) { CObject* object; D3DVERTEX2 vertex[4]; // 2 triangles - D3DMATRIX matrix; - D3DVECTOR corner[4], eye, pos, goal, n, angle, proj; + Math::Matrix matrix; + Math::Vector corner[4], eye, pos, goal, n, angle, proj; Math::Point dim, texInf, texSup; bool bLeft; float a, len, adv, prop, vario1, vario2; @@ -3306,26 +3322,29 @@ void CParticule::DrawParticuleRay(int i) a = Math::RotateAngle(Math::Point(pos.x,pos.z), Math::Point(goal.x,goal.z), Math::Point(eye.x,eye.z)); bLeft = (a < Math::PI); - proj = Projection(pos, goal, eye); - angle.x = -Math::RotateAngle(Length2d(proj, eye), proj.y-eye.y); + proj = Math::Projection(pos, goal, eye); + angle.x = -Math::RotateAngle(Math::DistanceProjected(proj, eye), proj.y-eye.y); angle.y = Math::RotateAngle(pos.z-goal.z, pos.x-goal.x)+Math::PI/2.0f; - angle.z = -Math::RotateAngle(Length2d(pos, goal), pos.y-goal.y); + angle.z = -Math::RotateAngle(Math::DistanceProjected(pos, goal), pos.y-goal.y); if ( bLeft ) angle.x = -angle.x; - MatRotateZXY(matrix, angle); - matrix._41 = pos.x; - matrix._42 = pos.y; - matrix._43 = pos.z; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + Math::LoadRotationZXYMatrix(matrix, angle); + matrix.Set(1, 4, pos.x); + matrix.Set(2, 4, pos.y); + matrix.Set(3, 4, pos.z); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } - n = D3DVECTOR(0.0f, 0.0f, bLeft?1.0f:-1.0f); + n = Math::Vector(0.0f, 0.0f, bLeft?1.0f:-1.0f); dim.x = m_particule[i].dim.x * m_particule[i].zoom; dim.y = m_particule[i].dim.y * m_particule[i].zoom; if ( bLeft ) dim.y = -dim.y; - len = Length(pos, goal); + len = Math::Distance(pos, goal); adv = 0.0f; step = (int)(len/(dim.x*2.0f))+1; @@ -3449,8 +3468,8 @@ void CParticule::DrawParticuleRay(int i) void CParticule::DrawParticuleSphere(int i) { D3DVERTEX2 vertex[2*16*(16+1)]; // triangles - D3DMATRIX matrix, rot; - D3DVECTOR angle, v0, v1; + Math::Matrix matrix, rot; + Math::Vector angle, v0, v1; Math::Point ts, ti; float zoom, deltaRingAngle, deltaSegAngle; float r0,r1, tu0,tv0, tu1,tv1; @@ -3468,24 +3487,27 @@ void CParticule::DrawParticuleSphere(int i) m_engine->SetState(D3DSTATETTb|D3DSTATE2FACE|D3DSTATEWRAP, RetColor(m_particule[i].intensity)); - D3DUtil_SetIdentityMatrix(matrix); - matrix._11 = zoom; - matrix._22 = zoom; - matrix._33 = zoom; - matrix._41 = m_particule[i].pos.x; - matrix._42 = m_particule[i].pos.y; - matrix._43 = m_particule[i].pos.z; + matrix.LoadIdentity(); + matrix.Set(1, 1, zoom); + matrix.Set(2, 2, zoom); + matrix.Set(3, 3, zoom); + matrix.Set(1, 4, m_particule[i].pos.x); + matrix.Set(2, 4, m_particule[i].pos.y); + matrix.Set(3, 4, m_particule[i].pos.z); if ( m_particule[i].angle != 0.0f ) { angle.x = m_particule[i].angle*0.4f; angle.y = m_particule[i].angle*1.0f; angle.z = m_particule[i].angle*0.7f; - MatRotateZXY(rot, angle); - matrix = rot*matrix; + Math::LoadRotationZXYMatrix(rot, angle); + matrix = Math::MultiplyMatrices(rot, matrix); } - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } ts.x = m_particule[i].texSup.x; ts.y = m_particule[i].texSup.y; @@ -3566,8 +3588,8 @@ float ProgressCylinder(float progress) void CParticule::DrawParticuleCylinder(int i) { D3DVERTEX2 vertex[2*5*(10+1)]; // triangles - D3DMATRIX matrix, rot; - D3DVECTOR angle, v0, v1; + Math::Matrix matrix, rot; + Math::Vector angle, v0, v1; Math::Point ts, ti; float progress, zoom, diam, deltaSegAngle, h[6], d[6]; float r0,r1, tu0,tv0, tu1,tv1, p1, p2, pp; @@ -3580,15 +3602,18 @@ void CParticule::DrawParticuleCylinder(int i) m_engine->SetState(D3DSTATETTb|D3DSTATE2FACE|D3DSTATEWRAP, RetColor(m_particule[i].intensity)); - D3DUtil_SetIdentityMatrix(matrix); - matrix._11 = zoom; - matrix._22 = zoom; - matrix._33 = zoom; - matrix._41 = m_particule[i].pos.x; - matrix._42 = m_particule[i].pos.y; - matrix._43 = m_particule[i].pos.z; + matrix.LoadIdentity(); + matrix.Set(1, 1, zoom); + matrix.Set(2, 2, zoom); + matrix.Set(3, 3, zoom); + matrix.Set(1, 4, m_particule[i].pos.x); + matrix.Set(2, 4, m_particule[i].pos.y); + matrix.Set(3, 4, m_particule[i].pos.z); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } ts.x = m_particule[i].texSup.x; ts.y = m_particule[i].texSup.y; @@ -3666,13 +3691,13 @@ void CParticule::DrawParticuleCylinder(int i) void CParticule::DrawParticuleWheel(int i) { - D3DVECTOR pos[4], center; + Math::Vector pos[4], center; D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR n; + Math::Vector n; Math::Point ts, ti; float dist, dp; - dist = Length2d(m_engine->RetEyePt(), m_wheelTrace[i].pos[0]); + dist = Math::DistanceProjected(m_engine->RetEyePt(), m_wheelTrace[i].pos[0]); if ( dist > 300.0f ) return; pos[0] = m_wheelTrace[i].pos[0]; @@ -3793,7 +3818,7 @@ void CParticule::DrawParticuleWheel(int i) ti.x = ti.x-dp; ti.y = ti.y-dp; - n = D3DVECTOR(0.0f, 1.0f, 0.0f); + n = Math::Vector(0.0f, 1.0f, 0.0f); vertex[0] = D3DVERTEX2(pos[0], n, ts.x, ts.y); vertex[1] = D3DVERTEX2(pos[1], n, ti.x, ts.y); @@ -3809,7 +3834,7 @@ void CParticule::DrawParticuleWheel(int i) void CParticule::DrawParticule(int sheet) { D3DMATERIAL7 mat; - D3DMATRIX matrix; + Math::Matrix matrix; bool bLoadTexture; char name[20]; int state, t, i, j, r; @@ -3857,8 +3882,11 @@ void CParticule::DrawParticule(int sheet) #endif m_engine->SetState(D3DSTATETTw); //? m_engine->SetState(D3DSTATENORMAL); - D3DUtil_SetIdentityMatrix(matrix); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } for ( i=0 ; iRetShieldRadius(); if ( shieldRadius > 0.0f ) { - dist = Length(oPos, pos); + dist = Math::Distance(oPos, pos); if ( dist <= shieldRadius ) { pBest = pObj; @@ -4056,7 +4084,7 @@ CObject* CParticule::SearchObjectGun(D3DVECTOR old, D3DVECTOR pos, // Test the center of the object, which is necessary for objects // that have no sphere in the center (station). - dist = Length(oPos, pos)-4.0f; + dist = Math::Distance(oPos, pos)-4.0f; if ( dist < min ) { pBest = pObj; @@ -4070,8 +4098,8 @@ CObject* CParticule::SearchObjectGun(D3DVECTOR old, D3DVECTOR pos, oPos.y+oRadius < box1.y || oPos.y-oRadius > box2.y || oPos.z+oRadius < box1.z || oPos.z-oRadius > box2.z ) continue; - p = Projection(old, pos, oPos); - dist = Length(p, oPos)-oRadius; + p = Math::Projection(old, pos, oPos); + dist = Math::Distance(p, oPos)-oRadius; if ( dist < min ) { pBest = pObj; @@ -4084,11 +4112,11 @@ CObject* CParticule::SearchObjectGun(D3DVECTOR old, D3DVECTOR pos, // Seeks if an object collided with a ray. -CObject* CParticule::SearchObjectRay(D3DVECTOR pos, D3DVECTOR goal, +CObject* CParticule::SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticuleType type, CObject *father) { CObject* pObj; - D3DVECTOR box1, box2, oPos, p; + Math::Vector box1, box2, oPos, p; ObjectType oType; float min, dist; int i; @@ -4138,8 +4166,8 @@ CObject* CParticule::SearchObjectRay(D3DVECTOR pos, D3DVECTOR goal, oPos.y < box1.y || oPos.y > box2.y || oPos.z < box1.z || oPos.z > box2.z ) continue; - p = Projection(pos, goal, oPos); - dist = Length(p, oPos); + p = Math::Projection(pos, goal, oPos); + dist = Math::Distance(p, oPos); if ( dist < min ) return pObj; } @@ -4149,7 +4177,7 @@ CObject* CParticule::SearchObjectRay(D3DVECTOR pos, D3DVECTOR goal, // Sounded one. -void CParticule::Play(Sound sound, D3DVECTOR pos, float amplitude) +void CParticule::Play(Sound sound, Math::Vector pos, float amplitude) { if ( m_sound == 0 ) { @@ -4164,7 +4192,7 @@ void CParticule::Play(Sound sound, D3DVECTOR pos, float amplitude) // Seeks the color if you're in the fog. // Returns black if you're not in the fog. -D3DCOLORVALUE CParticule::RetFogColor(D3DVECTOR pos) +D3DCOLORVALUE CParticule::RetFogColor(Math::Vector pos) { D3DCOLORVALUE result, color; float dist, factor; @@ -4182,7 +4210,7 @@ D3DCOLORVALUE CParticule::RetFogColor(D3DVECTOR pos) if ( pos.y >= m_particule[i].pos.y+FOG_HSUP ) continue; if ( pos.y <= m_particule[i].pos.y-FOG_HINF ) continue; - dist = Length2d(pos, m_particule[i].pos); + dist = Math::DistanceProjected(pos, m_particule[i].pos); if ( dist >= m_particule[i].dim.x*1.5f ) continue; // Calculates the horizontal distance. @@ -4251,7 +4279,7 @@ D3DCOLORVALUE CParticule::RetFogColor(D3DVECTOR pos) // Writes a file. BMP containing all the tire tracks. bool CParticule::WriteWheelTrace(char *filename, int width, int height, - D3DVECTOR dl, D3DVECTOR ur) + Math::Vector dl, Math::Vector ur) { HDC hDC; HDC hDCImage; diff --git a/src/graphics/common/particule.h b/src/graphics/common/particule.h index 19e4053..d82e0a7 100644 --- a/src/graphics/common/particule.h +++ b/src/graphics/common/particule.h @@ -213,9 +213,9 @@ struct Particule float mass; // mass of the particle (in rebounding) float weight; // weight of the particle (for noise) float duration; // length of life - D3DVECTOR pos; // absolute position (relative if object links) - D3DVECTOR goal; // goal position (if bRay) - D3DVECTOR speed; // speed of displacement + Math::Vector pos; // absolute position (relative if object links) + Math::Vector goal; // goal position (if bRay) + Math::Vector speed; // speed of displacement float windSensitivity; short bounce; // number of rebounds Math::Point dim; // dimensions of the rectangle @@ -243,14 +243,14 @@ struct Track float width; // tail width int used; // number of positions in "pos" int head; // head to write index - D3DVECTOR pos[MAXTRACKLEN]; + Math::Vector pos[MAXTRACKLEN]; float len[MAXTRACKLEN]; }; struct WheelTrace { ParticuleType type; // type PARTI* - D3DVECTOR pos[4]; // rectangle positions + Math::Vector pos[4]; // rectangle positions float startTime; // beginning of life }; @@ -266,32 +266,32 @@ public: void FlushParticule(); void FlushParticule(int sheet); - int CreateParticule(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateFrag(D3DVECTOR pos, D3DVECTOR speed, D3DTriangle *triangle, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreatePart(D3DVECTOR pos, D3DVECTOR speed, ParticuleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateRay(D3DVECTOR pos, D3DVECTOR goal, ParticuleType type, Math::Point dim, float duration=1.0f, int sheet=0); - int CreateTrack(D3DVECTOR pos, D3DVECTOR speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f); - void CreateWheelTrace(const D3DVECTOR &p1, const D3DVECTOR &p2, const D3DVECTOR &p3, const D3DVECTOR &p4, ParticuleType type); + int CreateParticule(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreateFrag(Math::Vector pos, Math::Vector speed, D3DTriangle *triangle, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreatePart(Math::Vector pos, Math::Vector speed, ParticuleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0); + int CreateRay(Math::Vector pos, Math::Vector goal, ParticuleType type, Math::Point dim, float duration=1.0f, int sheet=0); + int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f); + void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, const Math::Vector &p4, ParticuleType type); void DeleteParticule(ParticuleType type); void DeleteParticule(int channel); void SetObjectLink(int channel, CObject *object); void SetObjectFather(int channel, CObject *object); - void SetPosition(int channel, D3DVECTOR pos); + void SetPosition(int channel, Math::Vector pos); void SetDimension(int channel, Math::Point dim); void SetZoom(int channel, float zoom); void SetAngle(int channel, float angle); void SetIntensity(int channel, float intensity); - void SetParam(int channel, D3DVECTOR pos, Math::Point dim, float zoom, float angle, float intensity); + void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity); void SetPhase(int channel, ParticulePhase phase, float duration); - bool GetPosition(int channel, D3DVECTOR &pos); + bool GetPosition(int channel, Math::Vector &pos); - D3DCOLORVALUE RetFogColor(D3DVECTOR pos); + D3DCOLORVALUE RetFogColor(Math::Vector pos); void SetFrameUpdate(int sheet, bool bUpdate); void FrameParticule(float rTime); void DrawParticule(int sheet); - bool WriteWheelTrace(char *filename, int width, int height, D3DVECTOR dl, D3DVECTOR ur); + bool WriteWheelTrace(char *filename, int width, int height, Math::Vector dl, Math::Vector ur); protected: void DeleteRank(int rank); @@ -304,10 +304,10 @@ protected: void DrawParticuleSphere(int i); void DrawParticuleCylinder(int i); void DrawParticuleWheel(int i); - CObject* SearchObjectGun(D3DVECTOR old, D3DVECTOR pos, ParticuleType type, CObject *father); - CObject* SearchObjectRay(D3DVECTOR pos, D3DVECTOR goal, ParticuleType type, CObject *father); - void Play(Sound sound, D3DVECTOR pos, float amplitude); - bool TrackMove(int i, D3DVECTOR pos, float progress); + CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticuleType type, CObject *father); + CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticuleType type, CObject *father); + void Play(Sound sound, Math::Vector pos, float amplitude); + bool TrackMove(int i, Math::Vector pos, float progress); void TrackDraw(int i, ParticuleType type); protected: diff --git a/src/graphics/common/planet.cpp b/src/graphics/common/planet.cpp index 5353c54..6be1d31 100644 --- a/src/graphics/common/planet.cpp +++ b/src/graphics/common/planet.cpp @@ -135,7 +135,7 @@ void CPlanet::Draw() { LPDIRECT3DDEVICE7 device; D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR n; + Math::Vector n; Math::Point p1, p2; float eyeDirH, eyeDirV, dp, u1, u2, v1, v2, a; int i; @@ -144,7 +144,7 @@ void CPlanet::Draw() eyeDirH = m_engine->RetEyeDirH(); eyeDirV = m_engine->RetEyeDirV(); - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal dp = 0.5f/256.0f; for ( i=0 ; iDrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); diff --git a/src/graphics/common/pyro.cpp b/src/graphics/common/pyro.cpp index 0f187c8..443d428 100644 --- a/src/graphics/common/pyro.cpp +++ b/src/graphics/common/pyro.cpp @@ -23,6 +23,7 @@ #include "common/struct.h" #include "math/const.h" +#include "math/geometry.h" #include "graphics/d3d/d3dengine.h" #include "math/old/d3dmath.h" #include "common/event.h" @@ -92,10 +93,10 @@ void CPyro::DeleteObject(bool bAll) bool CPyro::Create(PyroType type, CObject* pObj, float force) { - D3DMATRIX* mat; + Math::Matrix* mat; CObject* power; CMotion* motion; - D3DVECTOR min, max, pos, speed; + Math::Vector min, max, pos, speed; Math::Point dim; ObjectType oType; Sound sound; @@ -130,7 +131,7 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) } else { - m_size = Length(min, max)*2.0f; + m_size = Math::Distance(min, max)*2.0f; if ( m_size < 4.0f ) m_size = 4.0f; if ( m_size > 80.0f ) m_size = 80.0f; } @@ -167,7 +168,7 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) pos = power->RetPosition(0); pos.y += 1.0f; mat = pObj->RetWorldMatrix(0); - m_posPower = Transform(*mat, pos); + m_posPower = Math::Transform(*mat, pos); } if ( oType == OBJECT_POWER || oType == OBJECT_ATOMIC || @@ -184,14 +185,14 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) { m_bPower = true; mat = pObj->RetWorldMatrix(0); - m_posPower = Transform(*mat, D3DVECTOR(-15.0f, 7.0f, 0.0f)); + m_posPower = Math::Transform(*mat, Math::Vector(-15.0f, 7.0f, 0.0f)); m_pos = m_posPower; } if ( oType == OBJECT_ENERGY ) { m_bPower = true; mat = pObj->RetWorldMatrix(0); - m_posPower = Transform(*mat, D3DVECTOR(-7.0f, 6.0f, 0.0f)); + m_posPower = Math::Transform(*mat, Math::Vector(-7.0f, 6.0f, 0.0f)); m_pos = m_posPower; } if ( oType == OBJECT_NUCLEAR ) @@ -416,9 +417,9 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) { m_speed = 1.0f/15.0f; - pos = D3DVECTOR(-3.0f, 2.0f, 0.0f); + pos = Math::Vector(-3.0f, 2.0f, 0.0f); mat = pObj->RetWorldMatrix(0); - m_pos = Transform(*mat, pos); + m_pos = Math::Transform(*mat, pos); m_engine->ShadowDelete(m_object->RetObjectRank(0)); } @@ -541,7 +542,7 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) } dim.x = m_size*0.4f; dim.y = dim.x; - m_particule->CreateParticule(pos, D3DVECTOR(0.0f,0.0f,0.0f), dim, PARTISPHERE0, 2.0f, 0.0f, 0.0f); + m_particule->CreateParticule(pos, Math::Vector(0.0f,0.0f,0.0f), dim, PARTISPHERE0, 2.0f, 0.0f, 0.0f); } } @@ -621,7 +622,7 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) pos = m_pos; //? m_terrain->MoveOnFloor(pos); //? pos.y += 2.0f; - speed = D3DVECTOR(0.0f, 0.0f, 0.0f); + speed = Math::Vector(0.0f, 0.0f, 0.0f); dim.x = m_size; dim.y = dim.x; m_particule->CreateParticule(pos, speed, dim, PARTICHOC, 2.0f); @@ -636,8 +637,8 @@ bool CPyro::Create(PyroType type, CObject* pObj, float force) void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) { D3DTriangle buffer[100]; - D3DMATRIX* mat; - D3DVECTOR offset, pos, speed; + Math::Matrix* mat; + Math::Vector offset, pos, speed; float percent, min, max, h, duration, mass; int objRank, total, i; @@ -665,7 +666,7 @@ void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) for ( i=0 ; i 5.0f ) { p2.x = p1.x+((p2.x-p1.x)*5.0f/h); @@ -685,7 +686,7 @@ void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) p2.z = p1.z+((p2.z-p1.z)*5.0f/h); } - h = Length(p2, p3); + h = Math::Distance(p2, p3); if ( h > 5.0f ) { p3.x = p2.x+((p3.x-p2.x)*5.0f/h); @@ -693,7 +694,7 @@ void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) p3.z = p2.z+((p3.z-p2.z)*5.0f/h); } - h = Length(p3, p1); + h = Math::Distance(p3, p1); if ( h > 5.0f ) { p1.x = p3.x+((p1.x-p3.x)*5.0f/h); @@ -728,7 +729,7 @@ void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) buffer[i].triangle[2].z -= offset.z; mat = pObj->RetWorldMatrix(part); - pos = Transform(*mat, offset); + pos = Math::Transform(*mat, offset); if ( m_type == PT_EGG ) { speed.x = (Math::Rand()-0.5f)*10.0f; @@ -851,7 +852,7 @@ void CPyro::DisplayError(PyroType type, CObject* pObj) bool CPyro::EventProcess(const Event &event) { ParticuleType type; - D3DVECTOR pos, speed, angle; + Math::Vector pos, speed, angle; Math::Point dim; float prog, factor, duration; int i, r; @@ -1463,7 +1464,7 @@ Error CPyro::IsEnded() void CPyro::DeleteObject(bool bPrimary, bool bSecondary) { CObject *sub, *truck; - D3DVECTOR pos; + Math::Vector pos; ObjectType type; if ( m_object == 0 ) return; @@ -1579,7 +1580,7 @@ void CPyro::LightOperFrame(float rTime) // Creates light to accompany a pyrotechnic effect. -bool CPyro::CreateLight(D3DVECTOR pos, float height) +bool CPyro::CreateLight(Math::Vector pos, float height) { D3DLIGHT7 light; @@ -1620,7 +1621,7 @@ bool CPyro::CreateLight(D3DVECTOR pos, float height) void CPyro::ExploStart() { - D3DVECTOR pos, angle, speed, min, max; + Math::Vector pos, angle, speed, min, max; float weight; int i, objRank, channel; @@ -1661,7 +1662,7 @@ void CPyro::ExploStart() else { m_engine->GetBBox(objRank, min, max); - weight = Length(min, max); // weight according to size! + weight = Math::Distance(min, max); // weight according to size! speed.y = 10.0f+Math::Rand()*20.0f; speed.x = (Math::Rand()-0.5f)*20.0f; @@ -1691,7 +1692,7 @@ void CPyro::ExploTerminate() void CPyro::BurnStart() { - D3DVECTOR pos, angle; + Math::Vector pos, angle; int i, objRank; m_burnType = m_object->RetType(); @@ -2162,7 +2163,7 @@ void CPyro::BurnStart() // Adds a part move. -void CPyro::BurnAddPart(int part, D3DVECTOR pos, D3DVECTOR angle) +void CPyro::BurnAddPart(int part, Math::Vector pos, Math::Vector angle) { int i; @@ -2181,7 +2182,7 @@ void CPyro::BurnAddPart(int part, D3DVECTOR pos, D3DVECTOR angle) void CPyro::BurnProgress() { CObject* sub; - D3DVECTOR pos; + Math::Vector pos; float h; int i; @@ -2285,7 +2286,7 @@ void CPyro::BurnTerminate() void CPyro::FallStart() { - D3DVECTOR pos; + Math::Vector pos; m_object->SetBurn(true); // usable @@ -2301,7 +2302,7 @@ void CPyro::FallStart() CObject* CPyro::FallSearchBeeExplo() { CObject* pObj; - D3DVECTOR iPos, oPos; + Math::Vector iPos, oPos; ObjectType oType; float iRadius, oRadius, distance, shieldRadius; int i, j; @@ -2370,26 +2371,26 @@ CObject* CPyro::FallSearchBeeExplo() shieldRadius = pObj->RetShieldRadius(); if ( shieldRadius > 0.0f ) { - distance = Length(oPos, iPos); + distance = Math::Distance(oPos, iPos); if ( distance <= shieldRadius ) return pObj; } if ( oType == OBJECT_BASE ) { - distance = Length(oPos, iPos); + distance = Math::Distance(oPos, iPos); if ( distance < 25.0f ) return pObj; } // Test the center of the object, which is necessary for objects // that have no sphere in the center (station). - distance = Length(oPos, iPos)-4.0f; + distance = Math::Distance(oPos, iPos)-4.0f; if ( distance < 5.0f ) return pObj; // Test with all spheres of the object. j = 0; while ( pObj->GetCrashSphere(j++, oPos, oRadius) ) { - distance = Length(oPos, iPos); + distance = Math::Distance(oPos, iPos); if ( distance <= iRadius+oRadius ) { return pObj; @@ -2404,7 +2405,7 @@ CObject* CPyro::FallSearchBeeExplo() void CPyro::FallProgress(float rTime) { CObject* pObj; - D3DVECTOR pos; + Math::Vector pos; bool bFloor = false; if ( m_object == 0 ) return; @@ -2440,7 +2441,7 @@ void CPyro::FallProgress(float rTime) { if ( pObj->RetShieldRadius() > 0.0f ) // protected by shield? { - m_particule->CreateParticule(pos, D3DVECTOR(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f, 0.0f, 0.0f); + m_particule->CreateParticule(pos, Math::Vector(0.0f, 0.0f, 0.0f), Math::Point(6.0f, 6.0f), PARTIGUNDEL, 2.0f, 0.0f, 0.0f); m_sound->Play(SOUND_GUNDEL); DeleteObject(true, true); // removes the ball @@ -2470,7 +2471,7 @@ void CPyro::FallProgress(float rTime) Error CPyro::FallIsEnded() { - D3DVECTOR pos; + Math::Vector pos; if ( m_bFallEnding || m_object == 0 ) return ERR_STOP; diff --git a/src/graphics/common/pyro.h b/src/graphics/common/pyro.h index d898a94..9f35438 100644 --- a/src/graphics/common/pyro.h +++ b/src/graphics/common/pyro.h @@ -70,10 +70,10 @@ enum PyroType struct PyroBurnPart { int part; - D3DVECTOR initialPos; - D3DVECTOR finalPos; - D3DVECTOR initialAngle; - D3DVECTOR finalAngle; + Math::Vector initialPos; + Math::Vector finalPos; + Math::Vector initialAngle; + Math::Vector finalAngle; }; struct PyroLightOper @@ -99,7 +99,7 @@ public: protected: void DisplayError(PyroType type, CObject* pObj); - bool CreateLight(D3DVECTOR pos, float height); + bool CreateLight(Math::Vector pos, float height); void DeleteObject(bool bPrimary, bool bSecondary); void CreateTriangle(CObject* pObj, ObjectType oType, int part); @@ -108,7 +108,7 @@ protected: void ExploTerminate(); void BurnStart(); - void BurnAddPart(int part, D3DVECTOR pos, D3DVECTOR angle); + void BurnAddPart(int part, Math::Vector pos, Math::Vector angle); void BurnProgress(); bool BurnIsKeepPart(int part); void BurnTerminate(); @@ -134,8 +134,8 @@ protected: CRobotMain* m_main; CSound* m_sound; - D3DVECTOR m_pos; // center of the effect - D3DVECTOR m_posPower; // center of the battery + Math::Vector m_pos; // center of the effect + Math::Vector m_posPower; // center of the battery bool m_bPower; // battery exists? PyroType m_type; float m_force; @@ -164,7 +164,7 @@ protected: bool m_bFallEnding; int m_crashSphereUsed; // number of spheres used - D3DVECTOR m_crashSpherePos[50]; + Math::Vector m_crashSpherePos[50]; float m_crashSphereRadius[50]; }; diff --git a/src/graphics/common/terrain.cpp b/src/graphics/common/terrain.cpp index dbf92c3..edc1611 100644 --- a/src/graphics/common/terrain.cpp +++ b/src/graphics/common/terrain.cpp @@ -70,7 +70,7 @@ CTerrain::CTerrain(CInstanceManager* iMan) m_levelMatTotal = 0; m_levelMatMax = 0; m_levelDot = 0; - m_wind = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_wind = Math::Vector(0.0f, 0.0f, 0.0f); m_defHardness = 0.5f; FlushBuildingLevel(); @@ -299,7 +299,7 @@ bool CTerrain::ResFromBMP(const char* filename) // Returns the resource type available underground. -TerrainRes CTerrain::RetResource(const D3DVECTOR &p) +TerrainRes CTerrain::RetResource(const Math::Vector &p) { int x, y, size, sizem, ress; @@ -405,7 +405,7 @@ bool CTerrain::ReliefFromBMP(const char* filename, float scaleRelief, // Adds a point of elevation in the buffer of relief. -bool CTerrain::ReliefAddDot(D3DVECTOR pos, float scaleRelief) +bool CTerrain::ReliefAddDot(Math::Vector pos, float scaleRelief) { float dim; int size, x, y; @@ -436,7 +436,7 @@ bool CTerrain::ReliefFromDXF(const char* filename, float scaleRelief) FILE* file = NULL; char line[100]; int command, rankSommet, nbSommet, nbFace, size; - D3DVECTOR* table; + Math::Vector* table; bool bWaitNbSommet; bool bWaitNbFace; bool bWaitSommetX; @@ -454,7 +454,7 @@ bool CTerrain::ReliefFromDXF(const char* filename, float scaleRelief) if ( file == NULL ) return false; size = (m_mosaic*m_brick)+1; - table = (D3DVECTOR*)malloc(sizeof(D3DVECTOR)*size*size); + table = (Math::Vector*)malloc(sizeof(Math::Vector)*size*size); rankSommet = 0; bWaitNbSommet = false; @@ -514,7 +514,7 @@ bool CTerrain::ReliefFromDXF(const char* filename, float scaleRelief) nbSommet --; if ( nbSommet >= 0 ) { - D3DVECTOR p(x,z,y); // permutation of Y and Z! + Math::Vector p(x,z,y); // permutation of Y and Z! table[rankSommet++] = p; bWaitSommetX = true; } @@ -566,7 +566,7 @@ bool CTerrain::ReliefFromDXF(const char* filename, float scaleRelief) // Adjusts a position so that it does not exceed the boundaries. -void CTerrain::LimitPos(D3DVECTOR &pos) +void CTerrain::LimitPos(Math::Vector &pos) { float dim; @@ -649,9 +649,9 @@ void CTerrain::AdjustRelief() // Calculates a vector of the terrain. -D3DVECTOR CTerrain::RetVector(int x, int y) +Math::Vector CTerrain::RetVector(int x, int y) { - D3DVECTOR p; + Math::Vector p; p.x = x*m_size - (m_mosaic*m_brick*m_size)/2; p.z = y*m_size - (m_mosaic*m_brick*m_size)/2; @@ -686,7 +686,7 @@ D3DVECTOR CTerrain::RetVector(int x, int y) D3DVERTEX2 CTerrain::RetVertex(int x, int y, int step) { D3DVERTEX2 v; - D3DVECTOR o, oo, a,b,c,d,e,f, n, s; + Math::Vector o, oo, a,b,c,d,e,f, n, s; int brick; o = RetVector(x, y); @@ -701,28 +701,28 @@ D3DVERTEX2 CTerrain::RetVertex(int x, int y, int step) e = RetVector(x+step, y-step); f = RetVector(x, y-step); - s = D3DVECTOR(0.0f, 0.0f, 0.0f); + s = Math::Vector(0.0f, 0.0f, 0.0f); if ( x-step >= 0 && y+step <= m_mosaic*m_brick+1 ) { - s += ComputeNormal(b,a,o); - s += ComputeNormal(c,b,o); + s += Math::NormalToPlane(b,a,o); + s += Math::NormalToPlane(c,b,o); } if ( x+step <= m_mosaic*m_brick+1 && y+step <= m_mosaic*m_brick+1 ) { - s += ComputeNormal(d,c,o); + s += Math::NormalToPlane(d,c,o); } if ( x+step <= m_mosaic*m_brick+1 && y-step >= 0 ) { - s += ComputeNormal(e,d,o); - s += ComputeNormal(f,e,o); + s += Math::NormalToPlane(e,d,o); + s += Math::NormalToPlane(f,e,o); } if ( x-step >= 0 && y-step >= 0 ) { - s += ComputeNormal(a,f,o); + s += Math::NormalToPlane(a,f,o); } s = Normalize(s); @@ -763,7 +763,7 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, const D3DMATERIAL7 &mat, float min, float max) { - D3DMATRIX transform; + Math::Matrix transform; D3DVERTEX2 o, p1, p2; D3DObjLevel6* buffer; Math::Point uv; @@ -915,9 +915,9 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, } } - D3DUtil_SetIdentityMatrix(transform); - transform._41 = o.x; - transform._43 = o.z; + transform.LoadIdentity(); + transform.Set(1, 4, o.x); + transform.Set(3, 4, o.z); m_engine->SetObjectTransform(objRank, transform); return true; @@ -1403,10 +1403,10 @@ bool CTerrain::LevelInit(int id) bool CTerrain::LevelGenerate(int *id, float min, float max, float slope, float freq, - D3DVECTOR center, float radius) + Math::Vector center, float radius) { TerrainMaterial *tm; - D3DVECTOR pos; + Math::Vector pos; int i, numID, x, y, xx, yy, group, rnd; float dim; @@ -1461,7 +1461,7 @@ bool CTerrain::LevelGenerate(int *id, float min, float max, { pos.x = ((float)x-m_levelDotSize/2.0f)*group*m_size; pos.z = ((float)y-m_levelDotSize/2.0f)*group*m_size; - if ( Length2d(pos, center) > radius ) continue; + if ( Math::DistanceProjected(pos, center) > radius ) continue; } if ( freq < 100.0f ) @@ -1582,7 +1582,7 @@ bool CTerrain::CreateObjects(bool bMultiRes) // Modifies the terrain's relief. // ATTENTION: ok only with m_depth = 2! -bool CTerrain::Terraform(const D3DVECTOR &p1, const D3DVECTOR &p2, float height) +bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height) { POINT tp1, tp2, pp1, pp2; float dim, avg; @@ -1671,12 +1671,12 @@ bool CTerrain::Terraform(const D3DVECTOR &p1, const D3DVECTOR &p2, float height) // Management of the wind. -void CTerrain::SetWind(D3DVECTOR speed) +void CTerrain::SetWind(Math::Vector speed) { m_wind = speed; } -D3DVECTOR CTerrain::RetWind() +Math::Vector CTerrain::RetWind() { return m_wind; } @@ -1684,17 +1684,17 @@ D3DVECTOR CTerrain::RetWind() // Gives the exact slope of the terrain of a place given. -float CTerrain::RetFineSlope(const D3DVECTOR &pos) +float CTerrain::RetFineSlope(const Math::Vector &pos) { - D3DVECTOR n; + Math::Vector n; if ( !GetNormal(n, pos) ) return 0.0f; - return fabs(Math::RotateAngle(Length(n.x, n.z), n.y)-Math::PI/2.0f); + return fabs(Math::RotateAngle(Math::Point(n.x, n.z).Length(), n.y)-Math::PI/2.0f); } // Gives the approximate slope of the terrain of a specific location. -float CTerrain::RetCoarseSlope(const D3DVECTOR &pos) +float CTerrain::RetCoarseSlope(const Math::Vector &pos) { float dim, level[4], min, max; int x, y; @@ -1722,9 +1722,9 @@ float CTerrain::RetCoarseSlope(const D3DVECTOR &pos) // Gives the normal vector at the position p (x,-,z) of the ground. -bool CTerrain::GetNormal(D3DVECTOR &n, const D3DVECTOR &p) +bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) { - D3DVECTOR p1, p2, p3, p4; + Math::Vector p1, p2, p3, p4; float dim; int x, y; @@ -1743,20 +1743,20 @@ bool CTerrain::GetNormal(D3DVECTOR &n, const D3DVECTOR &p) if ( fabs(p.z-p2.z) < fabs(p.x-p2.x) ) { - n = ComputeNormal(p1,p2,p3); + n = Math::NormalToPlane(p1,p2,p3); } else { - n = ComputeNormal(p2,p4,p3); + n = Math::NormalToPlane(p2,p4,p3); } return true; } // Returns the height of the ground. -float CTerrain::RetFloorLevel(const D3DVECTOR &p, bool bBrut, bool bWater) +float CTerrain::RetFloorLevel(const Math::Vector &p, bool bBrut, bool bWater) { - D3DVECTOR p1, p2, p3, p4, ps; + Math::Vector p1, p2, p3, p4, ps; float dim, level; int x, y; @@ -1797,9 +1797,9 @@ float CTerrain::RetFloorLevel(const D3DVECTOR &p, bool bBrut, bool bWater) // Returns the height to the ground. // This height is positive when you are above the ground. -float CTerrain::RetFloorHeight(const D3DVECTOR &p, bool bBrut, bool bWater) +float CTerrain::RetFloorHeight(const Math::Vector &p, bool bBrut, bool bWater) { - D3DVECTOR p1, p2, p3, p4, ps; + Math::Vector p1, p2, p3, p4, ps; float dim, level; int x, y; @@ -1839,9 +1839,9 @@ float CTerrain::RetFloorHeight(const D3DVECTOR &p, bool bBrut, bool bWater) // Modifies the coordinate "y" of point "p" to rest on the ground floor. -bool CTerrain::MoveOnFloor(D3DVECTOR &p, bool bBrut, bool bWater) +bool CTerrain::MoveOnFloor(Math::Vector &p, bool bBrut, bool bWater) { - D3DVECTOR p1, p2, p3, p4; + Math::Vector p1, p2, p3, p4; float dim, level; int x, y; @@ -1881,7 +1881,7 @@ bool CTerrain::MoveOnFloor(D3DVECTOR &p, bool bBrut, bool bWater) // Modifies a coordinate so that it is on the ground. // Returns false if the initial coordinate was too far. -bool CTerrain::ValidPosition(D3DVECTOR &p, float marging) +bool CTerrain::ValidPosition(Math::Vector &p, float marging) { bool bOK = true; float limit; @@ -1926,7 +1926,7 @@ void CTerrain::FlushBuildingLevel() // Adds a new elevation for a building. -bool CTerrain::AddBuildingLevel(D3DVECTOR center, float min, float max, +bool CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor) { int i; @@ -1960,7 +1960,7 @@ bool CTerrain::AddBuildingLevel(D3DVECTOR center, float min, float max, // Updates the elevation for a building when it was moved up (after a terraforming). -bool CTerrain::UpdateBuildingLevel(D3DVECTOR center) +bool CTerrain::UpdateBuildingLevel(Math::Vector center) { int i; @@ -1979,7 +1979,7 @@ bool CTerrain::UpdateBuildingLevel(D3DVECTOR center) // Removes the elevation for a building when it was destroyed. -bool CTerrain::DeleteBuildingLevel(D3DVECTOR center) +bool CTerrain::DeleteBuildingLevel(Math::Vector center) { int i, j; @@ -2001,7 +2001,7 @@ bool CTerrain::DeleteBuildingLevel(D3DVECTOR center) // Returns the influence factor whether a position is on a possible rise. -float CTerrain::RetBuildingFactor(const D3DVECTOR &p) +float CTerrain::RetBuildingFactor(const Math::Vector &p) { float dist; int i; @@ -2013,7 +2013,7 @@ float CTerrain::RetBuildingFactor(const D3DVECTOR &p) p.z < m_buildingTable[i].bboxMinZ || p.z > m_buildingTable[i].bboxMaxZ ) continue; - dist = Length2d(p, m_buildingTable[i].center); + dist = Math::DistanceProjected(p, m_buildingTable[i].center); if ( dist <= m_buildingTable[i].max ) { @@ -2025,9 +2025,9 @@ float CTerrain::RetBuildingFactor(const D3DVECTOR &p) // Adjusts a position according to a possible rise. -void CTerrain::AdjustBuildingLevel(D3DVECTOR &p) +void CTerrain::AdjustBuildingLevel(Math::Vector &p) { - D3DVECTOR border; + Math::Vector border; float dist, base; int i; @@ -2038,7 +2038,7 @@ void CTerrain::AdjustBuildingLevel(D3DVECTOR &p) p.z < m_buildingTable[i].bboxMinZ || p.z > m_buildingTable[i].bboxMaxZ ) continue; - dist = Length2d(p, m_buildingTable[i].center); + dist = Math::DistanceProjected(p, m_buildingTable[i].center); if ( dist > m_buildingTable[i].max ) continue; @@ -2077,7 +2077,7 @@ void CTerrain::AdjustBuildingLevel(D3DVECTOR &p) // Returns the hardness of the ground in a given place. // The hardness determines the noise (SOUND_STEP and SOUND_BOUM). -float CTerrain::RetHardness(const D3DVECTOR &p) +float CTerrain::RetHardness(const Math::Vector &p) { TerrainMaterial* tm; float factor, dim; @@ -2112,9 +2112,9 @@ float CTerrain::RetHardness(const D3DVECTOR &p) // Shows the flat areas on the ground. -void CTerrain::GroundFlat(D3DVECTOR pos) +void CTerrain::GroundFlat(Math::Vector pos) { - D3DVECTOR p; + Math::Vector p; float rapport, angle; int x, y, i; static char table[41*41]; @@ -2132,7 +2132,7 @@ void CTerrain::GroundFlat(D3DVECTOR pos) p.x = (x-20)*rapport; p.z = (y-20)*rapport; p.y = 0.0f; - if ( Length(p.x, p.y) > 20.0f*rapport ) continue; + if ( Math::Point(p.x, p.y).Length() > 20.0f*rapport ) continue; angle = RetFineSlope(pos+p); @@ -2154,9 +2154,9 @@ void CTerrain::GroundFlat(D3DVECTOR pos) // Calculates the radius of the largest flat area available. // This calculation is not optimized! -float CTerrain::RetFlatZoneRadius(D3DVECTOR center, float max) +float CTerrain::RetFlatZoneRadius(Math::Vector center, float max) { - D3DVECTOR pos; + Math::Vector pos; Math::Point c, p; float ref, radius, angle, h; int i, nb; @@ -2218,7 +2218,7 @@ void CTerrain::FlushFlyingLimit() // Empty the limits table of flight. -bool CTerrain::AddFlyingLimit(D3DVECTOR center, +bool CTerrain::AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight) { @@ -2238,7 +2238,7 @@ bool CTerrain::AddFlyingLimit(D3DVECTOR center, // Returns the maximum height of flight. -float CTerrain::RetFlyingLimit(D3DVECTOR pos, bool bNoLimit) +float CTerrain::RetFlyingLimit(Math::Vector pos, bool bNoLimit) { float dist, h; int i; @@ -2248,7 +2248,7 @@ float CTerrain::RetFlyingLimit(D3DVECTOR pos, bool bNoLimit) for ( i=0 ; i= m_flyingLimit[i].extRadius ) continue; diff --git a/src/graphics/common/terrain.h b/src/graphics/common/terrain.h index dd04377..d41cd15 100644 --- a/src/graphics/common/terrain.h +++ b/src/graphics/common/terrain.h @@ -50,7 +50,7 @@ const int MAXBUILDINGLEVEL = 100; struct BuildingLevel { - D3DVECTOR center; + Math::Vector center; float factor; float min; float max; @@ -85,7 +85,7 @@ const int MAXFLYINGLIMIT = 10; struct FlyingLimit { - D3DVECTOR center; + Math::Vector center; float extRadius; float intRadius; float maxHeight; @@ -104,52 +104,52 @@ public: void LevelFlush(); bool LevelMaterial(int id, char* baseName, float u, float v, int up, int right, int down, int left, float hardness); bool LevelInit(int id); - bool LevelGenerate(int *id, float min, float max, float slope, float freq, D3DVECTOR center, float radius); + bool LevelGenerate(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius); void FlushRelief(); bool ReliefFromBMP(const char* filename, float scaleRelief, bool adjustBorder); bool ReliefFromDXF(const char* filename, float scaleRelief); bool ResFromBMP(const char* filename); bool CreateObjects(bool bMultiRes); - bool Terraform(const D3DVECTOR &p1, const D3DVECTOR &p2, float height); + bool Terraform(const Math::Vector &p1, const Math::Vector &p2, float height); - void SetWind(D3DVECTOR speed); - D3DVECTOR RetWind(); + void SetWind(Math::Vector speed); + Math::Vector RetWind(); - float RetFineSlope(const D3DVECTOR &pos); - float RetCoarseSlope(const D3DVECTOR &pos); - bool GetNormal(D3DVECTOR &n, const D3DVECTOR &p); - float RetFloorLevel(const D3DVECTOR &p, bool bBrut=false, bool bWater=false); - float RetFloorHeight(const D3DVECTOR &p, bool bBrut=false, bool bWater=false); - bool MoveOnFloor(D3DVECTOR &p, bool bBrut=false, bool bWater=false); - bool ValidPosition(D3DVECTOR &p, float marging); - TerrainRes RetResource(const D3DVECTOR &p); - void LimitPos(D3DVECTOR &pos); + float RetFineSlope(const Math::Vector &pos); + float RetCoarseSlope(const Math::Vector &pos); + bool GetNormal(Math::Vector &n, const Math::Vector &p); + float RetFloorLevel(const Math::Vector &p, bool bBrut=false, bool bWater=false); + float RetFloorHeight(const Math::Vector &p, bool bBrut=false, bool bWater=false); + bool MoveOnFloor(Math::Vector &p, bool bBrut=false, bool bWater=false); + bool ValidPosition(Math::Vector &p, float marging); + TerrainRes RetResource(const Math::Vector &p); + void LimitPos(Math::Vector &pos); void FlushBuildingLevel(); - bool AddBuildingLevel(D3DVECTOR center, float min, float max, float height, float factor); - bool UpdateBuildingLevel(D3DVECTOR center); - bool DeleteBuildingLevel(D3DVECTOR center); - float RetBuildingFactor(const D3DVECTOR &p); - float RetHardness(const D3DVECTOR &p); + bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor); + bool UpdateBuildingLevel(Math::Vector center); + bool DeleteBuildingLevel(Math::Vector center); + float RetBuildingFactor(const Math::Vector &p); + float RetHardness(const Math::Vector &p); int RetMosaic(); int RetBrick(); float RetSize(); float RetScaleRelief(); - void GroundFlat(D3DVECTOR pos); - float RetFlatZoneRadius(D3DVECTOR center, float max); + void GroundFlat(Math::Vector pos); + float RetFlatZoneRadius(Math::Vector center, float max); void SetFlyingMaxHeight(float height); float RetFlyingMaxHeight(); void FlushFlyingLimit(); - bool AddFlyingLimit(D3DVECTOR center, float extRadius, float intRadius, float maxHeight); - float RetFlyingLimit(D3DVECTOR pos, bool bNoLimit); + bool AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight); + float RetFlyingLimit(Math::Vector pos, bool bNoLimit); protected: - bool ReliefAddDot(D3DVECTOR pos, float scaleRelief); + bool ReliefAddDot(Math::Vector pos, float scaleRelief); void AdjustRelief(); - D3DVECTOR RetVector(int x, int y); + Math::Vector RetVector(int x, int y); D3DVERTEX2 RetVertex(int x, int y, int step); bool CreateMosaic(int ox, int oy, int step, int objRank, const D3DMATERIAL7 &mat, float min, float max); bool CreateSquare(bool bMultiRes, int x, int y); @@ -165,7 +165,7 @@ protected: void LevelOpenTable(); void LevelCloseTable(); - void AdjustBuildingLevel(D3DVECTOR &p); + void AdjustBuildingLevel(Math::Vector &p); protected: CInstanceManager* m_iMan; @@ -200,7 +200,7 @@ protected: BuildingLevel m_buildingTable[MAXBUILDINGLEVEL]; unsigned char* m_resources; - D3DVECTOR m_wind; // wind speed + Math::Vector m_wind; // wind speed float m_flyingMaxHeight; int m_flyingLimitTotal; diff --git a/src/graphics/common/text.cpp b/src/graphics/common/text.cpp index 2bee6f4..f8d3f49 100644 --- a/src/graphics/common/text.cpp +++ b/src/graphics/common/text.cpp @@ -1648,7 +1648,7 @@ void CText::DrawColor(Math::Point pos, float size, float width, int color) D3DVERTEX2 vertex[4]; // 2 triangles Math::Point p1, p2; POINT dim; - D3DVECTOR n; + Math::Vector n; float h, u1, u2, v1, v2, dp; int icon; @@ -1707,12 +1707,12 @@ void CText::DrawColor(Math::Point pos, float size, float width, int color) u2 -= dp; v2 -= dp; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); @@ -1730,12 +1730,12 @@ void CText::DrawChar(int character, Math::Point pos, float size, { D3DVERTEX2 vertex[4]; // 2 triangles Math::Point p1, p2; - D3DVECTOR n; + Math::Vector n; float width, height, u1, u2, v1, v2, dp; short* pt; dp = 0.5f/256.0f; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal if ( font == FONT_BUTTON ) { @@ -1767,10 +1767,10 @@ void CText::DrawChar(int character, Math::Point pos, float size, u2 -= dp; v2 -= dp; - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); @@ -1803,10 +1803,10 @@ void CText::DrawChar(int character, Math::Point pos, float size, u2 -= dp; v2 -= dp; - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); @@ -1868,10 +1868,10 @@ void CText::DrawChar(int character, Math::Point pos, float size, } - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); diff --git a/src/graphics/common/water.cpp b/src/graphics/common/water.cpp index 7bd5614..dd4b5f3 100644 --- a/src/graphics/common/water.cpp +++ b/src/graphics/common/water.cpp @@ -22,6 +22,8 @@ #include #include "common/struct.h" +#include "math/geometry.h" +#include "math/conv.h" #include "graphics/d3d/d3dengine.h" #include "math/old/d3dmath.h" #include "graphics/d3d/d3dutil.h" @@ -170,7 +172,7 @@ bool CWater::EventFrame(const Event &event) void CWater::LavaFrame(float rTime) { - D3DVECTOR eye, lookat, dir, perp, pos; + Math::Vector eye, lookat, dir, perp, pos; float distance, shift, level; int i; @@ -245,7 +247,7 @@ void CWater::VaporFlush() // Creates a new steam. -bool CWater::VaporCreate(ParticuleType type, D3DVECTOR pos, float delay) +bool CWater::VaporCreate(ParticuleType type, Math::Vector pos, float delay) { int i; @@ -283,7 +285,7 @@ bool CWater::VaporCreate(ParticuleType type, D3DVECTOR pos, float delay) void CWater::VaporFrame(int i, float rTime) { - D3DVECTOR pos, speed; + Math::Vector pos, speed; Math::Point dim; int j; @@ -353,7 +355,7 @@ void CWater::VaporFrame(int i, float rTime) // Adjusts the position to normal, to imitate reflections on an expanse of water at rest. -void CWater::AdjustLevel(D3DVECTOR &pos, D3DVECTOR &norm, +void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2) { #if 0 @@ -377,7 +379,7 @@ void CWater::AdjustLevel(D3DVECTOR &pos, D3DVECTOR &norm, t1 = m_time*0.7f + pos.x*5.5f + pos.z*5.6f; t2 = m_time*0.8f + pos.x*5.7f + pos.z*5.8f; - norm = D3DVECTOR(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); + norm = Math::Vector(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); #else float t1, t2; @@ -392,7 +394,7 @@ void CWater::AdjustLevel(D3DVECTOR &pos, D3DVECTOR &norm, t1 = m_time*0.50f + pos.x*2.1f + pos.z*1.1f; t2 = m_time*0.75f + pos.x*2.0f + pos.z*1.0f; - norm = D3DVECTOR(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); + norm = Math::Vector(sinf(t1)*m_glint, 1.0f, sinf(t2)*m_glint); #endif } @@ -404,8 +406,8 @@ void CWater::DrawBack() LPDIRECT3DDEVICE7 device; D3DVERTEX2 vertex[4]; // 2 triangles D3DMATERIAL7 material; - D3DMATRIX matrix; - D3DVECTOR eye, lookat, n, p, p1, p2; + Math::Matrix matrix; + Math::Vector eye, lookat, n, p, p1, p2; Math::Point uv1, uv2; float deep, dist; @@ -434,12 +436,15 @@ void CWater::DrawBack() m_engine->SetFocus(m_engine->RetFocus()); m_engine->UpdateMatProj(); // twice the depth of view - D3DUtil_SetIdentityMatrix(matrix); - device->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + device->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } p.x = eye.x; p.z = eye.z; - dist = Length2d(eye, lookat); + dist = Math::DistanceProjected(eye, lookat); p.x = (lookat.x-eye.x)*deep*1.0f/dist + eye.x; p.z = (lookat.z-eye.z)*deep*1.0f/dist + eye.z; @@ -458,10 +463,10 @@ void CWater::DrawBack() uv1.x = uv1.y = 0.0f; uv2.x = uv2.y = 0.0f; - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, p1.z), n, uv1.x,uv2.y); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, p1.z), n, uv1.x,uv1.y); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, p2.z), n, uv2.x,uv2.y); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, p2.z), n, uv2.x,uv1.y); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p2.y, p1.z), n, uv1.x,uv2.y); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p1.y, p1.z), n, uv1.x,uv1.y); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p2.y, p2.z), n, uv2.x,uv2.y); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p1.y, p2.z), n, uv2.x,uv1.y); device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); m_engine->AddStatisticTriangle(2); @@ -482,8 +487,8 @@ void CWater::DrawSurf() LPDIRECT3DDEVICE7 device; D3DVERTEX2* vertex; // triangles D3DMATERIAL7 material; - D3DMATRIX matrix; - D3DVECTOR eye, lookat, n, pos, p; + Math::Matrix matrix; + Math::Vector eye, lookat, n, pos, p; Math::Point uv1, uv2; bool bUnder; DWORD flags; @@ -508,8 +513,11 @@ void CWater::DrawSurf() //? device->SetRenderState(D3DRENDERSTATE_ZENABLE, false); device->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false); - D3DUtil_SetIdentityMatrix(matrix); - device->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + device->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } ZeroMemory( &material, sizeof(D3DMATERIAL7) ); material.diffuse = m_diffuse; @@ -554,8 +562,11 @@ void CWater::DrawSurf() p = pos; p.x += size*(m_line[i].len-1); radius = sqrtf(powf(size, 2.0f)+powf(size*m_line[i].len, 2.0f)); - if ( Length(p, eye) > deep+radius ) continue; - device->ComputeSphereVisibility(&p, &radius, 1, 0, &flags); + if ( Math::Distance(p, eye) > deep+radius ) continue; + + D3DVECTOR pD3D = VEC_TO_D3DVEC(p); + device->ComputeSphereVisibility(&pD3D, &radius, 1, 0, &flags); + if ( flags & D3DSTATUS_CLIPINTERSECTIONALL ) continue; u = 0; @@ -604,7 +615,7 @@ void CWater::DrawSurf() bool CWater::RetWater(int x, int y) { - D3DVECTOR pos; + Math::Vector pos; float size, offset, level; int dx, dy; @@ -653,7 +664,7 @@ bool CWater::CreateLine(int x, int y, int len) bool CWater::Create(WaterType type1, WaterType type2, const char *filename, D3DCOLORVALUE diffuse, D3DCOLORVALUE ambient, - float level, float glint, D3DVECTOR eddy) + float level, float glint, Math::Vector eddy) { int x, y, len; @@ -812,7 +823,7 @@ bool CWater::RetLava() // Adjusts the eye of the camera, not to be in the water. -void CWater::AdjustEye(D3DVECTOR &eye) +void CWater::AdjustEye(Math::Vector &eye) { if ( m_bLava ) { diff --git a/src/graphics/common/water.h b/src/graphics/common/water.h index c385963..45a545d 100644 --- a/src/graphics/common/water.h +++ b/src/graphics/common/water.h @@ -46,7 +46,7 @@ struct WaterVapor { bool bUsed; ParticuleType type; - D3DVECTOR pos; + Math::Vector pos; float delay; float time; float last; @@ -72,7 +72,7 @@ public: void SetD3DDevice(LPDIRECT3DDEVICE7 device); bool EventProcess(const Event &event); void Flush(); - bool Create(WaterType type1, WaterType type2, const char *filename, D3DCOLORVALUE diffuse, D3DCOLORVALUE ambient, float level, float glint, D3DVECTOR eddy); + bool Create(WaterType type1, WaterType type2, const char *filename, D3DCOLORVALUE diffuse, D3DCOLORVALUE ambient, float level, float glint, Math::Vector eddy); void DrawBack(); void DrawSurf(); @@ -83,17 +83,17 @@ public: void SetLava(bool bLava); bool RetLava(); - void AdjustEye(D3DVECTOR &eye); + void AdjustEye(Math::Vector &eye); protected: bool EventFrame(const Event &event); void LavaFrame(float rTime); - void AdjustLevel(D3DVECTOR &pos, D3DVECTOR &norm, Math::Point &uv1, Math::Point &uv2); + void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2); bool RetWater(int x, int y); bool CreateLine(int x, int y, int len); void VaporFlush(); - bool VaporCreate(ParticuleType type, D3DVECTOR pos, float delay); + bool VaporCreate(ParticuleType type, Math::Vector pos, float delay); void VaporFrame(int i, float rTime); protected: @@ -108,7 +108,7 @@ protected: char m_filename[100]; float m_level; // overall level float m_glint; // amplitude of reflections - D3DVECTOR m_eddy; // amplitude of swirls + Math::Vector m_eddy; // amplitude of swirls D3DCOLORVALUE m_diffuse; // diffuse color D3DCOLORVALUE m_ambient; // ambient color float m_time; diff --git a/src/graphics/d3d/d3dengine.cpp b/src/graphics/d3d/d3dengine.cpp index 8b179ed..731a839 100644 --- a/src/graphics/d3d/d3dengine.cpp +++ b/src/graphics/d3d/d3dengine.cpp @@ -23,6 +23,7 @@ #include "common/struct.h" #include "math/const.h" #include "math/geometry.h" +#include "math/conv.h" #include "app/d3dapp.h" #include "graphics/d3d/d3dtextr.h" #include "graphics/d3d/d3dutil.h" @@ -163,8 +164,8 @@ CD3DEngine::CD3DEngine(CInstanceManager *iMan, CD3DApplication *app) m_bMouseHide = false; m_imageSurface = 0; m_imageCopy = 0; - m_eyePt = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_lookatPt = D3DVECTOR(0.0f, 0.0f, 1.0f); + m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); + m_lookatPt = Math::Vector(0.0f, 0.0f, 1.0f); m_bDrawWorld = true; m_bDrawFront = false; m_limitLOD[0] = 100.0f; @@ -668,7 +669,7 @@ int CD3DEngine::RetRestCreate() int CD3DEngine::CreateObject() { - D3DMATRIX mat; + Math::Matrix mat; int i; for ( i=0 ; i= m_objectParamTotal ) @@ -1031,8 +1032,8 @@ bool CD3DEngine::AddTriangle(int objRank, D3DVERTEX2* vertex, int nb, m_objectParam[objRank].bboxMax.z = Math::Max(vertex[i].z, m_objectParam[objRank].bboxMax.z); } - m_objectParam[objRank].radius = Math::Max(Length(m_objectParam[objRank].bboxMin), - Length(m_objectParam[objRank].bboxMax)); + m_objectParam[objRank].radius = Math::Max(m_objectParam[objRank].bboxMin.Length(), + m_objectParam[objRank].bboxMax.Length()); } m_objectParam[objRank].totalTriangle += nb/3; @@ -1078,8 +1079,8 @@ bool CD3DEngine::AddSurface(int objRank, D3DVERTEX2* vertex, int nb, m_objectParam[objRank].bboxMax.z = Math::Max(vertex[i].z, m_objectParam[objRank].bboxMax.z); } - m_objectParam[objRank].radius = Math::Max(Length(m_objectParam[objRank].bboxMin), - Length(m_objectParam[objRank].bboxMax)); + m_objectParam[objRank].radius = Math::Max(m_objectParam[objRank].bboxMin.Length(), + m_objectParam[objRank].bboxMax.Length()); } m_objectParam[objRank].totalTriangle += nb-2; @@ -1124,8 +1125,8 @@ bool CD3DEngine::AddQuick(int objRank, D3DObjLevel6* buffer, m_objectParam[objRank].bboxMax.z = Math::Max(buffer->vertex[i].z, m_objectParam[objRank].bboxMax.z); } - m_objectParam[objRank].radius = Math::Max(Length(m_objectParam[objRank].bboxMin), - Length(m_objectParam[objRank].bboxMax)); + m_objectParam[objRank].radius = Math::Max(m_objectParam[objRank].bboxMin.Length(), + m_objectParam[objRank].bboxMax.Length()); } m_objectParam[objRank].totalTriangle += buffer->totalUsed-2; @@ -1388,7 +1389,7 @@ int CD3DEngine::GetTriangles(int objRank, float min, float max, // Give the box of an object. -bool CD3DEngine::GetBBox(int objRank, D3DVECTOR &min, D3DVECTOR &max) +bool CD3DEngine::GetBBox(int objRank, Math::Vector &min, Math::Vector &max) { min = m_objectParam[objRank].bboxMin; max = m_objectParam[objRank].bboxMax; @@ -1530,7 +1531,7 @@ bool CD3DEngine::TrackTextureMapping(int objRank, { D3DObjLevel6* p6; D3DVERTEX2* pv; - D3DVECTOR current; + Math::Vector current; float ps, pe, pps, ppe, offset; int l6, nb, i, j, s, e; int is[6], ie[6]; @@ -1580,8 +1581,8 @@ bool CD3DEngine::TrackTextureMapping(int objRank, } if ( s == 3 && e == 3 ) { - pe = ps+Length(pv[is[0]].x-pv[ie[0]].x, - pv[is[0]].y-pv[ie[0]].y)/factor; // end position on the periphery + pe = ps+Math::Point(pv[is[0]].x-pv[ie[0]].x, + pv[is[0]].y-pv[ie[0]].y).Length() / factor; // end position on the periphery pps = ps+pos; ppe = pe+pos; @@ -1673,8 +1674,8 @@ void CD3DEngine::UpdateGeometry() m_objectParam[objRank].bboxMax.z = Math::Max(p6->vertex[i].z, m_objectParam[objRank].bboxMax.z); } - m_objectParam[objRank].radius = Math::Max(Length(m_objectParam[objRank].bboxMin), - Length(m_objectParam[objRank].bboxMax)); + m_objectParam[objRank].radius = Math::Max(m_objectParam[objRank].bboxMin.Length(), + m_objectParam[objRank].bboxMax.Length()); } } } @@ -1690,13 +1691,16 @@ void CD3DEngine::UpdateGeometry() bool CD3DEngine::IsVisible(int objRank) { - D3DVECTOR center; + Math::Vector center; DWORD flags; float radius; radius = m_objectParam[objRank].radius; - center = D3DVECTOR(0.0f, 0.0f, 0.0f); - m_pD3DDevice->ComputeSphereVisibility(¢er, &radius, 1, 0, &flags); + center = Math::Vector(0.0f, 0.0f, 0.0f); + { + D3DVECTOR centerD3D = VEC_TO_D3DVEC(center); + m_pD3DDevice->ComputeSphereVisibility(¢erD3D, &radius, 1, 0, &flags); + } if ( flags & D3DSTATUS_CLIPINTERSECTIONALL ) { @@ -1793,7 +1797,7 @@ int CD3DEngine::DetectObject(Math::Point mouse) bool CD3DEngine::DetectTriangle(Math::Point mouse, D3DVERTEX2 *triangle, int objRank, float &dist) { - D3DVECTOR p2D[3], p3D; + Math::Vector p2D[3], p3D; Math::Point a, b, c; int i; @@ -1834,7 +1838,7 @@ bool CD3DEngine::DetectTriangle(Math::Point mouse, D3DVERTEX2 *triangle, bool CD3DEngine::DetectBBox(int objRank, Math::Point mouse) { - D3DVECTOR p, pp; + Math::Vector p, pp; Math::Point min, max; int i; @@ -1869,15 +1873,15 @@ bool CD3DEngine::DetectBBox(int objRank, Math::Point mouse) // Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window. // The coordinated p2D.z gives the distance. -bool CD3DEngine::TransformPoint(D3DVECTOR &p2D, int objRank, D3DVECTOR p3D) +bool CD3DEngine::TransformPoint(Math::Vector &p2D, int objRank, Math::Vector p3D) { - p3D = Transform(m_objectParam[objRank].transform, p3D); - p3D = Transform(m_matView, p3D); + p3D = Math::Transform(m_objectParam[objRank].transform, p3D); + p3D = Math::Transform(m_matView, p3D); if ( p3D.z < 2.0f ) return false; // behind? - p2D.x = (p3D.x/p3D.z)*m_matProj._11; - p2D.y = (p3D.y/p3D.z)*m_matProj._22; + p2D.x = (p3D.x/p3D.z)*m_matProj.Get(1,1); + p2D.y = (p3D.y/p3D.z)*m_matProj.Get(2,2); p2D.z = p3D.z; p2D.x = (p2D.x+1.0f)/2.0f; // [-1..1] -> [0..1] @@ -1892,7 +1896,7 @@ bool CD3DEngine::TransformPoint(D3DVECTOR &p2D, int objRank, D3DVECTOR p3D) void CD3DEngine::ComputeDistance() { - D3DVECTOR v; + Math::Vector v; int i; float distance; @@ -1902,10 +1906,10 @@ void CD3DEngine::ComputeDistance() { if ( m_objectParam[i].bUsed == false ) continue; - v.x = m_eyePt.x - m_objectParam[i].transform._41; - v.y = m_eyePt.y - m_objectParam[i].transform._42; - v.z = m_eyePt.z - m_objectParam[i].transform._43; - m_objectParam[i].distance = Length(v); + v.x = m_eyePt.x - m_objectParam[i].transform.Get(1,4); + v.y = m_eyePt.y - m_objectParam[i].transform.Get(2,4); + v.z = m_eyePt.z - m_objectParam[i].transform.Get(3,4); + m_objectParam[i].distance = v.Length(); } } else @@ -1929,10 +1933,10 @@ void CD3DEngine::ComputeDistance() if ( m_objectParam[i].type == TYPETERRAIN ) { - v.x = m_eyePt.x - m_objectParam[i].transform._41; - v.y = m_eyePt.y - m_objectParam[i].transform._42; - v.z = m_eyePt.z - m_objectParam[i].transform._43; - m_objectParam[i].distance = Length(v); + v.x = m_eyePt.x - m_objectParam[i].transform.Get(1,4); + v.y = m_eyePt.y - m_objectParam[i].transform.Get(2,4); + v.z = m_eyePt.z - m_objectParam[i].transform.Get(3,4); + m_objectParam[i].distance = v.Length(); } else { @@ -2002,17 +2006,17 @@ bool CD3DEngine::ChangeDevice(char *device, char *mode, bool bFull) -D3DMATRIX* CD3DEngine::RetMatView() +Math::Matrix* CD3DEngine::RetMatView() { return &m_matView; } -D3DMATRIX* CD3DEngine::RetMatLeftView() +Math::Matrix* CD3DEngine::RetMatLeftView() { return &m_matLeftView; } -D3DMATRIX* CD3DEngine::RetMatRightView() +Math::Matrix* CD3DEngine::RetMatRightView() { return &m_matRightView; } @@ -2020,9 +2024,9 @@ D3DMATRIX* CD3DEngine::RetMatRightView() // Specifies the location and direction of view. -void CD3DEngine::SetViewParams(const D3DVECTOR &vEyePt, - const D3DVECTOR &vLookatPt, - const D3DVECTOR &vUpVec, +void CD3DEngine::SetViewParams(const Math::Vector &vEyePt, + const Math::Vector &vLookatPt, + const Math::Vector &vUpVec, FLOAT fEyeDistance) { #if 0 @@ -2030,24 +2034,24 @@ void CD3DEngine::SetViewParams(const D3DVECTOR &vEyePt, // Adjust camera position for left or right eye along the axis // perpendicular to the view direction vector and the up vector. - D3DVECTOR vView = (vLookatPt) - (vEyePt); + Math::Vector vView = (vLookatPt) - (vEyePt); vView = CrossProduct( vView, (vUpVec) ); vView = Normalize( vView ) * fEyeDistance; - D3DVECTOR vLeftEyePt = (vEyePt) + vView; - D3DVECTOR vRightEyePt = (vEyePt) - vView; + Math::Vector vLeftEyePt = (vEyePt) + vView; + Math::Vector vRightEyePt = (vEyePt) - vView; // Set the view matrices - D3DUtil_SetViewMatrix( m_matLeftView, (D3DVECTOR)vLeftEyePt, (D3DVECTOR)vLookatPt, (D3DVECTOR)vUpVec ); - D3DUtil_SetViewMatrix( m_matRightView, (D3DVECTOR)vRightEyePt, (D3DVECTOR)vLookatPt, (D3DVECTOR)vUpVec ); - D3DUtil_SetViewMatrix( m_matView, (D3DVECTOR)vEyePt, (D3DVECTOR)vLookatPt, (D3DVECTOR)vUpVec ); + Math::LoadViewMatrix( m_matLeftView, (Math::Vector)vLeftEyePt, (Math::Vector)vLookatPt, (Math::Vector)vUpVec ); + Math::LoadViewMatrix( m_matRightView, (Math::Vector)vRightEyePt, (Math::Vector)vLookatPt, (Math::Vector)vUpVec ); + Math::LoadViewMatrix( m_matView, (Math::Vector)vEyePt, (Math::Vector)vLookatPt, (Math::Vector)vUpVec ); #else m_eyePt = vEyePt; m_lookatPt = vLookatPt; m_eyeDirH = Math::RotateAngle(vEyePt.x-vLookatPt.x, vEyePt.z-vLookatPt.z); - m_eyeDirV = Math::RotateAngle(Length2d(vEyePt, vLookatPt), vEyePt.y-vLookatPt.y); + m_eyeDirV = Math::RotateAngle(Math::DistanceProjected(vEyePt, vLookatPt), vEyePt.y-vLookatPt.y); - D3DUtil_SetViewMatrix(m_matView, (D3DVECTOR&)vEyePt, (D3DVECTOR&)vLookatPt, (D3DVECTOR&)vUpVec); + Math::LoadViewMatrix(m_matView, vEyePt, vLookatPt, vUpVec); if ( m_sound == 0 ) { @@ -2060,7 +2064,7 @@ void CD3DEngine::SetViewParams(const D3DVECTOR &vEyePt, // Specifies the transformation matrix of an object. -bool CD3DEngine::SetObjectTransform(int objRank, const D3DMATRIX &transform) +bool CD3DEngine::SetObjectTransform(int objRank, const Math::Matrix &transform) { if ( objRank < 0 || objRank >= D3DMAXOBJECT ) return false; @@ -2070,7 +2074,7 @@ bool CD3DEngine::SetObjectTransform(int objRank, const D3DMATRIX &transform) // Gives the transformation matrix of an object. -bool CD3DEngine::GetObjectTransform(int objRank, D3DMATRIX &transform) +bool CD3DEngine::GetObjectTransform(int objRank, Math::Matrix &transform) { if ( objRank < 0 || objRank >= D3DMAXOBJECT ) return false; @@ -2150,7 +2154,7 @@ void CD3DEngine::ShadowDelete(int objRank) m_shadow[i].bUsed = false; m_shadow[i].objRank = -1; - m_shadow[i].pos = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_shadow[i].pos = Math::Vector(0.0f, 0.0f, 0.0f); m_shadow[i].type = D3DSHADOWNORM; m_objectParam[objRank].shadowRank = -1; @@ -2191,7 +2195,7 @@ bool CD3DEngine::SetObjectShadowType(int objRank, D3DShadowType type) // Specifies the position of the shadow of the object. -bool CD3DEngine::SetObjectShadowPos(int objRank, const D3DVECTOR &pos) +bool CD3DEngine::SetObjectShadowPos(int objRank, const Math::Vector &pos) { if ( objRank < 0 || objRank >= D3DMAXOBJECT ) return false; @@ -2204,7 +2208,7 @@ bool CD3DEngine::SetObjectShadowPos(int objRank, const D3DVECTOR &pos) // Specifies the normal shadow to the field of the object. -bool CD3DEngine::SetObjectShadowNormal(int objRank, const D3DVECTOR &n) +bool CD3DEngine::SetObjectShadowNormal(int objRank, const Math::Vector &n) { if ( objRank < 0 || objRank >= D3DMAXOBJECT ) return false; @@ -2340,12 +2344,12 @@ int CD3DEngine::GroundSpotCreate() void CD3DEngine::GroundSpotDelete(int rank) { m_groundSpot[rank].bUsed = false; - m_groundSpot[rank].pos = D3DVECTOR(0.0f, 0.0f, 0.0f); + m_groundSpot[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f); } // Specifies the position of surface marking of the object. -bool CD3DEngine::SetObjectGroundSpotPos(int rank, const D3DVECTOR &pos) +bool CD3DEngine::SetObjectGroundSpotPos(int rank, const Math::Vector &pos) { m_groundSpot[rank].pos = pos; return true; @@ -2387,7 +2391,7 @@ bool CD3DEngine::SetObjectGroundSpotSmooth(int rank, float smooth) // Creates ground marks. -int CD3DEngine::GroundMarkCreate(D3DVECTOR pos, float radius, +int CD3DEngine::GroundMarkCreate(Math::Vector pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table) { @@ -2947,12 +2951,12 @@ void CD3DEngine::ApplyChange() // Returns the point of view of the user. -D3DVECTOR CD3DEngine::RetEyePt() +Math::Vector CD3DEngine::RetEyePt() { return m_eyePt; } -D3DVECTOR CD3DEngine::RetLookatPt() +Math::Vector CD3DEngine::RetLookatPt() { return m_lookatPt; } @@ -3638,7 +3642,7 @@ void CD3DEngine::RenderGroundSpot() DDSURFACEDESC2 ddsd; WORD* pbSurf; D3DCOLORVALUE color; - D3DVECTOR pos; + Math::Vector pos; Math::Point min, max; int s, i, j, dot, ix, iy, y; float tu, tv, cx, cy, px, py, ppx, ppy; @@ -3780,7 +3784,7 @@ void CD3DEngine::RenderGroundSpot() } else { - intensity = Length(ppx-cx, ppy-cy)/dot; + intensity = Math::Point(ppx-cx, ppy-cy).Length()/dot; //? intensity = powf(intensity, m_groundSpot[i].smooth); } @@ -3859,7 +3863,7 @@ void CD3DEngine::RenderGroundSpot() ppx -= min.x; // on the texture ppy -= min.y; - intensity = 1.0f-Length((float)ix, (float)iy)/dot; + intensity = 1.0f-Math::Point((float)ix, (float)iy).Length()/dot; if ( intensity <= 0.0f ) continue; intensity *= m_groundMark.intensity; @@ -3912,9 +3916,9 @@ void CD3DEngine::RenderGroundSpot() void CD3DEngine::DrawShadow() { D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR corner[4], n, pos; + Math::Vector corner[4], n, pos; D3DMATERIAL7 material; - D3DMATRIX matrix; + Math::Matrix matrix; Math::Point ts, ti, rot; float startDeepView, endDeepView; float intensity, lastIntensity, hFactor, radius, max, height; @@ -3924,8 +3928,11 @@ void CD3DEngine::DrawShadow() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false); - D3DUtil_SetIdentityMatrix(matrix); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matrix); + matrix.LoadIdentity(); + { + D3DMATRIX mat = MAT_TO_D3DMAT(matrix); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } ZeroMemory( &material, sizeof(D3DMATERIAL7) ); material.diffuse.r = 1.0f; @@ -3948,7 +3955,7 @@ void CD3DEngine::DrawShadow() ts.y += dp; ti.y -= dp; - n = D3DVECTOR(0.0f, 1.0f, 0.0f); + n = Math::Vector(0.0f, 1.0f, 0.0f); startDeepView = m_deepView[m_rankView]*m_fogStart[m_rankView]; endDeepView = m_deepView[m_rankView]; @@ -3973,7 +3980,7 @@ void CD3DEngine::DrawShadow() if ( h > max ) h = max; if ( h > 4.0f ) h = 4.0f; - D = Length(m_eyePt, pos); + D = Math::Distance(m_eyePt, pos); if ( D >= endDeepView ) continue; d = D*h/height; @@ -3989,7 +3996,7 @@ void CD3DEngine::DrawShadow() if ( h > max ) h = max; if ( h > 4.0f ) h = 4.0f; - D = Length(m_eyePt, pos); + D = Math::Distance(m_eyePt, pos); if ( D >= endDeepView ) continue; d = D*h/height; @@ -4065,10 +4072,10 @@ void CD3DEngine::DrawShadow() } } - corner[0] = Cross(corner[0], m_shadow[i].normal); - corner[1] = Cross(corner[1], m_shadow[i].normal); - corner[2] = Cross(corner[2], m_shadow[i].normal); - corner[3] = Cross(corner[3], m_shadow[i].normal); + corner[0] = Math::CrossProduct(corner[0], m_shadow[i].normal); + corner[1] = Math::CrossProduct(corner[1], m_shadow[i].normal); + corner[2] = Math::CrossProduct(corner[2], m_shadow[i].normal); + corner[3] = Math::CrossProduct(corner[3], m_shadow[i].normal); corner[0] += pos; corner[1] += pos; @@ -4172,7 +4179,10 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, true); //? m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, F2DW(16)); //? m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProj); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProj); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, true); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, true); @@ -4181,7 +4191,10 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGSTART, F2DW(m_deepView[m_rankView]*m_fogStart[m_rankView])); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGEND, F2DW(m_deepView[m_rankView])); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matView); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matView); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } if ( m_bWaterMode ) m_water->DrawBack(); // draws water @@ -4202,8 +4215,12 @@ HRESULT CD3DEngine::Render() objRank = p3->objRank; if ( m_objectParam[objRank].type != TYPETERRAIN ) continue; if ( !m_objectParam[objRank].bDrawWorld ) continue; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, - &m_objectParam[objRank].transform); + + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_objectParam[objRank].transform); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } + if ( !IsVisible(objRank) ) continue; m_light->LightUpdate(m_objectParam[objRank].type); for ( l3=0 ; l3totalUsed ; l3++ ) @@ -4265,8 +4282,12 @@ HRESULT CD3DEngine::Render() objRank = p3->objRank; if ( m_bShadow && m_objectParam[objRank].type == TYPETERRAIN ) continue; if ( !m_objectParam[objRank].bDrawWorld ) continue; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, - &m_objectParam[objRank].transform); + + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_objectParam[objRank].transform); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } + if ( !IsVisible(objRank) ) continue; m_light->LightUpdate(m_objectParam[objRank].type); for ( l3=0 ; l3totalUsed ; l3++ ) @@ -4342,8 +4363,12 @@ HRESULT CD3DEngine::Render() objRank = p3->objRank; if ( m_bShadow && m_objectParam[objRank].type == TYPETERRAIN ) continue; if ( !m_objectParam[objRank].bDrawWorld ) continue; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, - &m_objectParam[objRank].transform); + + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_objectParam[objRank].transform); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } + if ( !IsVisible(objRank) ) continue; m_light->LightUpdate(m_objectParam[objRank].type); for ( l3=0 ; l3totalUsed ; l3++ ) @@ -4404,9 +4429,18 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, false); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } pInterface = (CInterface*)m_iMan->SearchInstance(CLASS_INTERFACE); if ( pInterface != 0 ) @@ -4421,7 +4455,10 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, true); //? m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, F2DW(16)); //? m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProj); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProj); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } m_pD3DDevice->SetRenderState(D3DRENDERSTATE_AMBIENT, m_ambiantColor[m_rankView]); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, true); @@ -4431,7 +4468,10 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGSTART, F2DW(m_deepView[m_rankView]*m_fogStart[m_rankView])); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGEND, F2DW(m_deepView[m_rankView])); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matView); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matView); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } p1 = m_objectPointer; for ( l1=0 ; l1totalUsed ; l1++ ) @@ -4446,8 +4486,12 @@ HRESULT CD3DEngine::Render() if ( p3 == 0 ) continue; objRank = p3->objRank; if ( !m_objectParam[objRank].bDrawFront ) continue; - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, - &m_objectParam[objRank].transform); + + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_objectParam[objRank].transform); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } + if ( !IsVisible(objRank) ) continue; m_light->LightUpdate(m_objectParam[objRank].type); for ( l3=0 ; l3totalUsed ; l3++ ) @@ -4497,9 +4541,18 @@ HRESULT CD3DEngine::Render() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, false); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } } if ( m_bOverFront ) DrawOverColor(); // draws the foreground color @@ -4568,9 +4621,18 @@ void CD3DEngine::DrawBackgroundGradient(D3DCOLOR up, D3DCOLOR down) SetTexture("xxx.tga"); // no texture SetState(D3DSTATENORMAL); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } vertex[0] = D3DLVERTEX(D3DVECTOR(p1.x, p1.y, 0.0f), color[1],color[2], 0.0f,0.0f); vertex[1] = D3DLVERTEX(D3DVECTOR(p1.x, p2.y, 0.0f), color[0],color[2], 0.0f,0.0f); @@ -4586,10 +4648,10 @@ void CD3DEngine::DrawBackgroundGradient(D3DCOLOR up, D3DCOLOR down) void CD3DEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, char *name) { D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR n; + Math::Vector n; float u1, u2, v1, v2, h, a; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal if ( m_bBackgroundFull ) { @@ -4632,14 +4694,23 @@ void CD3DEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, char SetTexture(name); SetState(D3DSTATEWRAP); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); AddStatisticTriangle(2); @@ -4704,9 +4775,18 @@ void CD3DEngine::DrawPlanet() m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, false ); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, false); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } m_planet->Draw(); // draws the planets } @@ -4716,13 +4796,13 @@ void CD3DEngine::DrawPlanet() void CD3DEngine::DrawFrontsize() { D3DVERTEX2 vertex[4]; // 2 triangles - D3DVECTOR n; + Math::Vector n; Math::Point p1, p2; float u1, u2, v1, v2; if ( m_frontsizeName[0] == 0 ) return; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal p1.x = 0.0f; p1.y = 0.0f; @@ -4741,10 +4821,10 @@ void CD3DEngine::DrawFrontsize() SetInfoText(3, s); #endif - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); //? m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, false); m_pD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false); @@ -4755,9 +4835,18 @@ void CD3DEngine::DrawFrontsize() SetTexture(m_frontsizeName); SetState(D3DSTATECLAMP|D3DSTATETTb); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); AddStatisticTriangle(2); @@ -4793,9 +4882,18 @@ void CD3DEngine::DrawOverColor() SetTexture("xxx.tga"); // no texture SetState(m_overMode); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &m_matViewInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProjInterface); - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matWorldInterface); + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matViewInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProjInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); + } + { + D3DMATRIX mat = MAT_TO_D3DMAT(m_matWorldInterface); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat); + } vertex[0] = D3DLVERTEX(D3DVECTOR(p1.x, p1.y, 0.0f), color[1],color[2], 0.0f,0.0f); vertex[1] = D3DLVERTEX(D3DVECTOR(p1.x, p2.y, 0.0f), color[0],color[2], 0.0f,0.0f); @@ -4825,7 +4923,7 @@ void CD3DEngine::SetHiliteRank(int *rankList) bool CD3DEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) { - D3DVECTOR p, pp; + Math::Vector p, pp; int i; min.x = 1000000.0f; @@ -4924,11 +5022,11 @@ int CD3DEngine::RetStatisticTriangle() bool CD3DEngine::GetSpriteCoord(int &x, int &y) { D3DVIEWPORT7 vp; - D3DVECTOR v, vv; + Math::Vector v, vv; return false; //? - vv = D3DVECTOR(0.0f, 0.0f, 0.0f); + vv = Math::Vector(0.0f, 0.0f, 0.0f); if ( !TransformPoint(v, 20*20+1, vv) ) return false; m_pD3DDevice->GetViewport(&vp); @@ -5328,8 +5426,8 @@ void CD3DEngine::SetFocus(float focus) } fAspect = ((float)m_dim.y) / m_dim.x; -//? D3DUtil_SetProjectionMatrix(m_matProj, m_focus, fAspect, 0.5f, m_deepView[m_rankView]); - D3DUtil_SetProjectionMatrix(m_matProj, m_focus, fAspect, 0.5f, m_deepView[0]); +//? Math::LoadProjectionMatrix(m_matProj, m_focus, fAspect, 0.5f, m_deepView[m_rankView]); + Math::LoadProjectionMatrix(m_matProj, m_focus, fAspect, 0.5f, m_deepView[0]); } float CD3DEngine::RetFocus() @@ -5341,7 +5439,8 @@ float CD3DEngine::RetFocus() void CD3DEngine::UpdateMatProj() { - m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProj); + D3DMATRIX mat = MAT_TO_D3DMAT(m_matProj); + m_pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mat); } @@ -5406,9 +5505,9 @@ bool CD3DEngine::RetSetupMode() // Indicates whether a point is visible. -bool CD3DEngine::IsVisiblePoint(const D3DVECTOR &pos) +bool CD3DEngine::IsVisiblePoint(const Math::Vector &pos) { - return ( Length(m_eyePt, pos) <= m_deepView[0] ); + return ( Math::Distance(m_eyePt, pos) <= m_deepView[0] ); } @@ -5432,19 +5531,19 @@ HRESULT CD3DEngine::InitDeviceObjects() SetFocus(m_focus); // Definitions of the matrices for the interface. - D3DUtil_SetIdentityMatrix(m_matWorldInterface); - - D3DUtil_SetIdentityMatrix(m_matViewInterface); - m_matViewInterface._41 = -0.5f; - m_matViewInterface._42 = -0.5f; - m_matViewInterface._43 = 1.0f; - - D3DUtil_SetIdentityMatrix(m_matProjInterface); - m_matProjInterface._11 = 2.0f; - m_matProjInterface._22 = 2.0f; - m_matProjInterface._34 = 1.0f; - m_matProjInterface._43 = -1.0f; - m_matProjInterface._44 = 0.0f; + m_matWorldInterface.LoadIdentity(); + + m_matViewInterface.LoadIdentity(); + m_matViewInterface.Set(1, 4, -0.5f); + m_matViewInterface.Set(2, 4, -0.5f); + m_matViewInterface.Set(3, 4, 1.0f); + + m_matProjInterface.LoadIdentity(); + m_matProjInterface.Set(1, 1, 2.0f); + m_matProjInterface.Set(2, 2, 2.0f); + m_matProjInterface.Set(4, 3, 1.0f); + m_matProjInterface.Set(3, 4, -1.0f); + m_matProjInterface.Set(4, 4, 0.0f); return S_OK; } @@ -5692,7 +5791,7 @@ void CD3DEngine::DrawSprite(Math::Point pos, Math::Point dim, int icon) { D3DVERTEX2 vertex[4]; // 2 triangles Math::Point p1, p2; - D3DVECTOR n; + Math::Vector n; float u1, u2, v1, v2, dp; if ( icon == -1 ) return; @@ -5713,12 +5812,12 @@ void CD3DEngine::DrawSprite(Math::Point pos, Math::Point dim, int icon) u2 -= dp; v2 -= dp; - n = D3DVECTOR(0.0f, 0.0f, -1.0f); // normal + n = Math::Vector(0.0f, 0.0f, -1.0f); // normal - vertex[0] = D3DVERTEX2(D3DVECTOR(p1.x, p1.y, 0.0f), n, u1,v2); - vertex[1] = D3DVERTEX2(D3DVECTOR(p1.x, p2.y, 0.0f), n, u1,v1); - vertex[2] = D3DVERTEX2(D3DVECTOR(p2.x, p1.y, 0.0f), n, u2,v2); - vertex[3] = D3DVERTEX2(D3DVECTOR(p2.x, p2.y, 0.0f), n, u2,v1); + vertex[0] = D3DVERTEX2(Math::Vector(p1.x, p1.y, 0.0f), n, u1,v2); + vertex[1] = D3DVERTEX2(Math::Vector(p1.x, p2.y, 0.0f), n, u1,v1); + vertex[2] = D3DVERTEX2(Math::Vector(p2.x, p1.y, 0.0f), n, u2,v2); + vertex[3] = D3DVERTEX2(Math::Vector(p2.x, p2.y, 0.0f), n, u2,v1); m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX2, vertex, 4, NULL); AddStatisticTriangle(2); diff --git a/src/graphics/d3d/d3dengine.h b/src/graphics/d3d/d3dengine.h index 8450f91..d028d2c 100644 --- a/src/graphics/d3d/d3dengine.h +++ b/src/graphics/d3d/d3dengine.h @@ -20,6 +20,8 @@ #include "math/point.h" +#include "math/vector.h" +#include "math/matrix.h" #include "common/struct.h" @@ -188,10 +190,10 @@ struct D3DObject char bDrawFront; // true -> shape before the interface int totalTriangle; // number of triangles used D3DTypeObj type; // type of the object (TYPE*) - D3DMATRIX transform; // transformation matrix + Math::Matrix transform; // transformation matrix float distance; // distance point of view - original - D3DVECTOR bboxMin; // bounding box of the object - D3DVECTOR bboxMax; // (the origin 0, 0, 0 is always included) + Math::Vector bboxMin; // bounding box of the object + Math::Vector bboxMax; // (the origin 0, 0, 0 is always included) float radius; // radius of the sphere at the origin int shadowRank; // rank of the associated shadow float transparency; // transparency of the object (0 .. 1) @@ -203,8 +205,8 @@ struct D3DShadow char bHide; // true -> invisible shadow (object carried by ex.) int objRank; // rank of the object D3DShadowType type; // type of shadow - D3DVECTOR pos; // position for the shadow - D3DVECTOR normal; // normal terrain + Math::Vector pos; // position for the shadow + Math::Vector normal; // normal terrain float angle; // angle of the shadow float radius; // radius of the shadow float intensity; // intensity of the shadow @@ -217,9 +219,9 @@ struct D3DGroundSpot D3DCOLORVALUE color; // color of the shadow float min, max; // altitudes min / max float smooth; // transition area - D3DVECTOR pos; // position for the shadow + Math::Vector pos; // position for the shadow float radius; // radius of the shadow - D3DVECTOR drawPos; // drawn to position the shade + Math::Vector drawPos; // drawn to position the shade float drawRadius; // radius of the shadow drawn }; @@ -230,10 +232,10 @@ struct D3DGroundMark int phase; // 1 = increase, 2 = fixed, 3 = decrease float delay[3]; // time for 3 phases float fix; // fixed time - D3DVECTOR pos; // position for marks + Math::Vector pos; // position for marks float radius; // radius of marks float intensity; // color intensity - D3DVECTOR drawPos; // drawn in position marks + Math::Vector drawPos; // drawn in position marks float drawRadius; // radius marks drawn float drawIntensity; // current drawn int dx, dy; // dimensions table @@ -291,9 +293,9 @@ public: bool RetFullScreen(); bool ChangeDevice(char *device, char *mode, bool bFull); - D3DMATRIX* RetMatView(); - D3DMATRIX* RetMatLeftView(); - D3DMATRIX* RetMatRightView(); + Math::Matrix* RetMatView(); + Math::Matrix* RetMatLeftView(); + Math::Matrix* RetMatRightView(); void TimeInit(); void TimeEnterGel(); @@ -314,11 +316,11 @@ public: bool ChangeSecondTexture(int objRank, char* texName2); int RetTotalTriangles(int objRank); int GetTriangles(int objRank, float min, float max, D3DTriangle* buffer, int size, float percent); - bool GetBBox(int objRank, D3DVECTOR &min, D3DVECTOR &max); + bool GetBBox(int objRank, Math::Vector &min, Math::Vector &max); bool ChangeTextureMapping(int objRank, const D3DMATERIAL7 &mat, int state, char* texName1, char* texName2, float min, float max, D3DMaping mode, float au, float bu, float av, float bv); bool TrackTextureMapping(int objRank, const D3DMATERIAL7 &mat, int state, char* texName1, char* texName2, float min, float max, D3DMaping mode, float pos, float factor, float tl, float ts, float tt); - bool SetObjectTransform(int objRank, const D3DMATRIX &transform); - bool GetObjectTransform(int objRank, D3DMATRIX &transform); + bool SetObjectTransform(int objRank, const Math::Matrix &transform); + bool GetObjectTransform(int objRank, Math::Matrix &transform); bool SetObjectType(int objRank, D3DTypeObj type); D3DTypeObj RetObjectType(int objRank); bool SetObjectTransparency(int objRank, float value); @@ -327,8 +329,8 @@ public: void ShadowDelete(int objRank); bool SetObjectShadowHide(int objRank, bool bHide); bool SetObjectShadowType(int objRank, D3DShadowType type); - bool SetObjectShadowPos(int objRank, const D3DVECTOR &pos); - bool SetObjectShadowNormal(int objRank, const D3DVECTOR &n); + bool SetObjectShadowPos(int objRank, const Math::Vector &pos); + bool SetObjectShadowNormal(int objRank, const Math::Vector &n); bool SetObjectShadowAngle(int objRank, float angle); bool SetObjectShadowRadius(int objRank, float radius); bool SetObjectShadowIntensity(int objRank, float intensity); @@ -338,18 +340,18 @@ public: void GroundSpotFlush(); int GroundSpotCreate(); void GroundSpotDelete(int rank); - bool SetObjectGroundSpotPos(int rank, const D3DVECTOR &pos); + bool SetObjectGroundSpotPos(int rank, const Math::Vector &pos); bool SetObjectGroundSpotRadius(int rank, float radius); bool SetObjectGroundSpotColor(int rank, D3DCOLORVALUE color); bool SetObjectGroundSpotMinMax(int rank, float min, float max); bool SetObjectGroundSpotSmooth(int rank, float smooth); - int GroundMarkCreate(D3DVECTOR pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table); + int GroundMarkCreate(Math::Vector pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table); bool GroundMarkDelete(int rank); void Update(); - void SetViewParams(const D3DVECTOR &vEyePt, const D3DVECTOR &vLookatPt, const D3DVECTOR &vUpVec, FLOAT fEyeDistance); + void SetViewParams(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, const Math::Vector &vUpVec, FLOAT fEyeDistance); bool FreeTexture(char* name); bool LoadTexture(char* name, int stage=0); @@ -454,8 +456,8 @@ public: void SetFocus(float focus); float RetFocus(); - D3DVECTOR RetEyePt(); - D3DVECTOR RetLookatPt(); + Math::Vector RetEyePt(); + Math::Vector RetLookatPt(); float RetEyeDirH(); float RetEyeDirV(); POINT RetDim(); @@ -475,7 +477,7 @@ public: bool RetDebugMode(); bool RetSetupMode(); - bool IsVisiblePoint(const D3DVECTOR &pos); + bool IsVisiblePoint(const Math::Vector &pos); int DetectObject(Math::Point mouse); void SetState(int state, D3DCOLOR color=0xffffffff); @@ -525,7 +527,7 @@ protected: bool IsVisible(int objRank); bool DetectBBox(int objRank, Math::Point mouse); bool DetectTriangle(Math::Point mouse, D3DVERTEX2 *triangle, int objRank, float &dist); - bool TransformPoint(D3DVECTOR &p2D, int objRank, D3DVECTOR p3D); + bool TransformPoint(Math::Vector &p2D, int objRank, Math::Vector p3D); void ComputeDistance(); void UpdateGeometry(); void RenderGroundSpot(); @@ -565,15 +567,15 @@ protected: int m_alphaSrcBlend[2]; int m_alphaDestBlend[2]; - D3DMATRIX m_matProj; - D3DMATRIX m_matLeftView; - D3DMATRIX m_matRightView; - D3DMATRIX m_matView; + Math::Matrix m_matProj; + Math::Matrix m_matLeftView; + Math::Matrix m_matRightView; + Math::Matrix m_matView; float m_focus; - D3DMATRIX m_matWorldInterface; - D3DMATRIX m_matProjInterface; - D3DMATRIX m_matViewInterface; + Math::Matrix m_matWorldInterface; + Math::Matrix m_matProjInterface; + Math::Matrix m_matViewInterface; DWORD m_baseTime; DWORD m_stopTime; @@ -593,8 +595,8 @@ protected: D3DShadow* m_shadow; D3DGroundSpot* m_groundSpot; D3DGroundMark m_groundMark; - D3DVECTOR m_eyePt; - D3DVECTOR m_lookatPt; + Math::Vector m_eyePt; + Math::Vector m_lookatPt; float m_eyeDirH; float m_eyeDirV; int m_rankView; -- cgit v1.2.3-1-g7c22