Solution refactoring and restructuring, removed Boost dependency, removed unused tools

This commit is contained in:
2022-11-21 23:42:01 +02:00
parent 33f19f9ff6
commit 9ef9f39e88
817 changed files with 326 additions and 59698 deletions

View File

@ -0,0 +1,200 @@
#include "StdAfx.h"
#include "../eterBase/Utils.h"
#include "AttributeData.h"
const char c_szAttributeDataFileHeader[] = "AttributeData";
const int c_iAttributeDataFileHeaderLength = 13;
/*DWORD CAttributeData::GetCollisionDataCount() const
{
return m_CollisionDataVector.size();
}
BOOL CAttributeData::GetCollisionDataPointer(DWORD dwIndex, const TCollisionData ** c_ppCollisionData) const
{
if (dwIndex >= GetCollisionDataCount())
return FALSE;
*c_ppCollisionData = &m_CollisionDataVector[dwIndex];
return TRUE;
}
*/
const CStaticCollisionDataVector & CAttributeData::GetCollisionDataVector() const
{
return m_StaticCollisionDataVector;
}
const THeightDataVector & CAttributeData::GetHeightDataVector() const
{
return m_HeightDataVector;
}
DWORD CAttributeData::GetHeightDataCount() const
{
return m_HeightDataVector.size();
}
BOOL CAttributeData::GetHeightDataPointer(DWORD dwIndex, const THeightData ** c_ppHeightData) const
{
if (dwIndex >= GetHeightDataCount())
return FALSE;
*c_ppHeightData = &m_HeightDataVector[dwIndex];
return TRUE;
}
float CAttributeData::GetMaximizeRadius()
{
return m_fMaximizeRadius;
}
size_t CAttributeData::AddCollisionData(const CStaticCollisionData& data)
{
m_StaticCollisionDataVector.push_back(data);
return m_StaticCollisionDataVector.size();
}
bool CAttributeData::OnLoad(int /*iSize*/, const void * c_pvBuf)
{
if (!c_pvBuf)
{
// NOTE: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٸ<EFBFBD><D9B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>׷<EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><20><><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD> <20>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD> <20>ʰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ.
return true;
}
const BYTE * c_pbBuf = static_cast<const BYTE *> (c_pvBuf);
char szHeader[c_iAttributeDataFileHeaderLength+1];
memcpy(szHeader, c_pbBuf, c_iAttributeDataFileHeaderLength+1);
c_pbBuf += c_iAttributeDataFileHeaderLength+1;
if (strcmp(szHeader, c_szAttributeDataFileHeader))
return FALSE;
DWORD dwCollisionDataCount;
DWORD dwHeightDataCount;
memcpy(&dwCollisionDataCount, c_pbBuf, sizeof(DWORD));
c_pbBuf += sizeof(DWORD);
memcpy(&dwHeightDataCount, c_pbBuf, sizeof(DWORD));
c_pbBuf += sizeof(DWORD);
m_StaticCollisionDataVector.clear();
m_StaticCollisionDataVector.resize(dwCollisionDataCount);
m_HeightDataVector.clear();
m_HeightDataVector.resize(dwHeightDataCount);
for (DWORD i = 0; i < dwCollisionDataCount; ++i)
{
CStaticCollisionData & rCollisionData = m_StaticCollisionDataVector[i];
memcpy(&rCollisionData.dwType, c_pbBuf, sizeof(DWORD));
c_pbBuf += sizeof(DWORD);
memcpy(rCollisionData.szName, c_pbBuf, 32);
c_pbBuf += 32;
memcpy(&rCollisionData.v3Position, c_pbBuf, sizeof(D3DXVECTOR3));
c_pbBuf += sizeof(D3DXVECTOR3);
switch(rCollisionData.dwType)
{
case COLLISION_TYPE_PLANE:
memcpy(rCollisionData.fDimensions, c_pbBuf, 2*sizeof(float));
c_pbBuf += 2*sizeof(float);
break;
case COLLISION_TYPE_BOX:
memcpy(rCollisionData.fDimensions, c_pbBuf, 3*sizeof(float));
c_pbBuf += 3*sizeof(float);
break;
case COLLISION_TYPE_SPHERE:
memcpy(rCollisionData.fDimensions, c_pbBuf, sizeof(float));
c_pbBuf += sizeof(float);
break;
case COLLISION_TYPE_CYLINDER:
memcpy(rCollisionData.fDimensions, c_pbBuf, 2*sizeof(float));
c_pbBuf += 2*sizeof(float);
break;
case COLLISION_TYPE_AABB:
memcpy(rCollisionData.fDimensions, c_pbBuf, 3*sizeof(float));
c_pbBuf += 3*sizeof(float);
break;
case COLLISION_TYPE_OBB:
memcpy(rCollisionData.fDimensions, c_pbBuf, 3*sizeof(float));
c_pbBuf += 3*sizeof(float);
break;
}
memcpy(rCollisionData.quatRotation, c_pbBuf, sizeof(D3DXQUATERNION));
c_pbBuf += sizeof(D3DXQUATERNION);
}
for (DWORD j = 0; j < dwHeightDataCount; ++j)
{
THeightData & rHeightData = m_HeightDataVector[j];
memcpy(rHeightData.szName, c_pbBuf, 32);
c_pbBuf += 32;
DWORD dwPrimitiveCount;
memcpy(&dwPrimitiveCount, c_pbBuf, sizeof(DWORD));
c_pbBuf += sizeof(DWORD);
rHeightData.v3VertexVector.clear();
rHeightData.v3VertexVector.resize(dwPrimitiveCount);
memcpy(&rHeightData.v3VertexVector[0], c_pbBuf, dwPrimitiveCount*sizeof(D3DXVECTOR3));
c_pbBuf += dwPrimitiveCount*sizeof(D3DXVECTOR3);
// Getting Maximize Radius
for (DWORD k = 0; k < rHeightData.v3VertexVector.size(); ++k)
{
m_fMaximizeRadius = fMAX(m_fMaximizeRadius, fabs(rHeightData.v3VertexVector[k].x)+50.0f);
m_fMaximizeRadius = fMAX(m_fMaximizeRadius, fabs(rHeightData.v3VertexVector[k].y)+50.0f);
m_fMaximizeRadius = fMAX(m_fMaximizeRadius, fabs(rHeightData.v3VertexVector[k].z)+50.0f);
}
// Getting Maximize Radius
}
return true;
}
void CAttributeData::OnClear()
{
m_StaticCollisionDataVector.clear();
m_HeightDataVector.clear();
}
bool CAttributeData::OnIsEmpty() const
{
if (!m_StaticCollisionDataVector.empty())
return false;
if (!m_HeightDataVector.empty())
return false;
return true;
}
bool CAttributeData::OnIsType(TType type)
{
if (CAttributeData::Type() == type)
return true;
return CResource::OnIsType(type);
}
CAttributeData::TType CAttributeData::Type()
{
static TType s_type = StringToType("CAttributeData");
return s_type;
}
void CAttributeData::OnSelfDestruct()
{
Clear();
}
CAttributeData::CAttributeData(const char * c_szFileName) : CResource(c_szFileName)
{
m_fMaximizeRadius = 0.0f;
}
CAttributeData::~CAttributeData()
{
}

View File

@ -0,0 +1,71 @@
#pragma once
#include "Resource.h"
#include "Ref.h"
#include "CollisionData.h"
typedef struct SHeightData
{
char szName[32+1];
std::vector<D3DXVECTOR3> v3VertexVector;
} THeightData;
typedef std::vector<THeightData> THeightDataVector;
class CAttributeData : public CResource
{
public:
typedef CRef<CAttributeData> TRef;
/*
enum ECollisionType
{
COLLISION_TYPE_PLANE,
COLLISION_TYPE_BOX,
COLLISION_TYPE_SPHERE,
COLLISION_TYPE_CYLINDER,
};
typedef struct SCollisionData
{
DWORD dwType;
char szName[32+1];
D3DXVECTOR3 v3Position;
float fDimensions[3];
D3DXQUATERNION quatRotation;
} TCollisionData;*/
public:
static TType Type();
public:
CAttributeData(const char * c_szFileName);
virtual ~CAttributeData();
//DWORD GetCollisionDataCount() const;
//BOOL GetCollisionDataPointer(DWORD dwIndex, const TCollisionData ** c_ppCollisionData) const;
const CStaticCollisionDataVector & GetCollisionDataVector() const;
const THeightDataVector & GetHeightDataVector() const;
size_t AddCollisionData(const CStaticCollisionData& collisionData); // return m_StaticCollisionDataVector.size();
DWORD GetHeightDataCount() const;
BOOL GetHeightDataPointer(DWORD dwIndex, const THeightData ** c_ppHeightData) const;
float GetMaximizeRadius();
protected:
bool OnLoad(int iSize, const void * c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
void OnSelfDestruct();
protected:
float m_fMaximizeRadius;
//std::vector<TCollisionData> m_CollisionDataVector;
CStaticCollisionDataVector m_StaticCollisionDataVector;
THeightDataVector m_HeightDataVector;
};

View File

@ -0,0 +1,215 @@
#include "StdAfx.h"
#include "../eterBase/Utils.h"
#include "AttributeInstance.h"
#include "GrpMath.h"
CDynamicPool<CAttributeInstance> CAttributeInstance::ms_kPool;
const float c_fStepSize = 50.0f;
bool CAttributeInstance::Picking(const D3DXVECTOR3 & v, const D3DXVECTOR3 & dir, float & out_x, float & out_y)
{
if (IsEmpty())
return FALSE;
//fy *= -1.0f;
bool bPicked = false;
float nx = 0;
float ny = 0;
for (DWORD i = 0; i < m_v3HeightDataVector.size(); ++i)
for (DWORD j = 0; j < m_v3HeightDataVector[i].size(); j+=3)
{
const D3DXVECTOR3 & cv0 = m_v3HeightDataVector[i][j];
const D3DXVECTOR3 & cv2 = m_v3HeightDataVector[i][j+1];
const D3DXVECTOR3 & cv1 = m_v3HeightDataVector[i][j+2];
D3DXVECTOR3 n;
D3DXVec3Cross(&n,&(cv1-cv0),&(cv2-cv0));
D3DXVECTOR3 x;
float t;
t = - D3DXVec3Dot(&(v-cv0),&n)/D3DXVec3Dot(&dir,&n);
x = v+t*dir;
D3DXVECTOR3 temp;
D3DXVec3Cross(&temp,&(cv1-cv0),&(x-cv0));
if (D3DXVec3Dot(&temp,&n)<0) continue;
D3DXVec3Cross(&temp,&(cv2-cv1),&(x-cv1));
if (D3DXVec3Dot(&temp,&n)<0) continue;
D3DXVec3Cross(&temp,&(cv0-cv2),&(x-cv2));
if (D3DXVec3Dot(&temp,&n)<0) continue;
if (bPicked)
{
if ((v.x-x.x)*(v.x-x.x)+(v.y-x.y)*(v.y-x.y)<(v.x-nx)*(v.x-nx)+(v.y-ny)*(v.y-ny))
{
nx=x.x;
ny=x.y;
}
}
else
{
nx = x.x;
ny = x.y;
}
bPicked = true;
}
if (bPicked)
{
out_x = nx;
out_y = ny;
}
return bPicked;
}
BOOL CAttributeInstance::GetHeight(float fx, float fy, float * pfHeight)
{
if(IsEmpty())
return FALSE;
fy *= -1.0f;
if (!IsInHeight(fx, fy))
return FALSE;
BOOL bFlag = FALSE;
for (DWORD i = 0; i < m_v3HeightDataVector.size(); ++i)
for (DWORD j = 0; j < m_v3HeightDataVector[i].size(); j+=3)
{
const D3DXVECTOR3 & c_rv3Vertex0 = m_v3HeightDataVector[i][j];
const D3DXVECTOR3 & c_rv3Vertex1 = m_v3HeightDataVector[i][j+1];
const D3DXVECTOR3 & c_rv3Vertex2 = m_v3HeightDataVector[i][j+2];
if (
fx<c_rv3Vertex0.x && fx<c_rv3Vertex1.x && fx<c_rv3Vertex2.x ||
fx>c_rv3Vertex0.x && fx>c_rv3Vertex1.x && fx>c_rv3Vertex2.x ||
fy<c_rv3Vertex0.y && fy<c_rv3Vertex1.y && fy<c_rv3Vertex2.y ||
fy>c_rv3Vertex0.y && fy>c_rv3Vertex1.y && fy>c_rv3Vertex2.y
)
continue;
if (IsInTriangle2D(c_rv3Vertex0.x, c_rv3Vertex0.y,
c_rv3Vertex1.x, c_rv3Vertex1.y,
c_rv3Vertex2.x, c_rv3Vertex2.y, fx, fy))
{
D3DXVECTOR3 v3Line1 = c_rv3Vertex1 - c_rv3Vertex0;
D3DXVECTOR3 v3Line2 = c_rv3Vertex2 - c_rv3Vertex0;
D3DXVECTOR3 v3Cross;
D3DXVec3Cross(&v3Cross, &v3Line1, &v3Line2);
D3DXVec3Normalize(&v3Cross, &v3Cross);
if (0.0f != v3Cross.z)
{
float fd = (v3Cross.x*c_rv3Vertex0.x + v3Cross.y*c_rv3Vertex0.y + v3Cross.z*c_rv3Vertex0.z);
float fm = (v3Cross.x*fx + v3Cross.y*fy);
*pfHeight = fMAX((fd - fm) / v3Cross.z, *pfHeight);
bFlag = TRUE;
}
}
}
return bFlag;
}
CAttributeData * CAttributeInstance::GetObjectPointer() const
{
return m_roAttributeData.GetPointer();
}
BOOL CAttributeInstance::IsInHeight(float fx, float fy)
{
float fdx = m_matGlobal._41 - fx;
float fdy = m_matGlobal._42 - fy;
if (sqrtf(fdx*fdx + fdy*fdy) > m_fHeightRadius)
return FALSE;
return TRUE;
}
void CAttributeInstance::SetObjectPointer(CAttributeData * pAttributeData)
{
Clear();
m_roAttributeData.SetPointer(pAttributeData);
}
void CAttributeInstance::RefreshObject(const D3DXMATRIX & c_rmatGlobal)
{
assert(!m_roAttributeData.IsNull());
m_matGlobal = c_rmatGlobal;
// Height
m_fHeightRadius = m_roAttributeData->GetMaximizeRadius();
DWORD dwHeightDataCount = m_roAttributeData->GetHeightDataCount();
m_v3HeightDataVector.clear();
m_v3HeightDataVector.resize(dwHeightDataCount);
for (DWORD i = 0; i < dwHeightDataCount; ++i)
{
const THeightData * c_pHeightData;
if (!m_roAttributeData->GetHeightDataPointer(i, &c_pHeightData))
continue;
DWORD dwVertexCount = c_pHeightData->v3VertexVector.size();
m_v3HeightDataVector[i].clear();
m_v3HeightDataVector[i].resize(dwVertexCount);
for (DWORD j = 0; j < dwVertexCount; ++j)
{
D3DXVec3TransformCoord(&m_v3HeightDataVector[i][j], &c_pHeightData->v3VertexVector[j], &m_matGlobal);
}
}
}
const char * CAttributeInstance::GetDataFileName() const
{
return m_roAttributeData->GetFileName();
}
void CAttributeInstance::CreateSystem(UINT uCapacity)
{
ms_kPool.Create(uCapacity);
}
void CAttributeInstance::DestroySystem()
{
ms_kPool.Destroy();
}
CAttributeInstance* CAttributeInstance::New()
{
return ms_kPool.Alloc();
}
void CAttributeInstance::Delete(CAttributeInstance* pkInst)
{
ms_kPool.Free(pkInst);
}
BOOL CAttributeInstance::IsEmpty() const
{
if (!m_v3HeightDataVector.empty())
return FALSE;
return TRUE;
}
void CAttributeInstance::Clear()
{
m_fHeightRadius = 0.0f;
m_fCollisionRadius = 0.0f;
D3DXMatrixIdentity(&m_matGlobal);
m_v3HeightDataVector.clear();
m_roAttributeData.SetPointer(NULL);
}
CAttributeInstance::CAttributeInstance()
{
}
CAttributeInstance::~CAttributeInstance()
{
}

View File

@ -0,0 +1,66 @@
#pragma once
#include <vector>
#include "AttributeData.h"
#include "Pool.h"
class CAttributeInstance
{
public:
CAttributeInstance();
virtual ~CAttributeInstance();
void Clear();
BOOL IsEmpty() const;
const char * GetDataFileName() const;
// NOTE : Object <20><><EFBFBD><EFBFBD>
void SetObjectPointer(CAttributeData * pAttributeData);
void RefreshObject(const D3DXMATRIX & c_rmatGlobal);
CAttributeData * GetObjectPointer() const;
bool Picking(const D3DXVECTOR3 & v, const D3DXVECTOR3 & dir, float & out_x, float & out_y);
BOOL IsInHeight(float fx, float fy);
BOOL GetHeight(float fx, float fy, float * pfHeight);
BOOL IsHeightData() const;
protected:
void SetGlobalMatrix(const D3DXMATRIX & c_rmatGlobal);
void SetGlobalPosition(const D3DXVECTOR3 & c_rv3Position);
protected:
float m_fCollisionRadius;
float m_fHeightRadius;
D3DXMATRIX m_matGlobal;
std::vector< std::vector<D3DXVECTOR3> > m_v3HeightDataVector;
CAttributeData::TRef m_roAttributeData;
/*
BOOL m_isHeightCached;
struct SHeightCacheData
{
float fxMin;
float fyMin;
float fxMax;
float fyMax;
DWORD dwxStep;
DWORD dwyStep;
std::vector<float> kVec_fHeight;
} m_kHeightCacheData;
*/
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CAttributeInstance* New();
static void Delete(CAttributeInstance* pkInst);
static CDynamicPool<CAttributeInstance> ms_kPool;
};

View File

@ -0,0 +1,183 @@
#include "StdAfx.h"
#include "BlockTexture.h"
#include "GrpBase.h"
#include "GrpDib.h"
#include "../eterbase/Stl.h"
#include "../eterlib/StateManager.h"
void CBlockTexture::SetClipRect(const RECT & c_rRect)
{
m_bClipEnable = TRUE;
m_clipRect = c_rRect;
}
void CBlockTexture::Render(int ix, int iy)
{
int isx = ix + m_rect.left;
int isy = iy + m_rect.top;
int iex = ix + m_rect.left + m_dwWidth;
int iey = iy + m_rect.top + m_dwHeight;
float su = 0.0f;
float sv = 0.0f;
float eu = 1.0f;
float ev = 1.0f;
if (m_bClipEnable)
{
if (isx > m_clipRect.right)
return;
if (iex < m_clipRect.left)
return;
if (isy > m_clipRect.bottom)
return;
if (iey < m_clipRect.top)
return;
if (m_clipRect.left > isx)
{
int idx = m_clipRect.left - isx;
isx += idx;
su += float(idx) / float(m_dwWidth);
}
if (iex > m_clipRect.right)
{
int idx = iex - m_clipRect.right;
iex -= idx;
eu -= float(idx) / float(m_dwWidth);
}
if (m_clipRect.top > isy)
{
int idy = m_clipRect.top - isy;
isy += idy;
sv += float(idy) / float(m_dwHeight);
}
if (iey > m_clipRect.bottom)
{
int idy = iey - m_clipRect.bottom;
iey -= idy;
ev -= float(idy) / float(m_dwHeight);
}
}
TPDTVertex vertices[4];
vertices[0].position.x = isx - 0.5f;
vertices[0].position.y = isy - 0.5f;
vertices[0].position.z = 0.0f;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[0].diffuse = 0xffffffff;
vertices[1].position.x = iex - 0.5f;
vertices[1].position.y = isy - 0.5f;
vertices[1].position.z = 0.0f;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[1].diffuse = 0xffffffff;
vertices[2].position.x = isx - 0.5f;
vertices[2].position.y = iey - 0.5f;
vertices[2].position.z = 0.0f;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[2].diffuse = 0xffffffff;
vertices[3].position.x = iex - 0.5f;
vertices[3].position.y = iey - 0.5f;
vertices[3].position.z = 0.0f;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
vertices[3].diffuse = 0xffffffff;
if (CGraphicBase::SetPDTStream(vertices, 4))
{
CGraphicBase::SetDefaultIndexBuffer(CGraphicBase::DEFAULT_IB_FILL_RECT);
STATEMANAGER.SetTexture(0, m_lpd3dTexture);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
}
}
void CBlockTexture::InvalidateRect(const RECT & c_rsrcRect)
{
RECT dstRect = m_rect;
if (c_rsrcRect.right < dstRect.left ||
c_rsrcRect.left > dstRect.right ||
c_rsrcRect.bottom < dstRect.top ||
c_rsrcRect.top > dstRect.bottom)
{
Tracef("InvalidateRect() - Strange rect");
return;
}
// DIBBAR_LONGSIZE_BUGFIX
const RECT clipRect = {
max(c_rsrcRect.left - dstRect.left, 0),
max(c_rsrcRect.top - dstRect.top, 0),
min(c_rsrcRect.right - dstRect.left, dstRect.right - dstRect.left),
min(c_rsrcRect.bottom - dstRect.top, dstRect.bottom - dstRect.top),
};
// END_OF_DIBBAR_LONGSIZE_BUGFIX
DWORD * pdwSrc;
pdwSrc = (DWORD *)m_pDIB->GetPointer();
pdwSrc += dstRect.left + dstRect.top*m_pDIB->GetWidth();
D3DLOCKED_RECT lockedRect;
if (FAILED(m_lpd3dTexture->LockRect(0, &lockedRect, &clipRect, 0)))
{
Tracef("InvalidateRect() - Failed to LockRect");
return;
}
int iclipWidth = clipRect.right - clipRect.left;
int iclipHeight = clipRect.bottom - clipRect.top;
DWORD * pdwDst = (DWORD *)lockedRect.pBits;
DWORD dwDstWidth = lockedRect.Pitch>>2;
DWORD dwSrcWidth = m_pDIB->GetWidth();
for (int i = 0; i < iclipHeight; ++i)
{
for (int i = 0; i < iclipWidth; ++i)
{
if (pdwSrc[i])
pdwDst[i] = pdwSrc[i] | 0xff000000;
else
pdwDst[i] = 0;
}
pdwDst += dwDstWidth;
pdwSrc += dwSrcWidth;
}
m_lpd3dTexture->UnlockRect(0);
}
bool CBlockTexture::Create(CGraphicDib * pDIB, const RECT & c_rRect, DWORD dwWidth, DWORD dwHeight)
{
if (FAILED(ms_lpd3dDevice->CreateTexture(dwWidth, dwHeight, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_lpd3dTexture)))
{
Tracef("Failed to create block texture %u, %u\n", dwWidth, dwHeight);
return false;
}
m_pDIB = pDIB;
m_rect = c_rRect;
m_dwWidth = dwWidth;
m_dwHeight = dwHeight;
m_bClipEnable = FALSE;
return true;
}
CBlockTexture::CBlockTexture()
{
m_pDIB = NULL;
m_lpd3dTexture = NULL;
}
CBlockTexture::~CBlockTexture()
{
safe_release(m_lpd3dTexture);
m_lpd3dTexture = NULL;
}

View File

@ -0,0 +1,26 @@
#pragma once
#include "GrpBase.h"
class CGraphicDib;
class CBlockTexture : public CGraphicBase
{
public:
CBlockTexture();
virtual ~CBlockTexture();
bool Create(CGraphicDib * pDIB, const RECT & c_rRect, DWORD dwWidth, DWORD dwHeight);
void SetClipRect(const RECT & c_rRect);
void Render(int ix, int iy);
void InvalidateRect(const RECT & c_rsrcRect);
protected:
CGraphicDib * m_pDIB;
RECT m_rect;
RECT m_clipRect;
BOOL m_bClipEnable;
DWORD m_dwWidth;
DWORD m_dwHeight;
LPDIRECT3DTEXTURE8 m_lpd3dTexture;
};

632
src/EterLib/Camera.cpp Normal file
View File

@ -0,0 +1,632 @@
// Camera.cpp: implementation of the CCamera class.
//
//////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "../eterBase/Utils.h"
#include "Camera.h"
const float c_fDefaultResistance = 0.3f;
CCameraManager aCameraManager; // CCameraManager Instance
void CCamera::SetCameraMaxDistance(float fMax)
{
CAMERA_MAX_DISTANCE = fMax;
}
float CCamera::GetTargetHeight()
{
return m_fTarget_;
}
void CCamera::SetTargetHeight(float fTarget)
{
m_fTarget_=fTarget;
}
//////////////////////////////////////////////////////////////////////////
// CCamera
//////////////////////////////////////////////////////////////////////////
CCamera::CCamera() :
m_fEyeGroundHeightRatio(0.3f),
m_fTargetHeightLimitRatio(2.0f),
m_fResistance(c_fDefaultResistance),
m_isLock(false)
{
m_fDistance = 1.0f;
m_eCameraState = CAMERA_STATE_NORMAL;
m_eCameraStatePrev = CAMERA_STATE_NORMAL;
m_ulNumScreenBuilding = 0;
m_fPitchSum = 0.0f;
m_fRollSum = 0.0f;
m_fTerrainCollisionRadius = 50.0f;
m_fObjectCollisionRadius = 50.0f;
m_bDrag = false;
m_lMousePosX = -1;
m_lMousePosY = -1;
m_fTarget_ = CAMERA_TARGET_STANDARD;
m_v3AngularAcceleration = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
m_v3AngularVelocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
m_bProcessTerrainCollision = true;
SetViewParams(D3DXVECTOR3(0.0f,0.0f,1.0f), D3DXVECTOR3(0.0f,0.0f,0.0f), D3DXVECTOR3(0.0f,1.0f,0.0f));
}
CCamera::~CCamera()
{
}
void CCamera::Lock()
{
m_isLock = true;
}
void CCamera::Unlock()
{
m_isLock = false;
}
bool CCamera::IsLock()
{
return m_isLock;
}
void CCamera::SetResistance(float fResistance)
{
m_fResistance = c_fDefaultResistance * fResistance;
}
void CCamera::Wheel(int nLen)
{
if (IsLock())
return;
m_v3AngularVelocity.y = (float)(nLen) * m_fResistance;
}
void CCamera::BeginDrag(int nMouseX, int nMouseY)
{
if (IsLock())
return;
m_bDrag = true;
m_lMousePosX = nMouseX;
m_lMousePosY = nMouseY;
m_fPitchSum = 0.0f;
m_fRollSum = 0.0f;
}
bool CCamera::IsDraging()
{
if (IsLock())
return false;
return m_bDrag;
}
bool CCamera::EndDrag()
{
if (IsLock())
return false;
m_bDrag = false;
float fSum=sqrt(m_fPitchSum*m_fPitchSum+m_fRollSum*m_fRollSum);
m_fPitchSum = 0.0f;
m_fRollSum = 0.0f;
if (fSum<1.0f)
return false;
return true;
}
bool CCamera::Drag(int nMouseX, int nMouseY, LPPOINT lpReturnPoint)
{
if (IsLock())
return false;
if (!m_bDrag)
{
m_lMousePosX = nMouseX;
m_lMousePosY = nMouseY;
lpReturnPoint->x = m_lMousePosX;
lpReturnPoint->y = m_lMousePosY;
return false;
}
long lMouseX = nMouseX;
long lMouseY = nMouseY;
float fNewPitchVelocity = (float)(lMouseY - m_lMousePosY) * m_fResistance;
float fNewRotationVelocity = (float)(lMouseX - m_lMousePosX) * m_fResistance;
m_fPitchSum += fNewPitchVelocity;
m_fRollSum += fNewRotationVelocity;
if (CAMERA_STATE_CANTGOLEFT == GetCameraState())
fNewRotationVelocity = fMAX(0.0f, fNewRotationVelocity);
if (CAMERA_STATE_CANTGORIGHT == GetCameraState())
fNewRotationVelocity = fMIN(0.0f, fNewRotationVelocity);
if (CAMERA_STATE_CANTGODOWN == GetCameraState())
fNewPitchVelocity = fMAX(0.0f, fNewPitchVelocity);
m_v3AngularVelocity.x = fNewRotationVelocity;
m_v3AngularVelocity.z = fNewPitchVelocity;
lpReturnPoint->x = m_lMousePosX;
lpReturnPoint->y = m_lMousePosY;
return true;
}
//////////////////////////////////////////////////////////////////////////
// Update
void CCamera::SetCameraState(eCameraState eNewCameraState)
{
if (eNewCameraState == m_eCameraState)
return;
m_eCameraStatePrev = m_eCameraState;
m_eCameraState = eNewCameraState;
/*
if ((CAMERA_STATE_NORMAL == m_eCameraStatePrev))
{
m_fDistanceBackup = m_fDistance;
m_fPitchBackup = m_fPitch;
m_fRollBackup = m_fRoll;
}
else if ((CAMERA_STATE_CANTGODOWN == m_eCameraStatePrev) && (CAMERA_STATE_CANTGODOWN == m_eCameraState) )
{
m_v3EyeBackup = m_v3Eye;
}
*/
}
void CCamera::IncreaseNumSrcreenBuilding()
{
++m_ulNumScreenBuilding;
}
void CCamera::ResetNumScreenBuilding()
{
m_ulNumScreenBuilding = 0;
}
//////////////////////////////////////////////////////////////////////////
// Property
void CCamera::SetViewParams( const D3DXVECTOR3 &v3Eye, const D3DXVECTOR3& v3Target, const D3DXVECTOR3& v3Up)
{
if (IsLock())
return;
// Set attributes for the view matrix
m_v3Eye = v3Eye;
m_v3Target = v3Target;
m_v3Up = v3Up;
SetViewMatrix();
}
void CCamera::SetEye(const D3DXVECTOR3 & v3Eye)
{
if (IsLock())
return;
m_v3Eye = v3Eye;
SetViewMatrix();
}
void CCamera::SetTarget(const D3DXVECTOR3 & v3Target)
{
if (IsLock())
return;
m_v3Target = v3Target;
SetViewMatrix();
}
void CCamera::SetUp(const D3DXVECTOR3 & v3Up)
{
if (IsLock())
return;
m_v3Up = v3Up;
SetViewMatrix();
}
void CCamera::SetViewMatrix()
{
m_v3View = m_v3Target - m_v3Eye;
D3DXVECTOR3 v3CenterRay = -m_v3View;
CalculateRoll();
m_fDistance = D3DXVec3Length(&m_v3View);
assert(m_fDistance >= 0);
D3DXVec3Normalize(&m_v3View , &m_v3View);
D3DXVec3Cross(&m_v3Cross, &m_v3Up, &m_v3View);
D3DXVec3Normalize(&m_v3Cross, &m_v3Cross);
D3DXVec3Cross(&m_v3Up, &m_v3View, &m_v3Cross);
D3DXVec3Normalize(&m_v3Up, &m_v3Up);
m_fPitch = D3DXVec3Dot(&m_v3Up, &D3DXVECTOR3(0.0f, 0.0f, 1.0f));// / D3DXVec2Length(&v2ViewYZ);
if (m_fPitch >= 1)
m_fPitch = 1;
else if (m_fPitch <= -1)
m_fPitch = -1;
m_fPitch = acosf(m_fPitch);
m_fPitch *= (180.0f / D3DX_PI);
if ( 0 < m_v3View.z )
m_fPitch = -m_fPitch;
D3DXMatrixLookAtRH(&m_matView, &m_v3Eye, &m_v3Target, &m_v3Up);
float fDeterminantD3DMatView = D3DXMatrixfDeterminant(&m_matView);
D3DXMatrixInverse(&m_matInverseView, &fDeterminantD3DMatView, &m_matView);
m_matBillboard = m_matInverseView;
m_matBillboard._41 = 0.0f;
m_matBillboard._42 = 0.0f;
m_matBillboard._43 = 0.0f;
m_ViewRay.SetStartPoint(m_v3Target);
m_ViewRay.SetDirection(v3CenterRay, m_fDistance);
m_kCameraBottomToTerrainRay.SetStartPoint(m_v3Eye);
m_kCameraFrontToTerrainRay.SetStartPoint(m_v3Eye);
m_kCameraBackToTerrainRay.SetStartPoint(m_v3Eye);
m_kCameraLeftToTerrainRay.SetStartPoint(m_v3Eye);
m_kCameraRightToTerrainRay.SetStartPoint(m_v3Eye);
m_kTargetToCameraBottomRay.SetStartPoint(m_v3Target);
m_kCameraBottomToTerrainRay.SetDirection(-m_v3Up, 2.0f * m_fTerrainCollisionRadius);
m_kCameraFrontToTerrainRay.SetDirection(m_v3View, 4.0f * m_fTerrainCollisionRadius);
m_kCameraBackToTerrainRay.SetDirection(-m_v3View, m_fTerrainCollisionRadius);
m_kCameraLeftToTerrainRay.SetDirection(-m_v3Cross, 3.0f * m_fTerrainCollisionRadius);
m_kCameraRightToTerrainRay.SetDirection(m_v3Cross, 3.0f * m_fTerrainCollisionRadius);
m_kTargetToCameraBottomRay.SetDirection(v3CenterRay - m_fTerrainCollisionRadius * m_v3Up,
D3DXVec3Length(&(v3CenterRay - m_fTerrainCollisionRadius * m_v3Up)));
m_kLeftObjectCollisionRay.SetStartPoint(m_v3Target);
m_kTopObjectCollisionRay.SetStartPoint(m_v3Target);
m_kRightObjectCollisionRay.SetStartPoint(m_v3Target);
m_kBottomObjectCollisionRay.SetStartPoint(m_v3Target);
m_kLeftObjectCollisionRay.SetDirection(v3CenterRay + m_fObjectCollisionRadius * m_v3Cross,
D3DXVec3Length(&(v3CenterRay + m_fObjectCollisionRadius * m_v3Cross)));
m_kRightObjectCollisionRay.SetDirection(v3CenterRay - m_fObjectCollisionRadius * m_v3Cross,
D3DXVec3Length(&(v3CenterRay - m_fObjectCollisionRadius * m_v3Cross)));
m_kTopObjectCollisionRay.SetDirection(v3CenterRay + m_fObjectCollisionRadius * m_v3Up,
D3DXVec3Length(&(v3CenterRay + m_fObjectCollisionRadius * m_v3Up)));
m_kBottomObjectCollisionRay.SetDirection(v3CenterRay - m_fObjectCollisionRadius * m_v3Up,
D3DXVec3Length(&(v3CenterRay + m_fObjectCollisionRadius * m_v3Up)));
}
void CCamera::Move(const D3DXVECTOR3 & v3Displacement)
{
if (IsLock())
return;
m_v3Eye += v3Displacement;
m_v3Target += v3Displacement;
SetViewMatrix();
}
void CCamera::Zoom(float fRatio)
{
if (IsLock())
return;
if (fRatio == 1.0f)
return;
D3DXVECTOR3 v3Temp = m_v3Eye - m_v3Target;
v3Temp *= fRatio;
m_v3Eye = v3Temp + m_v3Target;
SetViewMatrix();
}
void CCamera::MoveAlongView(float fDistance)
{
if (IsLock())
return;
D3DXVECTOR3 v3Temp;
D3DXVec3Normalize(&v3Temp, &m_v3View);
m_v3Eye += v3Temp * fDistance;
m_v3Target += v3Temp * fDistance;
SetViewMatrix();
}
void CCamera::MoveAlongCross(float fDistance)
{
if (IsLock())
return;
D3DXVECTOR3 v3Temp;
D3DXVec3Normalize(&v3Temp, &m_v3Cross);
m_v3Eye += v3Temp * fDistance;
m_v3Target += v3Temp * fDistance;
SetViewMatrix();
}
void CCamera::MoveAlongUp(FLOAT fDistance)
{
if (IsLock())
return;
D3DXVECTOR3 v3Temp ;
D3DXVec3Normalize(&v3Temp, &m_v3Up);
m_v3Target += v3Temp * fDistance;
m_v3Eye += v3Temp * fDistance;
SetViewMatrix();
}
void CCamera::MoveLateral(float fDistance)
{
if (IsLock())
return;
MoveAlongCross(fDistance);
}
void CCamera::MoveFront(float fDistance)
{
if (IsLock())
return;
D3DXVECTOR3 v3Temp = D3DXVECTOR3(m_v3View.x, m_v3View.y, 0.0f);
D3DXVec3Normalize(&v3Temp, &v3Temp);
m_v3Eye += v3Temp * fDistance;
m_v3Target += v3Temp * fDistance;
SetViewMatrix();
}
void CCamera::MoveVertical(float fDistance)
{
if (IsLock())
return;
m_v3Eye.z += fDistance;
m_v3Target.z += fDistance;
SetViewMatrix();
}
//void CCamera::RotateUpper(float fDegree)
//{
// D3DXMATRIX matRot;
// D3DXMatrixRotationAxis(&matRot, &m_v3Cross, -D3DXToRadian(fDegree));
// D3DXVec3TransformCoord(&m_v3View, &m_v3View, &matRot) ;
// D3DXVec3Cross(&m_v3Up, &m_v3View, &m_v3Cross);
//
// m_v3Target = m_v3Eye + m_v3View;
//
// SetViewMatrix() ;
//}
void CCamera::RotateEyeAroundTarget(float fPitchDegree, float fRollDegree)
{
if (IsLock())
return;
D3DXMATRIX matRot, matRotPitch, matRotRoll;
// <20>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD> <20>Ѿ<D1BE><EEB0A1> <20><><EFBFBD><EFBFBD>...
if (m_fPitch + fPitchDegree > 80.0f)
{
fPitchDegree = 80.0f - m_fPitch;
}
else if( m_fPitch + fPitchDegree < -80.0f)
{
fPitchDegree = -80.0f - m_fPitch;
}
D3DXMatrixRotationAxis(&matRotPitch, &m_v3Cross, D3DXToRadian(fPitchDegree));
D3DXMatrixRotationZ(&matRotRoll, -D3DXToRadian(fRollDegree));
matRot = matRotPitch * matRotRoll;
D3DXVECTOR3 v3Temp = m_v3Eye - m_v3Target;
D3DXVec3TransformCoord(&m_v3Eye, &v3Temp, &matRot);
m_v3Eye += m_v3Target;
SetUp(D3DXVECTOR3(0.0f, 0.0f, 1.0f));
m_fRoll += fRollDegree;
if (m_fRoll > 360.0f)
m_fRoll -= 360.0f;
else if (m_fRoll < -360.0f)
m_fRoll += 360.0f;
}
void CCamera::RotateEyeAroundPoint(const D3DXVECTOR3 & v3Point, float fPitchDegree, float fRollDegree)
{
// if (IsLock())
// return;
D3DXMATRIX matRot, matRotPitch, matRotRoll;
D3DXMatrixRotationAxis(&matRotPitch, &m_v3Cross, D3DXToRadian(fPitchDegree));
D3DXMatrixRotationZ(&matRotRoll, -D3DXToRadian(fRollDegree));
matRot = matRotPitch * matRotRoll;
D3DXVECTOR3 v3Temp = m_v3Eye - v3Point;
D3DXVec3TransformCoord(&m_v3Eye, &v3Temp, &matRot);
m_v3Eye += v3Point;
D3DXVec3TransformCoord(&m_v3Up, &(v3Temp + m_v3Up), &matRot);
m_v3Up -= (m_v3Eye - v3Point);
v3Temp = m_v3Target - v3Point;
D3DXVec3TransformCoord(&m_v3Target, &v3Temp, &matRot);
m_v3Target += v3Point;
SetViewMatrix();
}
void CCamera::Pitch(const float fPitchDelta)
{
// if (IsLock())
// return;
RotateEyeAroundTarget(fPitchDelta, 0.0f);
}
void CCamera::Roll(const float fRollDelta)
{
// if (IsLock())
// return;
RotateEyeAroundTarget(0.0f, fRollDelta);
}
void CCamera::SetDistance(const float fdistance)
{
// if (IsLock())
// return;
Zoom(fdistance/m_fDistance);
}
void CCamera::CalculateRoll()
{
D3DXVECTOR2 v2ViewXY;
v2ViewXY.x = m_v3View.x;
v2ViewXY.y = m_v3View.y;
D3DXVec2Normalize(&v2ViewXY, &v2ViewXY);
float fDot = D3DXVec2Dot(&v2ViewXY, &D3DXVECTOR2(0.0f, 1.0f));
if (fDot >= 1)
fDot = 1;
else if (fDot <= -1)
fDot = -1;
fDot = acosf(fDot);
fDot *= (180.0f / D3DX_PI);
float fCross = D3DXVec2CCW (&v2ViewXY, &D3DXVECTOR2(0.0f, 1.0f));
if ( 0 > fCross)
{
fDot = -fDot;
}
m_fRoll = fDot;
}
//////////////////////////////////////////////////////////////////////////
// CCameraMananger
//////////////////////////////////////////////////////////////////////////
CCameraManager::CCameraManager() :
m_pCurrentCamera(NULL),
m_pPreviousCamera(NULL)
{
AddCamera(DEFAULT_PERSPECTIVE_CAMERA);
AddCamera(DEFAULT_ORTHO_CAMERA);
SetCurrentCamera(DEFAULT_PERSPECTIVE_CAMERA);
}
CCameraManager::~CCameraManager()
{
for (TCameraMap::iterator itor = m_CameraMap.begin(); itor != m_CameraMap.end(); ++itor)
{
delete (*itor).second;
}
m_CameraMap.clear();
}
CCamera * CCameraManager::GetCurrentCamera()
{
if (!m_pCurrentCamera)
assert(false);
return m_pCurrentCamera;
}
void CCameraManager::SetCurrentCamera(unsigned char ucCameraNum)
{
if (m_pCurrentCamera != m_CameraMap[ucCameraNum])
m_pPreviousCamera = m_pCurrentCamera;
m_pCurrentCamera = m_CameraMap[ucCameraNum];
}
void CCameraManager::ResetToPreviousCamera()
{
if (!m_pPreviousCamera)
assert(false);
m_pCurrentCamera = m_pPreviousCamera;
m_pPreviousCamera = NULL;
}
bool CCameraManager::isCurrentCamera(unsigned char ucCameraNum)
{
if (m_CameraMap[ucCameraNum] == m_pCurrentCamera)
return true;
return false;
}
// <20><EFBFBD><E2BDBA><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD>...
bool CCameraManager::AddCamera(unsigned char ucCameraNum)
{
if(m_CameraMap.end() != m_CameraMap.find(ucCameraNum))
return false;
m_CameraMap.insert(TCameraMap::value_type(ucCameraNum, new CCamera));
return true;
}
bool CCameraManager::RemoveCamera(unsigned char ucCameraNum)
{
TCameraMap::iterator itor = m_CameraMap.find(ucCameraNum);
if(m_CameraMap.end() == itor)
return false;
m_CameraMap.erase(itor);
return true;
}
unsigned char CCameraManager::GetCurrentCameraNum()
{
if (!m_pCurrentCamera)
return NO_CURRENT_CAMERA;
for (TCameraMap::iterator itor = m_CameraMap.begin(); itor != m_CameraMap.end(); ++itor)
if(m_pCurrentCamera == (*itor).second)
return (*itor).first;
return NO_CURRENT_CAMERA;
}
bool CCameraManager::isTerrainCollisionEnable()
{
return m_pCurrentCamera->isTerrainCollisionEnable();
}
void CCameraManager::SetTerrainCollision(bool bEnable)
{
m_pCurrentCamera->SetTerrainCollision(bEnable);
}

285
src/EterLib/Camera.h Normal file
View File

@ -0,0 +1,285 @@
// Camera.h: interface for the CCamera class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CAMERA_H__C5D086BE_7A03_4246_9145_336747C47D9E__INCLUDED_)
#define AFX_CAMERA_H__C5D086BE_7A03_4246_9145_336747C47D9E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <map>
#include "../eterBase/Singleton.h"
#include "Ray.h"
const float CAMERA_TARGET_STANDARD = 100.0f;
const float CAMERA_TARGET_FACE = 150.0f;
typedef enum _eCameraState_
{
CAMERA_STATE_NORMAL,
CAMERA_STATE_CANTGODOWN,
CAMERA_STATE_CANTGORIGHT,
CAMERA_STATE_CANTGOLEFT,
CAMERA_STATE_SCREEN_BY_BUILDING,
CAMERA_STATE_SCREEN_BY_BUILDING_AND_TOOCLOSE,
} eCameraState;
class CCamera
{
public:
CCamera();
virtual ~CCamera();
static void SetCameraMaxDistance(float fMax);
void Lock();
void Unlock();
bool IsLock();
void Wheel(int nWheelLen);
bool Drag(int nMouseX, int nMouseY, LPPOINT lpReturnPoint);
bool EndDrag();
void BeginDrag(int nMouseX, int nMouseY);
bool IsDraging();
void SetResistance(float fResistance);
private:
const CCamera & operator = (const CCamera &) ; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
CCamera (const CCamera & ) ; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// Camera Update
eCameraState m_eCameraState;
eCameraState m_eCameraStatePrev;
float m_fPitchBackup;
float m_fRollBackup;
float m_fDistanceBackup;
float m_fTargetZBackUp;
D3DXVECTOR3 m_v3EyeBackup;
unsigned long m_ulNumScreenBuilding;
// protected:
bool m_isLock;
// Attributes for view matrix
D3DXVECTOR3 m_v3Eye;
D3DXVECTOR3 m_v3Target;
D3DXVECTOR3 m_v3Up;
// m_v3View = m_v3Target - m_v3Eye
D3DXVECTOR3 m_v3View;
// m_v3Cross = Cross(m_v3Up, m_v3View)
D3DXVECTOR3 m_v3Cross;
//ViewMatrixes
D3DXMATRIX m_matView;
D3DXMATRIX m_matInverseView;
D3DXMATRIX m_matBillboard; // Special matrix for billboarding effects
//<2F>߰<EFBFBD><DFB0><EFBFBD>
float m_fPitch;
float m_fRoll;
float m_fDistance;
// ī<>޶<EFBFBD> AI<41><49> <20><><EFBFBD><EFBFBD> Ray <20><>
// ī<>޶<EFBFBD><DEB6><EFBFBD> <20>ѷ<EFBFBD><D1B7><EFBFBD> Ray
CRay m_kCameraBottomToTerrainRay;
CRay m_kCameraFrontToTerrainRay;
CRay m_kCameraBackToTerrainRay;
CRay m_kCameraLeftToTerrainRay;
CRay m_kCameraRightToTerrainRay;
CRay m_kTargetToCameraBottomRay;
CRay m_ViewRay;
CRay m_kLeftObjectCollisionRay;
CRay m_kTopObjectCollisionRay;
CRay m_kRightObjectCollisionRay;
CRay m_kBottomObjectCollisionRay;
float m_fTerrainCollisionRadius;
float m_fObjectCollisionRadius;
// protected:
float m_fTarget_;
float m_fEyeGroundHeightRatio;
float m_fTargetHeightLimitRatio;
float m_fPitchSum;
float m_fRollSum;
long m_lMousePosX;
long m_lMousePosY;
bool m_bDrag;
// protected:
// <20><><EFBFBD><EFBFBD>
D3DXVECTOR3 m_v3AngularAcceleration;
D3DXVECTOR3 m_v3AngularVelocity;
float m_fResistance;
public:
//////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD>
//////////////////////////////////////////////////////////////////////////
void SetAngularAcceleration(D3DXVECTOR3 v3AngularAcceleration) { m_v3AngularAcceleration = v3AngularAcceleration; }
//////////////////////////////////////////////////////////////////////////
// AI
//////////////////////////////////////////////////////////////////////////
void SetTerrainCollisionRadius(float fTerrainCollisionRadius) { m_fTerrainCollisionRadius = fTerrainCollisionRadius; }
void SetObjectCollisionRadius(float fObjectCollisionRadius) { m_fObjectCollisionRadius = fObjectCollisionRadius; }
CRay & GetViewRay() { return m_ViewRay; }
CRay & GetLeftObjectCollisionRay() { return m_kLeftObjectCollisionRay; }
CRay & GetRightObjectCollisionRay() { return m_kRightObjectCollisionRay; }
CRay & GetTopObjectCollisionRay() { return m_kTopObjectCollisionRay; }
CRay & GetBottomObjectCollisionRay() { return m_kBottomObjectCollisionRay; }
//////////////////////////////////////////////////////////////////////////
// Update
//////////////////////////////////////////////////////////////////////////
void Update();
eCameraState GetCameraState() {return m_eCameraState;}
void SetCameraState(eCameraState eNewCameraState);
void IncreaseNumSrcreenBuilding();
void ResetNumScreenBuilding();
unsigned long & GetNumScreenBuilding() { return m_ulNumScreenBuilding; }
const float & GetPitchBackUp() { return m_fPitchBackup; }
const float & GetRollBackUp() { return m_fRollBackup; }
const float & GetDistanceBackUp() { return m_fDistanceBackup; }
//////////////////////////////////////////////////////////////////////////
// properties
//////////////////////////////////////////////////////////////////////////
const D3DXVECTOR3 & GetEye() const { return m_v3Eye; }
const D3DXVECTOR3 & GetTarget() const { return m_v3Target; }
const D3DXVECTOR3 & GetUp() const { return m_v3Up; }
const D3DXVECTOR3 & GetView() const { return m_v3View; }
const D3DXVECTOR3 & GetCross() const { return m_v3Cross; }
const D3DXMATRIX & GetViewMatrix() const { return m_matView; }
const D3DXMATRIX & GetInverseViewMatrix() const { return m_matInverseView; }
const D3DXMATRIX & GetBillboardMatrix()const { return m_matBillboard; }
void SetViewParams(const D3DXVECTOR3 & v3Eye, const D3DXVECTOR3& v3Target, const D3DXVECTOR3& v3Up );
void SetEye(const D3DXVECTOR3 & v3Eye);
void SetTarget(const D3DXVECTOR3 & v3Target);
void SetUp(const D3DXVECTOR3 & v3Up);
float GetPitch() const { return m_fPitch; }
float GetRoll() const { return m_fRoll; }
float GetDistance() const { return m_fDistance; }
void Pitch(const float fPitchDelta); //<2F><><EFBFBD>ư<EFBFBD><C6B0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ´<D6B4>.
void Roll(const float fRollDelta);
void SetDistance(const float fdistance);
//////////////////////////////////////////////////////////////////////////
// camera movement
//////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD>״<EFBFBD><D7B4><EFBFBD> <20>̵<EFBFBD>... ī<>޶<EFBFBD> <20><>ġ<EFBFBD><C4A1> Ÿ<><C5B8> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD> <20>޶<EFBFBD><DEB6><EFBFBD><EFBFBD><EFBFBD>.
void Move(const D3DXVECTOR3 & v3Displacement);
// <20><>.. ī<>޶<EFBFBD> <20><>ġ<EFBFBD><C4A1> <20>̵<EFBFBD>.. Ÿ<><C5B8> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD>...
void Zoom(float fRatio);
// <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD>.. Ÿ<><C5B8><EFBFBD><EFBFBD>ġ<EFBFBD><C4A1> <20>޶<EFBFBD><DEB6><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20>ܰ<EFBFBD><DCB0><EFBFBD> <20>ٸ<EFBFBD><D9B8><EFBFBD>...
void MoveAlongView(float fDistance);
// ī<>޶<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD>..
void MoveAlongCross(float fDistance);
// ī<>޶<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD>...
void MoveAlongUp(float fDistance);
// ī<>޶<EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD>... MoveAlongCross<73><73> <20><><EFBFBD><EFBFBD>..
void MoveLateral(float fDistance);
// <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Z <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> XY<58><59><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̵<EFBFBD>..
void MoveFront(float fDistance);
// Z<><5A><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD> <20>̵<EFBFBD>...
void MoveVertical(float fDistance);
// //ī<>޶<EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD><C5B0> <20>Ӹ<EFBFBD><D3B8><EFBFBD> <20><><EFBFBD><EFBFBD>. Ÿ<><C5B8><EFBFBD><EFBFBD> <20>޶<EFBFBD><DEB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
// //ȸ<><C8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴ<EFBFBD> "<22><>(Degree)"<22><> <20>ִ´<D6B4>.
// void RotateUpper(float fDegree);
// Ÿ<><C5B8> <20>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. Eterlib<69><62> SetAroundCamera<72><61> <20><><EFBFBD>ɰ<EFBFBD> <20><><EFBFBD><EFBFBD>...
// fPitchDegree<65><65> <20><><EFBFBD><EFBFBD>(0<><30>)<29>κ<EFBFBD><CEBA><EFBFBD> <20>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
// fRollDegree<65><65> Ÿ<><C5B8> <20>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD> <20>ð<EFBFBD><C3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>...
void RotateEyeAroundTarget(float fPitchDegree, float fRollDegree);
// <20><><EFBFBD><EFBFBD> <20>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20>߽<EFBFBD><DFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. Ÿ<><C5B8> <20><><EFBFBD><EFBFBD> <20>޶<EFBFBD><DEB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
void RotateEyeAroundPoint(const D3DXVECTOR3 & v3Point, float fPitchDegree, float fRollDegree);
protected:
void SetViewMatrix();
void CalculateRoll();
public:
float GetTargetHeight();
void SetTargetHeight(float fTarget);
bool isTerrainCollisionEnable() { return m_bProcessTerrainCollision; }
void SetTerrainCollision(bool bEnable) { m_bProcessTerrainCollision = bEnable; }
private:
void ProcessTerrainCollision();
void ProcessBuildingCollision();
private:
bool m_bProcessTerrainCollision;
static float CAMERA_MIN_DISTANCE;
static float CAMERA_MAX_DISTANCE;
};
typedef std::map<BYTE, CCamera *> TCameraMap;
class CCameraManager : public CSingleton<CCameraManager>
{
public:
enum ECameraNum
{
NO_CURRENT_CAMERA,
DEFAULT_PERSPECTIVE_CAMERA,
DEFAULT_ORTHO_CAMERA,
CAMERA_MAX = 255
};
CCameraManager();
virtual ~CCameraManager();
bool AddCamera(unsigned char ucCameraNum);
bool RemoveCamera(unsigned char ucCameraNum);
CCamera * GetCurrentCamera();
void SetCurrentCamera(unsigned char ucCameraNum);
void ResetToPreviousCamera();
bool isCurrentCamera(unsigned char ucCameraNum);
unsigned char GetCurrentCameraNum();
bool isTerrainCollisionEnable();
void SetTerrainCollision(bool bEnable);
private:
TCameraMap m_CameraMap;
CCamera * m_pCurrentCamera;
CCamera * m_pPreviousCamera;
};
#endif // !defined(AFX_CAMERA_H__C5D086BE_7A03_4246_9145_336747C47D9E__INCLUDED_)

View File

@ -0,0 +1,829 @@
#include "Stdafx.h"
#include "CollisionData.h"
#include "Pool.h"
#include "GrpScreen.h"
#include "GrpMath.h"
#include "lineintersect_utils.h"
#include "StateManager.h"
const float gc_fReduceMove = 0.5f;
//const float gc_fSlideMoveSpeed = 5.0f;
/*inline D3DXVECTOR3 FitAtSpecifiedLength(const D3DXVECTOR3 & v3Vector, float length)
{
D3DXVECTOR3 v;
D3DXVec3Normalize(&v,&v3Vector);
return v*length;
}
*/
CDynamicPool<CSphereCollisionInstance> gs_sci;
CDynamicPool<CCylinderCollisionInstance> gs_cci;
CDynamicPool<CPlaneCollisionInstance> gs_pci;
CDynamicPool<CAABBCollisionInstance> gs_aci;
CDynamicPool<COBBCollisionInstance> gs_oci;
void DestroyCollisionInstanceSystem()
{
gs_sci.Destroy();
gs_cci.Destroy();
gs_pci.Destroy();
gs_aci.Destroy();
gs_oci.Destroy();
}
/////////////////////////////////////////////
// Base
CBaseCollisionInstance * CBaseCollisionInstance::BuildCollisionInstance(const CStaticCollisionData * c_pCollisionData, const D3DXMATRIX * pMat)
{
switch(c_pCollisionData->dwType)
{
case COLLISION_TYPE_PLANE:
{
CPlaneCollisionInstance * ppci = gs_pci.Alloc();
D3DXMATRIX matRotation;
D3DXMATRIX matTranslationLocal;
D3DXMatrixRotationQuaternion(&matRotation, &c_pCollisionData->quatRotation);
D3DXMatrixTranslation(&matTranslationLocal, c_pCollisionData->v3Position.x, c_pCollisionData->v3Position.y, c_pCollisionData->v3Position.z);
D3DXMATRIX matTransform = matRotation * matTranslationLocal * *pMat;
TPlaneData & PlaneData = ppci->GetAttribute();
D3DXVec3TransformCoord(&PlaneData.v3Position, &c_pCollisionData->v3Position, pMat);
float fHalfWidth = c_pCollisionData->fDimensions[0] / 2.0f;
float fHalfLength = c_pCollisionData->fDimensions[1] / 2.0f;
PlaneData.v3QuadPosition[0].x = -fHalfWidth;
PlaneData.v3QuadPosition[0].y = -fHalfLength;
PlaneData.v3QuadPosition[0].z = 0.0f;
PlaneData.v3QuadPosition[1].x = +fHalfWidth;
PlaneData.v3QuadPosition[1].y = -fHalfLength;
PlaneData.v3QuadPosition[1].z = 0.0f;
PlaneData.v3QuadPosition[2].x = -fHalfWidth;
PlaneData.v3QuadPosition[2].y = +fHalfLength;
PlaneData.v3QuadPosition[2].z = 0.0f;
PlaneData.v3QuadPosition[3].x = +fHalfWidth;
PlaneData.v3QuadPosition[3].y = +fHalfLength;
PlaneData.v3QuadPosition[3].z = 0.0f;
for (DWORD i = 0; i < 4; ++i)
D3DXVec3TransformCoord(&PlaneData.v3QuadPosition[i], &PlaneData.v3QuadPosition[i], &matTransform);
D3DXVECTOR3 v3Line0 = PlaneData.v3QuadPosition[1] - PlaneData.v3QuadPosition[0];
D3DXVECTOR3 v3Line1 = PlaneData.v3QuadPosition[2] - PlaneData.v3QuadPosition[0];
D3DXVECTOR3 v3Line2 = PlaneData.v3QuadPosition[1] - PlaneData.v3QuadPosition[3];
D3DXVECTOR3 v3Line3 = PlaneData.v3QuadPosition[2] - PlaneData.v3QuadPosition[3];
D3DXVec3Normalize(&v3Line0, &v3Line0);
D3DXVec3Normalize(&v3Line1, &v3Line1);
D3DXVec3Normalize(&v3Line2, &v3Line2);
D3DXVec3Normalize(&v3Line3, &v3Line3);
D3DXVec3Cross(&PlaneData.v3Normal, &v3Line0, &v3Line1);
D3DXVec3Normalize(&PlaneData.v3Normal, &PlaneData.v3Normal);
D3DXVec3Cross(&PlaneData.v3InsideVector[0], &PlaneData.v3Normal, &v3Line0 );
D3DXVec3Cross(&PlaneData.v3InsideVector[1], &v3Line1, &PlaneData.v3Normal);
D3DXVec3Cross(&PlaneData.v3InsideVector[2], &v3Line2, &PlaneData.v3Normal);
D3DXVec3Cross(&PlaneData.v3InsideVector[3], &PlaneData.v3Normal, &v3Line3);
return ppci;
}
break;
case COLLISION_TYPE_BOX:
assert(false && "COLLISION_TYPE_BOX not implemented");
break;
case COLLISION_TYPE_AABB:
{
CAABBCollisionInstance * paci = gs_aci.Alloc();
D3DXMATRIX matTranslationLocal;
D3DXMatrixTranslation(&matTranslationLocal, c_pCollisionData->v3Position.x, c_pCollisionData->v3Position.y, c_pCollisionData->v3Position.z);
D3DXMATRIX matTransform = *pMat;
D3DXVECTOR3 v3Pos;
v3Pos.x = matTranslationLocal._41;
v3Pos.y = matTranslationLocal._42;
v3Pos.z = matTranslationLocal._43;
TAABBData & AABBData = paci->GetAttribute();
AABBData.v3Min.x = v3Pos.x - c_pCollisionData->fDimensions[0];
AABBData.v3Min.y = v3Pos.y - c_pCollisionData->fDimensions[1];
AABBData.v3Min.z = v3Pos.z - c_pCollisionData->fDimensions[2];
AABBData.v3Max.x = v3Pos.x + c_pCollisionData->fDimensions[0];
AABBData.v3Max.y = v3Pos.y + c_pCollisionData->fDimensions[1];
AABBData.v3Max.z = v3Pos.z + c_pCollisionData->fDimensions[2];
D3DXVec3TransformCoord(&AABBData.v3Min, &AABBData.v3Min, &matTransform);
D3DXVec3TransformCoord(&AABBData.v3Max, &AABBData.v3Max, &matTransform);
return paci;
}
break;
case COLLISION_TYPE_OBB:
{
COBBCollisionInstance * poci = gs_oci.Alloc();
D3DXMATRIX matTranslationLocal; D3DXMatrixTranslation(&matTranslationLocal, c_pCollisionData->v3Position.x, c_pCollisionData->v3Position.y, c_pCollisionData->v3Position.z);
D3DXMATRIX matRotation; D3DXMatrixRotationQuaternion(&matRotation, &c_pCollisionData->quatRotation);
D3DXMATRIX matTranslationWorld; D3DXMatrixIdentity(&matTranslationWorld);
matTranslationWorld._41 = pMat->_41; matTranslationWorld._42 = pMat->_42; matTranslationWorld._43 = pMat->_43; matTranslationWorld._44 = pMat->_44;
D3DXVECTOR3 v3Min, v3Max;
v3Min.x = c_pCollisionData->v3Position.x - c_pCollisionData->fDimensions[0];
v3Min.y = c_pCollisionData->v3Position.y - c_pCollisionData->fDimensions[1];
v3Min.z = c_pCollisionData->v3Position.z - c_pCollisionData->fDimensions[2];
v3Max.x = c_pCollisionData->v3Position.x + c_pCollisionData->fDimensions[0];
v3Max.y = c_pCollisionData->v3Position.y + c_pCollisionData->fDimensions[1];
v3Max.z = c_pCollisionData->v3Position.z + c_pCollisionData->fDimensions[2];
D3DXVec3TransformCoord(&v3Min, &v3Min, pMat);
D3DXVec3TransformCoord(&v3Max, &v3Max, pMat);
D3DXVECTOR3 v3Position = (v3Min + v3Max) * 0.5f;
TOBBData & OBBData = poci->GetAttribute();
OBBData.v3Min.x = v3Position.x - c_pCollisionData->fDimensions[0];
OBBData.v3Min.y = v3Position.y - c_pCollisionData->fDimensions[1];
OBBData.v3Min.z = v3Position.z - c_pCollisionData->fDimensions[2];
OBBData.v3Max.x = v3Position.x + c_pCollisionData->fDimensions[0];
OBBData.v3Max.y = v3Position.y + c_pCollisionData->fDimensions[1];
OBBData.v3Max.z = v3Position.z + c_pCollisionData->fDimensions[2];
D3DXMATRIX matTransform = *pMat;
D3DXMatrixIdentity(&OBBData.matRot); OBBData.matRot = *pMat;
OBBData.matRot._41 = 0; OBBData.matRot._42 = 0; OBBData.matRot._43 = 0; OBBData.matRot._44 = 1;
return poci;
}
break;
case COLLISION_TYPE_SPHERE:
{
CSphereCollisionInstance * psci = gs_sci.Alloc();
D3DXMATRIX matTranslationLocal;
D3DXMatrixTranslation(&matTranslationLocal, c_pCollisionData->v3Position.x, c_pCollisionData->v3Position.y, c_pCollisionData->v3Position.z);
matTranslationLocal = matTranslationLocal * *pMat;
TSphereData & SphereData = psci->GetAttribute();
SphereData.v3Position.x = matTranslationLocal._41;
SphereData.v3Position.y = matTranslationLocal._42;
SphereData.v3Position.z = matTranslationLocal._43;
SphereData.fRadius = c_pCollisionData->fDimensions[0];
return psci;
}
break;
case COLLISION_TYPE_CYLINDER:
{
CCylinderCollisionInstance * pcci = gs_cci.Alloc();
D3DXMATRIX matTranslationLocal;
D3DXMatrixTranslation(&matTranslationLocal, c_pCollisionData->v3Position.x, c_pCollisionData->v3Position.y, c_pCollisionData->v3Position.z);
matTranslationLocal = matTranslationLocal * *pMat;
TCylinderData & CylinderData = pcci->GetAttribute();
CylinderData.fRadius = c_pCollisionData->fDimensions[0];
CylinderData.fHeight = c_pCollisionData->fDimensions[1];
CylinderData.v3Position.x = matTranslationLocal._41;
CylinderData.v3Position.y = matTranslationLocal._42;
CylinderData.v3Position.z = matTranslationLocal._43 /*+ CylinderData.fHeight/2.0f*/;
return pcci;
}
break;
}
assert(false && "NOT_REACHED");
return 0;
}
void CBaseCollisionInstance::Destroy()
{
OnDestroy();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*------------------------------------------------------Sphere---------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TSphereData & CSphereCollisionInstance::GetAttribute()
{
return m_attribute;
}
const TSphereData & CSphereCollisionInstance::GetAttribute() const
{
return m_attribute;
}
void CSphereCollisionInstance::Render(D3DFILLMODE d3dFillMode)
{
static CScreen s;
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);
s.RenderSphere(NULL, m_attribute.v3Position.x, m_attribute.v3Position.y, m_attribute.v3Position.z, m_attribute.fRadius, d3dFillMode);
}
void CSphereCollisionInstance::OnDestroy()
{
gs_sci.Free(this);
}
bool CSphereCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
if (square_distance_between_linesegment_and_point(s.v3LastPosition,s.v3Position,m_attribute.v3Position) < (m_attribute.fRadius+s.fRadius)*(m_attribute.fRadius+s.fRadius))
{
// NOTE : <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. - [levites]
if (GetVector3Distance(s.v3Position, m_attribute.v3Position) <
GetVector3Distance(s.v3LastPosition, m_attribute.v3Position))
return true;
}
return false;
}
bool CSphereCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
//Tracef("OnCollisionDynamicSphere\n");
if (square_distance_between_linesegment_and_point(s.v3LastPosition,s.v3Position,m_attribute.v3Position)<(m_attribute.fRadius+s.fRadius)*(m_attribute.fRadius+s.fRadius))
{
return true;
}
return false;
}
D3DXVECTOR3 CSphereCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
if (D3DXVec3LengthSq(&(s.v3Position-m_attribute.v3Position))>=(s.fRadius+m_attribute.fRadius)*(m_attribute.fRadius+s.fRadius))
return D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &(s.v3Position-s.v3LastPosition), &D3DXVECTOR3(0.0f,0.0f,1.0f) );
float sum = - D3DXVec3Dot(&c,&(s.v3Position-m_attribute.v3Position));
float mul = (s.fRadius+m_attribute.fRadius)*(s.fRadius+m_attribute.fRadius)-D3DXVec3LengthSq(&(s.v3Position-m_attribute.v3Position));
if (sum*sum-4*mul<=0)
return D3DXVECTOR3(0.0f,0.0f,0.0f);
float sq = sqrt(sum*sum-4*mul);
float t1=-sum-sq, t2=-sum+sq;
t1*=0.5f;
t2*=0.5f;
if (fabs(t1)<=fabs(t2))
{
return (gc_fReduceMove*t1)*c;
}
else
return (gc_fReduceMove*t2)*c;
/*
D3DXVECTOR3 p1 = s.v3Position+t1*c;
D3DXVECTOR3 p2 = s.v3Position+t2*c;
if (D3DXVec3LengthSq(&(p2-s.v3Position))>D3DXVec3LengthSq(&(p1-s.v3Position)))
{
return p1-s.v3Position;
}
else
{
return p2-s.v3Position;
}
*/
}
/////////////////////////////////////////////
// Plane
TPlaneData & CPlaneCollisionInstance::GetAttribute()
{
return m_attribute;
}
const TPlaneData & CPlaneCollisionInstance::GetAttribute() const
{
return m_attribute;
}
bool CPlaneCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v3SpherePosition = s.v3Position - m_attribute.v3Position;
D3DXVECTOR3 v3SphereLastPosition = s.v3LastPosition - m_attribute.v3Position;
float fPosition1 = D3DXVec3Dot(&m_attribute.v3Normal, &v3SpherePosition);
float fPosition2 = D3DXVec3Dot(&m_attribute.v3Normal, &v3SphereLastPosition);
if (fPosition1 >0.0f && fPosition2 < 0.0f || fPosition1 <0.0f && fPosition2 >0.0f
|| (fPosition1) <= s.fRadius && fPosition1 >= -s.fRadius)
{
D3DXVECTOR3 v3QuadPosition1 = s.v3Position - m_attribute.v3QuadPosition[0];
D3DXVECTOR3 v3QuadPosition2 = s.v3Position - m_attribute.v3QuadPosition[3];
if (D3DXVec3Dot(&v3QuadPosition1, &m_attribute.v3InsideVector[0]) > - s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition1, &m_attribute.v3InsideVector[1]) > -s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition2, &m_attribute.v3InsideVector[2]) > - s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition2, &m_attribute.v3InsideVector[3]) > - s.fRadius/*0.0f*/)
{
// NOTE : <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. - [levites]
if (fabs(D3DXVec3Dot(&(s.v3Position - m_attribute.v3Position), &m_attribute.v3Normal)) <
fabs(D3DXVec3Dot(&(s.v3LastPosition - m_attribute.v3Position), &m_attribute.v3Normal)))
return true;
}
}
return false;
}
bool CPlaneCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
//Tracef("OnCollisionDynamicSphere\n");
D3DXVECTOR3 v3SpherePosition = s.v3Position - m_attribute.v3Position;
D3DXVECTOR3 v3SphereLastPosition = s.v3LastPosition - m_attribute.v3Position;
float fPosition1 = D3DXVec3Dot(&m_attribute.v3Normal, &v3SpherePosition);
float fPosition2 = D3DXVec3Dot(&m_attribute.v3Normal, &v3SphereLastPosition);
if (fPosition1 >0.0f && fPosition2 < 0.0f || fPosition1 <0.0f && fPosition2 >0.0f
|| (fPosition1) <= s.fRadius && fPosition1 >= -s.fRadius)
{
D3DXVECTOR3 v3QuadPosition1 = s.v3Position - m_attribute.v3QuadPosition[0];
D3DXVECTOR3 v3QuadPosition2 = s.v3Position - m_attribute.v3QuadPosition[3];
if (D3DXVec3Dot(&v3QuadPosition1, &m_attribute.v3InsideVector[0]) > - s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition1, &m_attribute.v3InsideVector[1]) > -s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition2, &m_attribute.v3InsideVector[2]) > - s.fRadius/*0.0f*/)
if (D3DXVec3Dot(&v3QuadPosition2, &m_attribute.v3InsideVector[3]) > - s.fRadius/*0.0f*/)
{
return true;
}
}
return false;
}
D3DXVECTOR3 CPlaneCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 advance = s.v3Position-s.v3LastPosition;
float d = D3DXVec3Dot(&m_attribute.v3Normal, &advance);
if (d>=-0.0001 && d<=0.0001)
return D3DXVECTOR3(0.0f,0.0f,0.0f);
float t= - D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position))/d;
//D3DXVECTOR3 onplane = s.v3Position+t*advance;
if (D3DXVec3Dot(&m_attribute.v3Normal, &advance)>=0)
{
//return m_attribute.v3Normal*((-s.fRadius+D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position)))*gc_fReduceMove);
return t*advance -s.fRadius*m_attribute.v3Normal;
}
else
{
//return m_attribute.v3Normal*((s.fRadius+D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position)))*gc_fReduceMove);
return t*advance +s.fRadius*m_attribute.v3Normal;
}
/*if (D3DXVec3Dot(&m_attribute.v3Normal, &advance)>=0)
{
Tracef("%f %f\n",s.fRadius,-(D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position))));
return m_attribute.v3Normal*((-s.fRadius+D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position)))*gc_fReduceMove);
}
else
{
Tracef("%f %f\n",(s.fRadius),(D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position))));
return m_attribute.v3Normal*((s.fRadius+D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position-m_attribute.v3Position)))*gc_fReduceMove);
}*/
/*
D3DXVECTOR3 advance = s.v3Position-s.v3LastPosition;
D3DXVECTOR3 slide(-advance.y,advance.x,advance.z);
slide = m_attribute.v3Normal;
D3DXVECTOR3 radius_adjust = advance;
D3DXVec3Normalize(&radius_adjust,&radius_adjust);
radius_adjust*=s.fRadius;
float d = D3DXVec3Dot(&m_attribute.v3Normal, &slide);
if (d>=-0.0001 && d<=0.0001)
return D3DXVECTOR3(0.0f,0.0f,0.0f);
float t= - D3DXVec3Dot(&m_attribute.v3Normal, &(s.v3Position+radius_adjust-m_attribute.v3Position))
/ d;*/
//D3DXVECTOR3 nextposition;
//nextposition = s.v3Position + t*slide;
//Tracef("$T %f",t);
//if (D3DXVec3Dot(&m_attribute.v3Normal, &advance)>=0)
// return (t*slide - m_attribute.v3Normal * s.fRadius)/**gc_fReduceMove*/;
//else
// return (t*slide + m_attribute.v3Normal * s.fRadius)/*gc_fReduceMove*/;
//if (D3DXVec3Dot(&m_attribute.v3Normal, &advance)>=0)
// return (t*slide + m_attribute.v3Normal * D3DXVec3Dot(&m_attribute.v3Normal,&(s.v3LastPosition-m_attribute.v3Position))/** s.fRadius*/)*gc_fReduceMove;
//else
// return (t*slide + m_attribute.v3Normal * D3DXVec3Dot(&m_attribute.v3Normal,&(s.v3LastPosition-m_attribute.v3Position))/*s.fRadius*/)*gc_fReduceMove;
//
}
void CPlaneCollisionInstance::Render(D3DFILLMODE /*d3dFillMode*/)
{
static CScreen s;
s.RenderBar3d(m_attribute.v3QuadPosition);
}
void CPlaneCollisionInstance::OnDestroy()
{
gs_pci.Free(this);
}
/////////////////////////////////////////////
// Cylinder
TCylinderData & CCylinderCollisionInstance::GetAttribute()
{
return m_attribute;
}
const TCylinderData & CCylinderCollisionInstance::GetAttribute() const
{
return m_attribute;
}
bool CCylinderCollisionInstance::CollideCylinderVSDynamicSphere(const TCylinderData & c_rattribute, const CDynamicSphereInstance & s) const
{
if (s.v3Position.z + s.fRadius < c_rattribute.v3Position.z)
return false;
if (s.v3Position.z - s.fRadius > c_rattribute.v3Position.z + c_rattribute.fHeight)
return false;
/*D3DXVECTOR2 v2curDistance(s.v3Position.x - c_rattribute.v3Position.x, s.v3Position.y - c_rattribute.v3Position.y);
float fDistance = D3DXVec2Length(&v2curDistance);
if (fDistance <= s.fRadius + c_rattribute.fRadius)
return true;
*/
D3DXVECTOR3 oa, ob;
IntersectLineSegments(c_rattribute.v3Position, D3DXVECTOR3(c_rattribute.v3Position.x,c_rattribute.v3Position.y,c_rattribute.v3Position.z+c_rattribute.fHeight), s.v3LastPosition, s.v3Position, oa, ob);
return (D3DXVec3LengthSq(&(oa-ob))<=(c_rattribute.fRadius+s.fRadius)*(c_rattribute.fRadius+s.fRadius));
}
bool CCylinderCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
if (CollideCylinderVSDynamicSphere(m_attribute, s))
{
// NOTE : <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. - [levites]
if (GetVector3Distance(s.v3Position, m_attribute.v3Position) <
GetVector3Distance(s.v3LastPosition, m_attribute.v3Position))
return true;
}
// NOTE : <20>̵<EFBFBD> <20>Ÿ<EFBFBD><C5B8><EFBFBD> Ŭ <20><><EFBFBD><EFBFBD> <20><>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD> (<28><> ũ<><C5A9> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) <20>̵<EFBFBD><CCB5>ϸ鼭 <20><><EFBFBD><EFBFBD> üũ <20><> <20><><EFBFBD><EFBFBD> - [levites]
D3DXVECTOR3 v3Distance = s.v3Position - s.v3LastPosition;
float fDistance = D3DXVec3Length(&v3Distance);
if (s.fRadius<=0.0001f)
return false;
if (fDistance >= s.fRadius*2.0f)
{
TCylinderData cylinder;
cylinder = m_attribute;
cylinder.v3Position = s.v3LastPosition;
int iStep = fDistance / s.fRadius*2.0f;
D3DXVECTOR3 v3Step = v3Distance / float(iStep);
for (int i = 0; i < iStep; ++i)
{
cylinder.v3Position += v3Step;
if (CollideCylinderVSDynamicSphere(cylinder, s))
return true;
}
}
return false;
}
bool CCylinderCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
//Tracef("OnCollisionDynamicSphere\n");
return (CollideCylinderVSDynamicSphere(m_attribute, s));
}
D3DXVECTOR3 CCylinderCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v3Position = m_attribute.v3Position;
v3Position.z = s.v3Position.z;
if (D3DXVec3LengthSq(&(s.v3Position-v3Position))>=(s.fRadius+m_attribute.fRadius)*(m_attribute.fRadius+s.fRadius))
return D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXVECTOR3 c;
D3DXVECTOR3 advance = s.v3Position - s.v3LastPosition;
advance.z = 0;
D3DXVec3Cross(&c, &advance, &D3DXVECTOR3(0.0f,0.0f,1.0f) );
float sum = - D3DXVec3Dot(&c,&(s.v3Position-v3Position));
float mul = (s.fRadius+m_attribute.fRadius)*(s.fRadius+m_attribute.fRadius)-D3DXVec3LengthSq(&(s.v3Position-v3Position));
if (sum*sum-4*mul<=0)
return D3DXVECTOR3(0.0f,0.0f,0.0f);
float sq = sqrt(sum*sum-4*mul);
float t1=-sum-sq, t2=-sum+sq;
t1*=0.5f;
t2*=0.5f;
if (fabs(t1)<=fabs(t2))
{
return (gc_fReduceMove*t1)*c;
}
else
return (gc_fReduceMove*t2)*c;
/*D3DXVECTOR3 p1 = s.v3Position+t1*c;
D3DXVECTOR3 p2 = s.v3Position+t2*c;
if (D3DXVec3LengthSq(&(p2-s.v3Position))>D3DXVec3LengthSq(&(p1-s.v3Position)))
{
return p1-s.v3Position;
}
else
{
return p2-s.v3Position;
}*/
}
void CCylinderCollisionInstance::Render(D3DFILLMODE d3dFillMode)
{
static CScreen s;
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);
s.RenderCylinder(NULL, m_attribute.v3Position.x, m_attribute.v3Position.y, m_attribute.v3Position.z+m_attribute.fHeight/2, m_attribute.fRadius, m_attribute.fHeight, d3dFillMode);
}
void CCylinderCollisionInstance::OnDestroy()
{
gs_cci.Free(this);
}
/////////////////////////////////////////////
// AABB (Aligned Axis Bounding Box)
TAABBData & CAABBCollisionInstance::GetAttribute()
{
return m_attribute;
}
const TAABBData & CAABBCollisionInstance::GetAttribute() const
{
return m_attribute;
}
bool CAABBCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v;
D3DXVECTOR3 v3center = (m_attribute.v3Min + m_attribute.v3Max) * 0.5f;
memcpy(&v, &s.v3Position, sizeof(D3DXVECTOR3));
if(v.x < m_attribute.v3Min.x) v.x = m_attribute.v3Min.x;
if(v.x > m_attribute.v3Max.x) v.x = m_attribute.v3Max.x;
if(v.y < m_attribute.v3Min.y) v.x = m_attribute.v3Min.y;
if(v.y > m_attribute.v3Max.y) v.x = m_attribute.v3Max.y;
if(v.z < m_attribute.v3Min.z) v.z = m_attribute.v3Min.z;
if(v.z > m_attribute.v3Max.z) v.z = m_attribute.v3Max.z;
if(GetVector3Distance(v, s.v3Position) <= s.fRadius * s.fRadius)
{
return true;
}
memcpy(&v, &s.v3LastPosition, sizeof(D3DXVECTOR3));
if(v.x < m_attribute.v3Min.x) v.x = m_attribute.v3Min.x;
if(v.x > m_attribute.v3Max.x) v.x = m_attribute.v3Max.x;
if(v.y < m_attribute.v3Min.y) v.x = m_attribute.v3Min.y;
if(v.y > m_attribute.v3Max.y) v.x = m_attribute.v3Max.y;
if(v.z < m_attribute.v3Min.z) v.z = m_attribute.v3Min.z;
if(v.z > m_attribute.v3Max.z) v.z = m_attribute.v3Max.z;
if(GetVector3Distance(v, s.v3LastPosition) <= s.fRadius * s.fRadius)
{
return true;
}
return false;
}
bool CAABBCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v;
memcpy(&v, &s.v3Position, sizeof(D3DXVECTOR3));
if(v.x < m_attribute.v3Min.x) v.x = m_attribute.v3Min.x;
if(v.x > m_attribute.v3Max.x) v.x = m_attribute.v3Max.x;
if(v.y < m_attribute.v3Min.y) v.x = m_attribute.v3Min.y;
if(v.y > m_attribute.v3Max.y) v.x = m_attribute.v3Max.y;
if(v.z < m_attribute.v3Min.z) v.z = m_attribute.v3Min.z;
if(v.z > m_attribute.v3Max.z) v.z = m_attribute.v3Max.z;
if(v.x > m_attribute.v3Min.x && v.x < m_attribute.v3Max.x &&
v.y > m_attribute.v3Min.y && v.y < m_attribute.v3Max.y &&
v.z > m_attribute.v3Min.z && v.z < m_attribute.v3Max.z) { return true; }
if(GetVector3Distance(v, s.v3Position) <= s.fRadius * s.fRadius) { return true; }
memcpy(&v, &s.v3LastPosition, sizeof(D3DXVECTOR3));
if(v.x < m_attribute.v3Min.x) v.x = m_attribute.v3Min.x;
if(v.x > m_attribute.v3Max.x) v.x = m_attribute.v3Max.x;
if(v.y < m_attribute.v3Min.y) v.x = m_attribute.v3Min.y;
if(v.y > m_attribute.v3Max.y) v.x = m_attribute.v3Max.y;
if(v.z < m_attribute.v3Min.z) v.z = m_attribute.v3Min.z;
if(v.z > m_attribute.v3Max.z) v.z = m_attribute.v3Max.z;
if(v.x > m_attribute.v3Min.x && v.x < m_attribute.v3Max.x &&
v.y > m_attribute.v3Min.y && v.y < m_attribute.v3Max.y &&
v.z > m_attribute.v3Min.z && v.z < m_attribute.v3Max.z) { return true; }
if(GetVector3Distance(v, s.v3LastPosition) <= s.fRadius * s.fRadius) { return true; }
return false;
}
D3DXVECTOR3 CAABBCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
//Tracef("OnGetCollisionMovementAdjust v3Min.x = %f, v3Max.x = %f\n", m_attribute.v3Min.x, m_attribute.v3Max.x);
/*
float fARadius = D3DXVec3Length(&(m_attribute.v3Min - m_attribute.v3Max));
if (D3DXVec3LengthSq(&(s.v3Position-(m_attribute.v3Max + m_attribute.v3Min)))>=(s.fRadius+fARadius)*(fARadius+s.fRadius))
return D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &(s.v3Position-s.v3LastPosition), &D3DXVECTOR3(0.0f,0.0f,1.0f) );
float sum = - D3DXVec3Dot(&c,&(s.v3Position-(m_attribute.v3Max + m_attribute.v3Min)));
float mul = (s.fRadius+fARadius)*(s.fRadius+fARadius)-D3DXVec3LengthSq(&(s.v3Position-(m_attribute.v3Max + m_attribute.v3Min)));
if (sum*sum-4*mul<=0)
return D3DXVECTOR3(0.0f,0.0f,0.0f);
float sq = sqrt(sum*sum-4*mul);
float t1=-sum-sq, t2=-sum+sq;
t1*=0.5f;
t2*=0.5f;
if (fabs(t1)<=fabs(t2))
{
return (gc_fReduceMove*t1)*c;
}
else
return (gc_fReduceMove*t2)*c;
*/
D3DXVECTOR3 v3Temp;
if(s.v3Position.x + s.fRadius <= m_attribute.v3Min.x) { v3Temp.x = m_attribute.v3Min.x; }
else if(s.v3Position.x - s.fRadius >= m_attribute.v3Max.x) { v3Temp.x = m_attribute.v3Max.x; }
else if(s.v3Position.x + s.fRadius >= m_attribute.v3Min.x && s.v3Position.x + s.fRadius <= m_attribute.v3Max.x) { v3Temp.x = s.v3Position.x + s.fRadius; }
else { v3Temp.x = s.v3Position.x - s.fRadius; }
if(s.v3Position.y + s.fRadius <= m_attribute.v3Min.y) { v3Temp.y = m_attribute.v3Min.y; }
else if(s.v3Position.y - s.fRadius >= m_attribute.v3Max.y) { v3Temp.y = m_attribute.v3Max.y; }
else if(s.v3Position.y + s.fRadius >= m_attribute.v3Min.y && s.v3Position.y + s.fRadius <= m_attribute.v3Max.y) { v3Temp.y = s.v3Position.y + s.fRadius; }
else { v3Temp.y = s.v3Position.y - s.fRadius; }
if(s.v3Position.z + s.fRadius <= m_attribute.v3Min.z) { v3Temp.z = m_attribute.v3Min.z; }
else if(s.v3Position.z - s.fRadius >= m_attribute.v3Max.z) { v3Temp.z = m_attribute.v3Max.z; }
else if(s.v3Position.z + s.fRadius >= m_attribute.v3Min.z && s.v3Position.z + s.fRadius <= m_attribute.v3Max.z) { v3Temp.z = s.v3Position.z + s.fRadius; }
else { v3Temp.z = s.v3Position.z - s.fRadius; }
if(D3DXVec3LengthSq(&(v3Temp - s.v3Position)) < s.fRadius * s.fRadius)
return D3DXVECTOR3(.0f, .0f, .0f);
return D3DXVECTOR3(.0f, .0f, .0f);
}
void CAABBCollisionInstance::Render(D3DFILLMODE d3dFillMode)
{
static CScreen s;
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);
s.RenderCube(m_attribute.v3Min.x, m_attribute.v3Min.y, m_attribute.v3Min.z, m_attribute.v3Max.x, m_attribute.v3Max.y, m_attribute.v3Max.z);
return;
}
void CAABBCollisionInstance::OnDestroy()
{
gs_aci.Free(this);
}
/////////////////////////////////////////////
// OBB
TOBBData & COBBCollisionInstance::GetAttribute()
{
return m_attribute;
}
const TOBBData & COBBCollisionInstance::GetAttribute() const
{
return m_attribute;
}
bool COBBCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v3Center = 0.5f * (m_attribute.v3Min + m_attribute.v3Max);
D3DXVECTOR3 v3Sphere = s.v3Position - v3Center;
D3DXVec3TransformCoord(&v3Sphere, &v3Sphere, &m_attribute.matRot);
v3Sphere = v3Sphere + v3Center;
D3DXVECTOR3 v3Point = v3Sphere;
if(v3Point.x < m_attribute.v3Min.x) { v3Point.x = m_attribute.v3Min.x; }
if(v3Point.x > m_attribute.v3Max.x) { v3Point.x = m_attribute.v3Max.x; }
if(v3Point.y < m_attribute.v3Min.y) { v3Point.y = m_attribute.v3Min.y; }
if(v3Point.y > m_attribute.v3Max.y) { v3Point.y = m_attribute.v3Max.y; }
if(v3Point.z < m_attribute.v3Min.z) { v3Point.z = m_attribute.v3Min.z; }
if(v3Point.z > m_attribute.v3Max.z) { v3Point.z = m_attribute.v3Max.z; }
if(GetVector3Distance(v3Point, v3Sphere) <= s.fRadius * s.fRadius) { return true; }
v3Sphere = s.v3LastPosition - v3Center;
D3DXVec3TransformCoord(&v3Sphere, &v3Sphere, &m_attribute.matRot);
v3Sphere = v3Sphere + v3Center;
v3Point = v3Sphere;
if(v3Point.x < m_attribute.v3Min.x) { v3Point.x = m_attribute.v3Min.x; }
if(v3Point.x > m_attribute.v3Max.x) { v3Point.x = m_attribute.v3Max.x; }
if(v3Point.y < m_attribute.v3Min.y) { v3Point.y = m_attribute.v3Min.y; }
if(v3Point.y > m_attribute.v3Max.y) { v3Point.y = m_attribute.v3Max.y; }
if(v3Point.z < m_attribute.v3Min.z) { v3Point.z = m_attribute.v3Min.z; }
if(v3Point.z > m_attribute.v3Max.z) { v3Point.z = m_attribute.v3Max.z; }
if(GetVector3Distance(v3Point, v3Sphere) <= s.fRadius * s.fRadius) { return true; }
return false;
}
bool COBBCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
D3DXVECTOR3 v3Center = 0.5f * (m_attribute.v3Min + m_attribute.v3Max);
D3DXVECTOR3 v3Sphere = s.v3Position - v3Center;
D3DXVec3TransformCoord(&v3Sphere, &v3Sphere, &m_attribute.matRot);
v3Sphere = v3Sphere + v3Center;
D3DXVECTOR3 v3Point = v3Sphere;
if(v3Point.x < m_attribute.v3Min.x) { v3Point.x = m_attribute.v3Min.x; }
if(v3Point.x > m_attribute.v3Max.x) { v3Point.x = m_attribute.v3Max.x; }
if(v3Point.y < m_attribute.v3Min.y) { v3Point.y = m_attribute.v3Min.y; }
if(v3Point.y > m_attribute.v3Max.y) { v3Point.y = m_attribute.v3Max.y; }
if(v3Point.z < m_attribute.v3Min.z) { v3Point.z = m_attribute.v3Min.z; }
if(v3Point.z > m_attribute.v3Max.z) { v3Point.z = m_attribute.v3Max.z; }
if(GetVector3Distance(v3Point, v3Sphere) <= s.fRadius * s.fRadius) { return true; }
v3Sphere = s.v3LastPosition - v3Center;
D3DXVec3TransformCoord(&v3Sphere, &v3Sphere, &m_attribute.matRot);
v3Sphere = v3Sphere + v3Center;
v3Point = v3Sphere;
if(v3Point.x < m_attribute.v3Min.x) { v3Point.x = m_attribute.v3Min.x; }
if(v3Point.x > m_attribute.v3Max.x) { v3Point.x = m_attribute.v3Max.x; }
if(v3Point.y < m_attribute.v3Min.y) { v3Point.y = m_attribute.v3Min.y; }
if(v3Point.y > m_attribute.v3Max.y) { v3Point.y = m_attribute.v3Max.y; }
if(v3Point.z < m_attribute.v3Min.z) { v3Point.z = m_attribute.v3Min.z; }
if(v3Point.z > m_attribute.v3Max.z) { v3Point.z = m_attribute.v3Max.z; }
if(GetVector3Distance(v3Point, v3Sphere) <= s.fRadius * s.fRadius) { return true; }
return false;
}
D3DXVECTOR3 COBBCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
return D3DXVECTOR3(.0f, .0f, .0f);
}
void COBBCollisionInstance::Render(D3DFILLMODE d3dFillMode)
{
static CScreen s;
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);
s.RenderCube(m_attribute.v3Min.x, m_attribute.v3Min.y, m_attribute.v3Min.z, m_attribute.v3Max.x, m_attribute.v3Max.y, m_attribute.v3Max.z, m_attribute.matRot);
return;
}
void COBBCollisionInstance::OnDestroy()
{
gs_oci.Free(this);
}

206
src/EterLib/CollisionData.h Normal file
View File

@ -0,0 +1,206 @@
#pragma once
// Collision Detection
typedef struct SSphereData
{
D3DXVECTOR3 v3Position;
float fRadius;
} TSphereData;
typedef struct SPlaneData
{
D3DXVECTOR3 v3Position;
D3DXVECTOR3 v3Normal;
D3DXVECTOR3 v3QuadPosition[4];
D3DXVECTOR3 v3InsideVector[4];
} TPlaneData;
typedef struct SAABBData
{
D3DXVECTOR3 v3Min;
D3DXVECTOR3 v3Max;
} TAABBData;
typedef struct SOBBData
{
D3DXVECTOR3 v3Min;
D3DXVECTOR3 v3Max;
D3DXMATRIX matRot;
} TOBBData;
typedef struct SCylinderData
{
D3DXVECTOR3 v3Position;
float fRadius;
float fHeight;
} TCylinderData;
enum ECollisionType
{
COLLISION_TYPE_PLANE,
COLLISION_TYPE_BOX,
COLLISION_TYPE_SPHERE,
COLLISION_TYPE_CYLINDER,
COLLISION_TYPE_AABB,
COLLISION_TYPE_OBB,
};
struct CDynamicSphereInstance
{
D3DXVECTOR3 v3Position;
D3DXVECTOR3 v3LastPosition;
float fRadius;
};
class CStaticCollisionData
{
public:
DWORD dwType;
char szName[32+1];
D3DXVECTOR3 v3Position;
float fDimensions[3];
D3DXQUATERNION quatRotation;
};
void DestroyCollisionInstanceSystem();
typedef std::vector<CStaticCollisionData> CStaticCollisionDataVector;
/////////////////////////////////////////////
// Base
class CBaseCollisionInstance
{
public:
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID) = 0;
bool MovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
return OnMovementCollisionDynamicSphere(s);
}
bool CollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
return OnCollisionDynamicSphere(s);
}
D3DXVECTOR3 GetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
return OnGetCollisionMovementAdjust(s);
}
void Destroy();
static CBaseCollisionInstance * BuildCollisionInstance(const CStaticCollisionData * c_pCollisionData, const D3DXMATRIX * pMat);
protected:
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const = 0;
virtual bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const = 0;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const = 0;
virtual void OnDestroy() = 0;
};
/////////////////////////////////////////////
// Sphere
class CSphereCollisionInstance : public CBaseCollisionInstance
{
public:
TSphereData & GetAttribute();
const TSphereData & GetAttribute() const;
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
protected:
void OnDestroy();
bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
protected:
TSphereData m_attribute;
};
/////////////////////////////////////////////
// Plane
class CPlaneCollisionInstance : public CBaseCollisionInstance
{
public:
TPlaneData & GetAttribute();
const TPlaneData & GetAttribute() const;
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
protected:
void OnDestroy();
bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
protected:
TPlaneData m_attribute;
};
/////////////////////////////////////////////
// AABB (Aligned Axis Bounding Box)
class CAABBCollisionInstance : public CBaseCollisionInstance
{
public:
TAABBData & GetAttribute();
const TAABBData & GetAttribute() const;
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
protected:
void OnDestroy();
bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
protected:
TAABBData m_attribute;
};
/////////////////////////////////////////////
// OBB
class COBBCollisionInstance : public CBaseCollisionInstance
{
public:
TOBBData & GetAttribute();
const TOBBData & GetAttribute() const;
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
protected:
void OnDestroy();
bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
protected:
TOBBData m_attribute;
};
/////////////////////////////////////////////
// Cylinder
class CCylinderCollisionInstance : public CBaseCollisionInstance
{
public:
TCylinderData & GetAttribute();
const TCylinderData & GetAttribute() const;
virtual void Render(D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
protected:
void OnDestroy();
bool OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual bool OnCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
virtual D3DXVECTOR3 OnGetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
bool CollideCylinderVSDynamicSphere(const TCylinderData & c_rattribute, const CDynamicSphereInstance & s) const;
protected:
TCylinderData m_attribute;
};
typedef std::vector<CSphereCollisionInstance> CSphereCollisionInstanceVector;
typedef std::vector<CDynamicSphereInstance> CDynamicSphereInstanceVector;
typedef std::vector<CBaseCollisionInstance*> CCollisionInstanceVector;

View File

@ -0,0 +1,104 @@
#include "StdAfx.h"
#include "ColorTransitionHelper.h"
void CColorTransitionHelper::Clear(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha)
{
m_fSrcRed = c_rfRed;
m_fSrcGreen = c_rfGreen;
m_fSrcBlue = c_rfBlue;
m_fSrcAlpha = c_rfAlpha;
m_fDstRed = c_rfRed;
m_fDstGreen = c_rfGreen;
m_fDstBlue = c_rfBlue;
m_fDstAlpha = c_rfAlpha;
m_dwCurColor = 0x00000000;
m_dwStartTime = m_dwDuration = 0;
}
void CColorTransitionHelper::SetSrcColor(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha)
{
m_fSrcRed = c_rfRed;
m_fSrcGreen = c_rfGreen;
m_fSrcBlue = c_rfBlue;
m_fSrcAlpha = c_rfAlpha;
}
void CColorTransitionHelper::SetTransition(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha,
const DWORD & dwDuration)
{
m_fDstRed = c_rfRed;
m_fDstGreen = c_rfGreen;
m_fDstBlue = c_rfBlue;
m_fDstAlpha = c_rfAlpha;
m_dwDuration = dwDuration;
}
void CColorTransitionHelper::StartTransition()
{
m_bTransitionStarted = true;
m_dwStartTime = GetCurrentTime();
}
bool CColorTransitionHelper::Update()
{
// if (!m_bTransitionStarted)
// return false;
DWORD dwCurTime = GetCurrentTime();
DWORD dwElapsedTime = dwCurTime - m_dwStartTime;
float fpercent = (float)(dwElapsedTime) / (float)(m_dwDuration);
if (fpercent <= 0.0f)
fpercent = 0.0f;
if (fpercent >= 1.0f)
fpercent = 1.0f;
float fCurRed, fCurGreen, fCurBlue, fCurAlpha;
fCurRed = m_fSrcRed + (m_fDstRed - m_fSrcRed) * fpercent;
fCurGreen = m_fSrcGreen + (m_fDstGreen - m_fSrcGreen) * fpercent;
fCurBlue = m_fSrcBlue + (m_fDstBlue - m_fSrcBlue) * fpercent;
fCurAlpha = m_fSrcAlpha + (m_fDstAlpha - m_fSrcAlpha) * fpercent;
// Tracef("%f, %f, %f, %f\n", fCurRed, fCurGreen, fCurBlue, fCurAlpha);
m_dwCurColor = (((DWORD)(fCurAlpha * 255.0f)&0xff)<< 24) |
(((DWORD)(fCurRed * 255.0f)&0xff) << 16) |
(((DWORD)(fCurGreen * 255.0f)&0xff) << 8) |
((DWORD)(fCurBlue * 255.0f)&0xff);
if ( (1.0f == fpercent) && (fCurAlpha == m_fDstAlpha) && (fCurRed == m_fDstRed) && (fCurGreen == m_fDstGreen) && (fCurBlue == m_fDstBlue) )
{
m_bTransitionStarted = false;
return false;
}
return true;
}
const D3DCOLOR & CColorTransitionHelper::GetCurColor()
{
return m_dwCurColor;
}
CColorTransitionHelper::CColorTransitionHelper():m_bTransitionStarted(false)
{
Clear(0.0f, 0.0f, 0.0f, 0.0f);
}
CColorTransitionHelper::~CColorTransitionHelper()
{
Clear(0.0f, 0.0f, 0.0f, 0.0f);
}

View File

@ -0,0 +1,39 @@
#pragma once
class CColorTransitionHelper
{
public:
CColorTransitionHelper();
~CColorTransitionHelper();
void Clear(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha);
void SetSrcColor(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha);
void SetTransition(const float & c_rfRed,
const float & c_rfGreen,
const float & c_rfBlue,
const float & c_rfAlpha,
const DWORD & dwDuration);
const D3DCOLOR & GetCurColor();// { return m_dwCurColor; }
void StartTransition();
bool Update();
bool isTransitionStarted() { return m_bTransitionStarted; }
private:
D3DCOLOR m_dwCurColor; // <20><><EFBFBD><EFBFBD> <20><>
DWORD m_dwStartTime; // <20>ٲ<EFBFBD><D9B2><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ð<EFBFBD>
DWORD m_dwDuration; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ȿ<EFBFBD> <20>ٲ<EFBFBD><D9B2>°<EFBFBD>?
bool m_bTransitionStarted;
float m_fSrcRed, m_fSrcGreen, m_fSrcBlue, m_fSrcAlpha;
float m_fDstRed, m_fDstGreen, m_fDstBlue, m_fDstAlpha;
};

View File

@ -0,0 +1,176 @@
#include "StdAfx.h"
#include "CullingManager.h"
#include "GrpObjectInstance.h"
//#define COUNT_SHOWING_SPHERE
#ifdef COUNT_SHOWING_SPHERE
int showingcount = 0;
#endif
void CCullingManager::RayTraceCallback(const Vector3d &/*p1*/, // source pos of ray
const Vector3d &/*dir*/, // dest pos of ray
float distance,
const Vector3d &/*sect*/,
SpherePack *sphere)
{
//if (state!=VS_OUTSIDE)
//{
if (m_RayFarDistance<=0.0f || m_RayFarDistance>=distance)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("CCullingManager::RayTraceCallback");
#endif
m_list.push_back((CGraphicObjectInstance *)sphere->GetUserData());
}
//f((CGraphicObjectInstance *)sphere->GetUserData());
//}
}
void CCullingManager::VisibilityCallback(const Frustum &/*f*/,SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("CCullingManager::VisibilityCallback");
#endif
CGraphicObjectInstance * pInstance = (CGraphicObjectInstance*)sphere->GetUserData();
/*if (state == VS_PARTIAL)
{
Vector3d v;
float r;
pInstance->GetBoundingSphere(v,r);
state = f.ViewVolumeTest(v,r);
}*/
if (state == VS_OUTSIDE)
{
#ifdef COUNT_SHOWING_SPHERE
if (pInstance->isShow())
{
Tracef("SH : %p ",sphere->GetUserData());
showingcount--;
Tracef("show size : %5d\n",showingcount);
}
#endif
pInstance->Hide();
}
else
{
#ifdef COUNT_SHOWING_SPHERE
if (!pInstance->isShow())
{
Tracef("HS : %p ",sphere->GetUserData());
showingcount++;
Tracef("show size : %5d\n",showingcount);
}
#endif
pInstance->Show();
}
}
void CCullingManager::RangeTestCallback(const Vector3d &/*p*/,float /*distance*/,SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("CCullingManager::RangeTestCallback");
#endif
if (state!=VS_OUTSIDE)
{
m_list.push_back((CGraphicObjectInstance *)sphere->GetUserData());
//f((CGraphicObjectInstance *)sphere->GetUserData());
}
//assert(false && "NOT REACHED");
}
void CCullingManager::Reset()
{
m_Factory->Reset();
}
void CCullingManager::Update()
{
// TODO : update each object
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϰ<EFBFBD> <20>غ<EFBFBD><D8BA><EFBFBD>
//DWORD time = ELTimer_GetMSec();
//Reset();
m_Factory->Process();
//Tracef("cull update : %3d ",ELTimer_GetMSec()-time);
}
void CCullingManager::Process()
{
//DWORD time = ELTimer_GetMSec();
//Frustum f;
UpdateViewMatrix();
UpdateProjMatrix();
BuildViewFrustum();
m_Factory->FrustumTest(GetFrustum(), this);
//Tracef("cull process : %3d ",ELTimer_GetMSec()-time);
}
CCullingManager::CullingHandle CCullingManager::Register(CGraphicObjectInstance * obj)
{
assert(obj);
#ifdef COUNT_SHOWING_SPHERE
Tracef("CR : %p ",obj);
showingcount++;
Tracef("show size : %5d\n",showingcount);
#endif
Vector3d center;
float radius;
obj->GetBoundingSphere(center,radius);
return m_Factory->AddSphere_(center,radius,obj, false);
}
void CCullingManager::Unregister(CullingHandle h)
{
#ifdef COUNT_SHOWING_SPHERE
if (((CGraphicObjectInstance*)h->GetUserData())->isShow())
{
Tracef("DE : %p ",h->GetUserData());
showingcount--;
Tracef("show size : %5d\n",showingcount);
}
#endif
m_Factory->Remove(h);
}
CCullingManager::CCullingManager()
{
m_Factory = new SpherePackFactory(
10000, // maximum count
6400, // root radius
1600, // leaf radius
400 // extra radius
);
}
CCullingManager::~CCullingManager()
{
delete m_Factory;
}
void CCullingManager::FindRange(const Vector3d &p, float radius)
{
m_list.clear();
m_Factory->RangeTest(p, radius, this);
}
void CCullingManager::FindRay(const Vector3d &p1, const Vector3d &dir)
{
m_RayFarDistance = -1;
m_list.clear();
m_Factory->RayTrace(p1,dir,this);
}
void CCullingManager::FindRayDistance(const Vector3d &p1, const Vector3d &dir, float distance)
{
m_RayFarDistance = distance;
m_list.clear();
m_Factory->RayTrace(p1,dir,this);
}

View File

@ -0,0 +1,149 @@
#pragma once
#include "GrpScreen.h"
#include "../eterbase/Singleton.h"
#include "../SphereLib/spherepack.h"
class CGraphicObjectInstance;
template <class T>
struct RangeTester : public SpherePackCallback
{
T * f;
float dist;
RangeTester(T * fn, float distance=-1)
: f(fn), dist(distance)
{}
virtual ~RangeTester()
{}
virtual void RayTraceCallback(const Vector3d &p1, // source pos of ray
const Vector3d &dir, // dest pos of ray
float distance,
const Vector3d &sect,
SpherePack *sphere)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::RayTraceCallback");
#endif
if (dist<=0.0f || dist>=distance)
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
};
virtual void VisibilityCallback(const Frustum &f,SpherePack *sphere,ViewState state){};
virtual void RangeTestCallback(const Vector3d &p,float distance,SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::RangeTestCallback");
#endif
if (state!=VS_OUTSIDE)
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
}
virtual void PointTest2dCallback(const Vector3d &p, SpherePack *sphere,ViewState state)
{
#ifdef SPHERELIB_STRICT
if (sphere->IS_SPHERE)
puts("RangeTester::PointTest2dCallback");
#endif
if (state!=VS_OUTSIDE)
{
#ifdef SPHERELIB_STRICT
puts("FIND!!");
#endif
(*f)((CGraphicObjectInstance *)sphere->GetUserData());
}
}
};
class CCullingManager : public CSingleton<CCullingManager>, public SpherePackCallback, private CScreen
{
public:
typedef SpherePack * CullingHandle;
typedef std::vector<CGraphicObjectInstance *> TRangeList;
CCullingManager();
virtual ~CCullingManager();
virtual void RayTraceCallback(const Vector3d &p1, // source pos of ray
const Vector3d &dir, // dest pos of ray
float distance,
const Vector3d &sect,
SpherePack *sphere);
virtual void VisibilityCallback(const Frustum &f,SpherePack *sphere,ViewState state);
void RangeTestCallback(const Vector3d &p,float distance,SpherePack *sphere,ViewState state);
void Reset();
void Update();
void Process();
void FindRange(const Vector3d &p, float radius);
void FindRay(const Vector3d &p1, const Vector3d &dir);
void FindRayDistance(const Vector3d &p1, const Vector3d &dir, float distance);
void RangeTest(const Vector3d& p, float radius, SpherePackCallback* callback)
{
m_Factory->RangeTest(p, radius, callback);
}
void PointTest2d(const Vector3d& p, SpherePackCallback* callback)
{
m_Factory->PointTest2d(p, callback);
}
template <class T>
void ForInRange2d(const Vector3d& p, T* pFunc)
{
RangeTester<T> r(pFunc);
m_Factory->PointTest2d(p, &r);
}
template <class T>
void ForInRange(const Vector3d &p, float radius, T* pFunc)
{
RangeTester<T> r(pFunc);
m_Factory->RangeTest(p, radius, &r/*this*/);
}
template <class T>
void ForInRay(const Vector3d &p1, const Vector3d &dir, T* pFunc)
{
RangeTester<T> r(pFunc);
/*Vector3d p2;
//p2.Set(p.x+(dir.x*50000.0f),p.y+(dir.y*50000.0f),p.z+(dir.z*50000.0f));
p2.x = p.x+50000.0f*dir.x;
p2.y = p.y+50000.0f*dir.y;
p2.z = p.z+50000.0f*dir.z;
// p + (50000.0f*dir);//(p.x+(dir.x*50000.0f),p.y+(dir.y*50000.0f),p.z+(dir.z*50000.0f));*/
m_Factory->RayTrace(p1, dir, &r/*this*/);
}
template <class T>
void ForInRayDistance(const Vector3d &p, const Vector3d &dir, float distance, T* pFunc)
{
RangeTester<T> r(pFunc, distance);
m_Factory->RayTrace(p, dir, &r/*this*/);
}
CullingHandle Register(CGraphicObjectInstance * ob);
void Unregister(CullingHandle h);
TRangeList::iterator begin() { return m_list.begin(); }
TRangeList::iterator end() { return m_list.end(); }
protected:
TRangeList m_list;
float m_RayFarDistance;
SpherePackFactory * m_Factory;
};

285
src/EterLib/Decal.cpp Normal file
View File

@ -0,0 +1,285 @@
// Decal.cpp: implementation of the CDecal class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Decal.h"
#include "StateManager.h"
//////////////////////////////////////////////////////////////////////
// CDecal
//////////////////////////////////////////////////////////////////////
CDecal::CDecal():m_cfDecalEpsilon(0.25f)
{
Clear();
}
CDecal::~CDecal()
{
Clear();
}
void CDecal::Clear()
{
m_v3Center = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
m_v3Normal = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
m_v4LeftPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_v4RightPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_v4TopPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_v4BottomPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_v4FrontPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_v4BackPlane = D3DXPLANE(0.0f, 0.0f, 0.0f, 0.0f);
m_dwVertexCount = 0;
m_dwPrimitiveCount = 0;
m_TriangleFanStructVector.clear();
memset(m_Vertices, 0, sizeof(m_Vertices));
memset(m_Indices, 0, sizeof(m_Indices));
}
void CDecal::ClipMesh(DWORD dwPrimitiveCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 *c_pv3Normal)
{
D3DXVECTOR3 v3NewVertex[9];
D3DXVECTOR3 v3NewNormal[9];
// Clip one triangle at a time
for(DWORD dwi = 0; dwi < dwPrimitiveCount; ++dwi)
{
const D3DXVECTOR3 & v3_1 = c_pv3Vertex[3 * dwi];
const D3DXVECTOR3 & v3_2 = c_pv3Vertex[3 * dwi + 1];
const D3DXVECTOR3 & v3_3 = c_pv3Vertex[3 * dwi + 2];
D3DXVECTOR3 v3Cross;
D3DXVec3Cross(&v3Cross, &(v3_2 - v3_1), &(v3_3 - v3_1));
if (D3DXVec3Dot(&m_v3Normal, &v3Cross) > ( m_cfDecalEpsilon ) * D3DXVec3Length(&v3Cross))
{
v3NewVertex[0] = v3_1;
v3NewVertex[1] = v3_2;
v3NewVertex[2] = v3_3;
v3NewNormal[0] = c_pv3Normal[3 * dwi];
v3NewNormal[1] = c_pv3Normal[3 * dwi + 1];
v3NewNormal[2] = c_pv3Normal[3 * dwi + 2];
DWORD dwCount = ClipPolygon(3, v3NewVertex, v3NewNormal, v3NewVertex, v3NewNormal);
if ((dwCount != 0) && (!AddPolygon(dwCount, v3NewVertex, v3NewNormal))) break;
}
}
}
bool CDecal::AddPolygon(DWORD dwAddCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 * /*c_pv3Normal */)
{
if (m_dwVertexCount + dwAddCount >= MAX_DECAL_VERTICES)
return false;
TTRIANGLEFANSTRUCT aTriangleFanStruct;
aTriangleFanStruct.m_wMinIndex = m_dwVertexCount;
aTriangleFanStruct.m_dwVertexCount = dwAddCount;
aTriangleFanStruct.m_dwPrimitiveCount = dwAddCount - 2;
aTriangleFanStruct.m_dwVBOffset = m_dwVertexCount;
m_TriangleFanStructVector.push_back(aTriangleFanStruct);
DWORD dwCount = m_dwVertexCount;
// Add polygon as a triangle fan
WORD * wIndex = m_Indices + dwCount;
m_dwPrimitiveCount += dwAddCount - 2;
//float fOne_over_1MinusDecalEpsilon = 1.0f / (1.0f - m_cfDecalEpsilon);
// Assign vertex colors
for (DWORD dwVertexNum = 0; dwVertexNum < dwAddCount; ++dwVertexNum)
{
*wIndex++ = (WORD) dwCount;
m_Vertices[dwCount].position = c_pv3Vertex[dwVertexNum];
//const D3DXVECTOR3 & v3Normal = c_pv3Normal[dwVertexNum];
//float fAlpha = (D3DXVec3Dot(&m_v3Normal, &v3Normal) / D3DXVec3Length(&v3Normal) - m_cfDecalEpsilon) * fOne_over_1MinusDecalEpsilon;
//m_Vertices[dwCount].diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, (fAlpha > 0.0f) ? fAlpha : 0.0f);
m_Vertices[dwCount].diffuse = 0xFFFFFFFF;
++dwCount;
}
m_dwVertexCount = dwCount;
return true;
}
DWORD CDecal::ClipPolygon(DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal) const
{
D3DXVECTOR3 v3TempVertex[9];
D3DXVECTOR3 v3TempNormal[9];
// Clip against all six planes
DWORD dwCount = ClipPolygonAgainstPlane(m_v4LeftPlane, dwVertexCount, c_pv3Vertex, c_pv3Normal, v3TempVertex, v3TempNormal);
if (dwCount != 0)
{
dwCount = ClipPolygonAgainstPlane(m_v4RightPlane, dwCount, v3TempVertex, v3TempNormal, c_pv3NewVertex, c_pv3NewNormal);
if (dwCount != 0)
{
dwCount = ClipPolygonAgainstPlane(m_v4BottomPlane, dwCount, c_pv3NewVertex, c_pv3NewNormal, v3TempVertex, v3TempNormal);
if (dwCount != 0)
{
dwCount = ClipPolygonAgainstPlane(m_v4TopPlane, dwCount, v3TempVertex, v3TempNormal, c_pv3NewVertex, c_pv3NewNormal);
if (dwCount != 0)
{
dwCount = ClipPolygonAgainstPlane(m_v4BackPlane, dwCount, c_pv3NewVertex, c_pv3NewNormal, v3TempVertex, v3TempNormal);
if (dwCount != 0)
{
dwCount = ClipPolygonAgainstPlane(m_v4FrontPlane, dwCount, v3TempVertex, v3TempNormal, c_pv3NewVertex, c_pv3NewNormal);
}
}
}
}
}
return dwCount;
}
DWORD CDecal::ClipPolygonAgainstPlane(const D3DXPLANE& c_rv4Plane,
DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal)
{
bool bNegative[10];
// Classify vertices
DWORD dwNegativeCount = 0;
for (DWORD dwi = 0; dwi < dwVertexCount; ++dwi)
{
bool bNeg = (D3DXPlaneDotCoord(&c_rv4Plane, &c_pv3Vertex[dwi]) < 0.0F);
bNegative[dwi] = bNeg;
dwNegativeCount += bNeg;
}
// Discard this polygon if it's completely culled
if (dwNegativeCount == dwVertexCount)
return 0;
DWORD dwCount = 0;
for (DWORD dwCurIndex = 0; dwCurIndex < dwVertexCount; ++dwCurIndex)
{
// dwPrevIndex is the index of the previous vertex
DWORD dwPrevIndex = (dwCurIndex != 0) ? dwCurIndex - 1 : dwVertexCount - 1;
if (bNegative[dwCurIndex])
{
if (!bNegative[dwPrevIndex])
{
// Current vertex is on negative side of plane,
// but previous vertex is on positive side.
const D3DXVECTOR3& v3_1 = c_pv3Vertex[dwPrevIndex];
const D3DXVECTOR3& v3_2 = c_pv3Vertex[dwCurIndex];
float ft = D3DXPlaneDotCoord(&c_rv4Plane, &v3_1) / (c_rv4Plane.a * (v3_1.x - v3_2.x) + c_rv4Plane.b * (v3_1.y - v3_2.y) + c_rv4Plane.c * (v3_1.z - v3_2.z));
c_pv3NewVertex[dwCount] = v3_1 * (1.0f - ft) + v3_2 * ft;
const D3DXVECTOR3& v3_n1 = c_pv3Normal[dwPrevIndex];
const D3DXVECTOR3& v3_n2 = c_pv3Normal[dwCurIndex];
c_pv3NewNormal[dwCount] = v3_n1 * (1.0f - ft) + v3_n2 * ft;
++dwCount;
}
}
else
{
if (bNegative[dwPrevIndex])
{
// Current vertex is on positive side of plane,
// but previous vertex is on negative side.
const D3DXVECTOR3& v3_1 = c_pv3Vertex[dwCurIndex];
const D3DXVECTOR3& v3_2 = c_pv3Vertex[dwPrevIndex];
float ft = D3DXPlaneDotCoord(&c_rv4Plane, &v3_1) / (c_rv4Plane.a * (v3_1.x - v3_2.x) + c_rv4Plane.b * (v3_1.y - v3_2.y) + c_rv4Plane.c * (v3_1.z - v3_2.z));
c_pv3NewVertex[dwCount] = v3_1 * (1.0f - ft) + v3_2 * ft;
const D3DXVECTOR3& v3_n1 = c_pv3Normal[dwCurIndex];
const D3DXVECTOR3& v3_n2 = c_pv3Normal[dwPrevIndex];
c_pv3NewNormal[dwCount] = v3_n1 * (1.0f - ft) + v3_n2 * ft;
++dwCount;
}
// Include current vertex
c_pv3NewVertex[dwCount] = c_pv3Vertex[dwCurIndex];
c_pv3NewNormal[dwCount] = c_pv3Normal[dwCurIndex];
++dwCount;
}
}
// Return number of vertices in clipped polygon
return dwCount;
}
/*
void CDecal::Update()
{
}
*/
void CDecal::Render()
{
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
STATEMANAGER.SetTransform(D3DTS_WORLD, &matWorld);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
for (DWORD dwi = 0; dwi < m_TriangleFanStructVector.size(); ++dwi)
STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLEFAN,
m_TriangleFanStructVector[dwi].m_wMinIndex,
m_TriangleFanStructVector[dwi].m_dwVertexCount,
m_TriangleFanStructVector[dwi].m_dwPrimitiveCount,
m_Indices + m_TriangleFanStructVector[dwi].m_wMinIndex,
D3DFMT_INDEX16,
m_Vertices,
sizeof(TPDTVertex));
}
/*
//////////////////////////////////////////////////////////////////////////
// CDecalManager
//////////////////////////////////////////////////////////////////////////
CDecalManager aDecalManager;
CDecalManager::CDecalManager()
{
m_DecalPtrVector.clear();
}
CDecalManager::~CDecalManager()
{
m_DecalPtrVector.clear();
}
void CDecalManager::Add(CDecal * pDecal)
{
m_DecalPtrVector.push_back(pDecal);
}
void CDecalManager::Remove(CDecal * pDecal)
{
std::vector<CDecal *>::iterator aIterator;
for (aIterator = m_DecalPtrVector.begin(); aIterator != m_DecalPtrVector.end();)
{
if (*aIterator == pDecal)
aIterator = m_DecalPtrVector.erase(aIterator);
else
++aIterator;
}
}
void CDecalManager::Update()
{
for (DWORD dwi = 0; dwi < m_DecalPtrVector.size(); ++dwi)
m_DecalPtrVector[dwi]->Update();
}
void CDecalManager::Render()
{
for (DWORD dwi = 0; dwi < m_DecalPtrVector.size(); ++dwi)
m_DecalPtrVector[dwi]->Render();
}
*/

103
src/EterLib/Decal.h Normal file
View File

@ -0,0 +1,103 @@
// Decal.h: interface for the CDecal class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_)
#define AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "GrpBase.h"
class CDecal
{
public:
enum
{
MAX_DECAL_VERTICES = 256,
};
CDecal();
virtual ~CDecal();
void Clear();
virtual void Make(D3DXVECTOR3 v3Center, D3DXVECTOR3 v3Normal, D3DXVECTOR3 v3Tangent, float fWidth, float fHeight, float fDepth) = 0;
// virtual void Update();
virtual void Render();
protected:
//
D3DXVECTOR3 m_v3Center;
D3DXVECTOR3 m_v3Normal;
// Clip Plane
D3DXPLANE m_v4LeftPlane;
D3DXPLANE m_v4RightPlane;
D3DXPLANE m_v4BottomPlane;
D3DXPLANE m_v4TopPlane;
D3DXPLANE m_v4FrontPlane;
D3DXPLANE m_v4BackPlane;
// <20><><EFBFBD><EFBFBD>
DWORD m_dwVertexCount;
DWORD m_dwPrimitiveCount;
// <20><><EFBFBD>ý<EFBFBD> <20><><EFBFBD>ۿ<EFBFBD> <20>δ콺 <20><><EFBFBD><EFBFBD>
// CGraphicVertexBuffer m_GraphicVertexBuffer;
// CGraphicIndexBuffer m_GraphicIndexBuffer;
// <20><><EFBFBD>ý<EFBFBD> <20><><EFBFBD>ۿ<EFBFBD> <20>δ콺 <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ſ<EFBFBD> <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DrawIndexedPrimitiveUP<55><50> <20>׸<EFBFBD><D7B8><EFBFBD>.
typedef struct
{
WORD m_wMinIndex;
DWORD m_dwVertexCount;
DWORD m_dwPrimitiveCount;
DWORD m_dwVBOffset;
} TTRIANGLEFANSTRUCT;
std::vector<TTRIANGLEFANSTRUCT> m_TriangleFanStructVector;
TPDTVertex m_Vertices[MAX_DECAL_VERTICES];
WORD m_Indices[MAX_DECAL_VERTICES];
const float m_cfDecalEpsilon;
protected:
bool AddPolygon(DWORD dwAddCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 *c_pv3Normal);
void ClipMesh(DWORD dwPrimitiveCount, const D3DXVECTOR3 *c_pv3Vertex, const D3DXVECTOR3 *c_pv3Normal);
DWORD ClipPolygon(DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal) const;
static DWORD ClipPolygonAgainstPlane(const D3DXPLANE& v4Plane,
DWORD dwVertexCount,
const D3DXVECTOR3 *c_pv3Vertex,
const D3DXVECTOR3 *c_pv3Normal,
D3DXVECTOR3 *c_pv3NewVertex,
D3DXVECTOR3 *c_pv3NewNormal);
};
/*
class CDecalManager : public CSingleton<CDecalManager>
{
public:
CDecalManager();
~CDecalManager();
void Add(CDecal * pDecal);
void Remove(CDecal * pDecal);
void Update();
void Render();
private:
std::vector<CDecal *> m_DecalPtrVector;
};
*/
#endif // !defined(AFX_DECAL_H__E3D27DFC_30CB_4995_B9B9_396B5E8A5F02__INCLUDED_)

163
src/EterLib/DibBar.cpp Normal file
View File

@ -0,0 +1,163 @@
#include "StdAfx.h"
#include "DibBar.h"
#include "BlockTexture.h"
void CDibBar::Invalidate()
{
RECT rect = {0, 0, m_dwWidth, m_dwHeight};
std::vector<CBlockTexture *>::iterator itor = m_kVec_pkBlockTexture.begin();
for (; itor != m_kVec_pkBlockTexture.end(); ++itor)
{
CBlockTexture * pTexture = *itor;
pTexture->InvalidateRect(rect);
}
}
void CDibBar::SetClipRect(const RECT & c_rRect)
{
std::vector<CBlockTexture *>::iterator itor = m_kVec_pkBlockTexture.begin();
for (; itor != m_kVec_pkBlockTexture.end(); ++itor)
{
CBlockTexture * pTexture = *itor;
assert(pTexture);
if (!pTexture)
continue;
pTexture->SetClipRect(c_rRect);
}
}
void CDibBar::ClearBar()
{
DWORD * pdwBuf = (DWORD *)m_dib.GetPointer();
memset(pdwBuf, 0, m_dib.GetWidth()*m_dib.GetHeight()*4);
Invalidate();
}
void CDibBar::Render(int ix, int iy)
{
std::vector<CBlockTexture *>::iterator itor = m_kVec_pkBlockTexture.begin();
for (; itor != m_kVec_pkBlockTexture.end(); ++itor)
{
CBlockTexture * pTexture = *itor;
pTexture->Render(ix, iy);
}
}
DWORD CDibBar::__NearTextureSize(DWORD dwSize)
{
if ((dwSize & (dwSize-1)) == 0)
return dwSize;
DWORD dwRet = 2;
while (dwRet < dwSize)
{
dwRet <<= 1;
}
return dwRet;
}
void CDibBar::__DivideTextureSize(DWORD dwSize, DWORD dwMax, DWORD * pdwxStep, DWORD * pdwxCount, DWORD * pdwxRest)
{
if (dwSize<dwMax)
{
*pdwxStep = dwMax;
*pdwxCount = 0;
*pdwxRest = dwSize%dwMax;
return;
}
*pdwxStep = dwMax;
*pdwxCount = dwSize/dwMax;
*pdwxRest = dwSize%dwMax;
}
CBlockTexture * CDibBar::__BuildTextureBlock(DWORD dwxPos, DWORD dwyPos, DWORD dwImageWidth, DWORD dwImageHeight, DWORD dwTextureWidth, DWORD dwTextureHeight)
{
if (dwTextureWidth == 0 || dwTextureHeight == 0)
return NULL;
RECT posRect = {dwxPos, dwyPos, dwxPos+dwImageWidth, dwyPos+dwImageHeight};
CBlockTexture * pBlockTexture = new CBlockTexture;
if (!pBlockTexture->Create(&m_dib, posRect, dwTextureWidth, dwTextureHeight))
{
delete pBlockTexture;
return NULL;
}
return pBlockTexture;
}
void CDibBar::__BuildTextureBlockList(DWORD dwWidth, DWORD dwHeight, DWORD dwMax)
{
DWORD dwxStep, dwyStep;
DWORD dwxCount, dwyCount;
DWORD dwxRest, dwyRest;
__DivideTextureSize(dwWidth, dwMax, &dwxStep, &dwxCount, &dwxRest);
__DivideTextureSize(dwHeight, dwMax, &dwyStep, &dwyCount, &dwyRest);
DWORD dwxTexRest = __NearTextureSize(dwxRest);
DWORD dwyTexRest = __NearTextureSize(dwyRest);
for (DWORD y = 0; y < dwyCount; ++y)
{
for (DWORD x = 0; x < dwxCount; ++x)
{
CBlockTexture * pTexture = __BuildTextureBlock(x*dwxStep, y*dwyStep,
dwxStep, dwyStep,
dwMax, dwMax);
if (pTexture)
m_kVec_pkBlockTexture.push_back(pTexture);
}
CBlockTexture * pTexture = __BuildTextureBlock(dwxCount*dwxStep, y*dwyStep,
dwxRest, dwyStep,
dwxTexRest, dwMax);
if (pTexture)
m_kVec_pkBlockTexture.push_back(pTexture);
}
for (DWORD x = 0; x < dwxCount; ++x)
{
CBlockTexture * pTexture = __BuildTextureBlock(x*dwxStep, dwyCount*dwyStep,
dwxStep, dwyRest,
dwMax, dwyTexRest);
if (pTexture)
m_kVec_pkBlockTexture.push_back(pTexture);
}
if (dwxRest > 0 && dwyRest > 0)
{
CBlockTexture * pTexture = __BuildTextureBlock(dwxCount*dwxStep, dwyCount*dwyStep,
dwxRest, dwyRest,
dwxTexRest, dwyTexRest);
if (pTexture)
m_kVec_pkBlockTexture.push_back(pTexture);
}
}
bool CDibBar::Create(HDC hdc, DWORD dwWidth, DWORD dwHeight)
{
if (!m_dib.Create(hdc, dwWidth, dwHeight))
{
Tracef(" Failed to create CDibBar\n");
return false;
}
m_dwWidth = dwWidth;
m_dwHeight = dwHeight;
__BuildTextureBlockList(dwWidth, dwHeight);
OnCreate();
return true;
}
CDibBar::CDibBar()
{
}
CDibBar::~CDibBar()
{
}

33
src/EterLib/DibBar.h Normal file
View File

@ -0,0 +1,33 @@
#pragma once
#include "GrpDib.h"
class CBlockTexture;
class CDibBar
{
public:
CDibBar();
virtual ~CDibBar();
bool Create(HDC hdc, DWORD dwWidth, DWORD dwHeight);
void Invalidate();
void SetClipRect(const RECT & c_rRect);
void ClearBar();
void Render(int ix, int iy);
protected:
DWORD __NearTextureSize(DWORD dwSize);
void __DivideTextureSize(DWORD dwSize, DWORD dwMax, DWORD * pdwxStep, DWORD * pdwxCount, DWORD * pdwxRest);
CBlockTexture * __BuildTextureBlock(DWORD dwxPos, DWORD dwyPos, DWORD dwImageWidth, DWORD dwImageHeight, DWORD dwTextureWidth, DWORD dwTextureHeight);
void __BuildTextureBlockList(DWORD dwWidth, DWORD dwHeight, DWORD dwMax=256);
virtual void OnCreate(){}
protected:
CGraphicDib m_dib;
std::vector<CBlockTexture *> m_kVec_pkBlockTexture;
DWORD m_dwWidth;
DWORD m_dwHeight;
};

6579
src/EterLib/Dimm.h Normal file

File diff suppressed because it is too large Load Diff

75
src/EterLib/Dynamic.h Normal file
View File

@ -0,0 +1,75 @@
#pragma once
template<typename T>
class CDynamic
{
public:
struct FClear
{
void operator() (CDynamic<T>& rDynamic)
{
rDynamic.Clear();
}
};
public:
CDynamic()
{
Initialize();
}
~CDynamic()
{
Clear();
}
void Clear()
{
if (m_pObject)
ms_objectPool.Free(m_pObject);
Initialize();
}
T* GetUsablePointer()
{
if (!m_pObject)
m_pObject = ms_objectPool.Alloc();
return m_pObject;
}
bool IsNull() const
{
if (m_pObject)
return false;
return true;
}
T* GetPointer() const
{
assert(m_pObject != NULL);
return m_pObject;
}
T* operator->() const
{
assert(m_pObject != NULL);
return m_pObject;
}
private:
T* m_pObject;
private:
void Initialize()
{
m_pObject = NULL;
}
private:
static CDynamicPool<T> ms_objectPool;
};
template<typename T>
CDynamicPool<T> CDynamic<T>::ms_objectPool;

View File

@ -0,0 +1,20 @@
// EnvironmentMap.cpp: implementation of the CEnvironmentMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EnvironmentMap.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CEnvironmentMap::CEnvironmentMap()
{
}
CEnvironmentMap::~CEnvironmentMap()
{
}

View File

@ -0,0 +1,22 @@
// EnvironmentMap.h: interface for the CEnvironmentMap class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ENVIRONMENTMAP_H__FD56B8B7_5B98_4E55_B86E_A2293BE9F4F8__INCLUDED_)
#define AFX_ENVIRONMENTMAP_H__FD56B8B7_5B98_4E55_B86E_A2293BE9F4F8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "GrpScreen.h"
class CEnvironmentMap : public CScreen
{
public:
CEnvironmentMap();
virtual ~CEnvironmentMap();
};
#endif // !defined(AFX_ENVIRONMENTMAP_H__FD56B8B7_5B98_4E55_B86E_A2293BE9F4F8__INCLUDED_)

497
src/EterLib/EterLib.vcxproj Normal file
View File

@ -0,0 +1,497 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Distribute|Win32">
<Configuration>Distribute</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="MfcDebug|Win32">
<Configuration>MfcDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="MfcRelease|Win32">
<Configuration>MfcRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="VTune|Win32">
<Configuration>VTune</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectName>EterLib</ProjectName>
<ProjectGuid>{887F89DF-A1A2-47DF-A869-F3FC84704E3E}</ProjectGuid>
<RootNamespace>EterLib</RootNamespace>
<SccProjectName>SAK</SccProjectName>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProvider>SAK</SccProvider>
<Keyword>MFCProj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>17.0.32203.90</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<OutDir>$(SolutionDir)build\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgConfiguration>$(Configuration)</VcpkgConfiguration>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\MfcRelease/</AssemblerListingLocation>
<ObjectFileName>.\MfcRelease/</ObjectFileName>
<ProgramDataBaseFileName>.\MfcRelease/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
<AdditionalIncludeDirectories>c:/eterlib/bin/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Lib>
<OutputFile>.\MfcRelease\eterlib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
<ObjectFileName>.\Debug/</ObjectFileName>
<ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
<IgnoreStandardIncludePath>true</IgnoreStandardIncludePath>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">
<ClCompile>
<AdditionalOptions>/Gs %(AdditionalOptions)</AdditionalOptions>
<Optimization>Disabled</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\VTune/</AssemblerListingLocation>
<ObjectFileName>.\VTune/</ObjectFileName>
<ProgramDataBaseFileName>.\VTune/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
<AdditionalIncludeDirectories>c:/eterlib/bin/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Lib>
<OutputFile>.\VTune\eterlib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;../../extern/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\MfcDebug/</AssemblerListingLocation>
<ObjectFileName>.\MfcDebug/</ObjectFileName>
<ProgramDataBaseFileName>.\MfcDebug/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
</ResourceCompile>
<Lib>
<OutputFile>.\MfcDebug\eterlib.lib</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerListingLocation>.\Release/</AssemblerListingLocation>
<ObjectFileName>.\Release/</ObjectFileName>
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
<AdditionalIncludeDirectories>c:/eterlib/bin/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<AdditionalIncludeDirectories>$(SolutionDir)extern\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName).pch</PrecompiledHeaderOutputFile>
<AssemblerOutput>All</AssemblerOutput>
<AssemblerListingLocation>.\Distribute/</AssemblerListingLocation>
<ObjectFileName>.\Distribute/</ObjectFileName>
<ProgramDataBaseFileName>.\Distribute/</ProgramDataBaseFileName>
<BrowseInformation />
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0412</Culture>
<AdditionalIncludeDirectories>c:/eterlib/bin/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Lib>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AttributeData.cpp" />
<ClCompile Include="AttributeInstance.cpp" />
<ClCompile Include="BlockTexture.cpp" />
<ClCompile Include="Camera.cpp" />
<ClCompile Include="CollisionData.cpp" />
<ClCompile Include="ColorTransitionHelper.cpp" />
<ClCompile Include="CullingManager.cpp" />
<ClCompile Include="Decal.cpp" />
<ClCompile Include="DibBar.cpp" />
<ClCompile Include="EnvironmentMap.cpp" />
<ClCompile Include="FileLoaderThread.cpp" />
<ClCompile Include="GrpBase.cpp" />
<ClCompile Include="GrpCollisionObject.cpp" />
<ClCompile Include="GrpColor.cpp" />
<ClCompile Include="GrpColorInstance.cpp" />
<ClCompile Include="GrpD3DXBuffer.cpp" />
<ClCompile Include="GrpDetector.cpp" />
<ClCompile Include="GrpDevice.cpp" />
<ClCompile Include="GrpDIB.cpp" />
<ClCompile Include="GrpExpandedImageInstance.cpp" />
<ClCompile Include="GrpFontTexture.cpp" />
<ClCompile Include="GrpImage.cpp" />
<ClCompile Include="GrpImageInstance.cpp" />
<ClCompile Include="GrpImageTexture.cpp" />
<ClCompile Include="GrpIndexBuffer.cpp" />
<ClCompile Include="GrpLightManager.cpp" />
<ClCompile Include="GrpMarkInstance.cpp" />
<ClCompile Include="GrpMath.cpp" />
<ClCompile Include="GrpObjectInstance.cpp" />
<ClCompile Include="GrpPixelShader.cpp" />
<ClCompile Include="GrpRatioInstance.cpp" />
<ClCompile Include="GrpScreen.cpp" />
<ClCompile Include="GrpShadowTexture.cpp" />
<ClCompile Include="GrpSubImage.cpp" />
<ClCompile Include="GrpText.cpp" />
<ClCompile Include="GrpTextInstance.cpp" />
<ClCompile Include="GrpTexture.cpp" />
<ClCompile Include="GrpVertexBuffer.cpp" />
<ClCompile Include="GrpVertexBufferDynamic.cpp" />
<ClCompile Include="GrpVertexBufferStatic.cpp" />
<ClCompile Include="GrpVertexShader.cpp" />
<ClCompile Include="IME.cpp" />
<ClCompile Include="Input.cpp" />
<ClCompile Include="JpegFile.cpp" />
<ClCompile Include="LensFlare.cpp" />
<ClCompile Include="lineintersect_utils.cpp" />
<ClCompile Include="MSApplication.cpp" />
<ClCompile Include="MSWindow.cpp" />
<ClCompile Include="Mutex.cpp" />
<ClCompile Include="NetAddress.cpp" />
<ClCompile Include="NetDatagram.cpp" />
<ClCompile Include="NetDatagramReceiver.cpp" />
<ClCompile Include="NetDatagramSender.cpp" />
<ClCompile Include="NetDevice.cpp" />
<ClCompile Include="NetPacketHeaderMap.cpp" />
<ClCompile Include="NetStream.cpp" />
<ClCompile Include="parser.cpp" />
<ClCompile Include="PathStack.cpp" />
<ClCompile Include="ReferenceObject.cpp" />
<ClCompile Include="Resource.cpp" />
<ClCompile Include="ResourceManager.cpp" />
<ClCompile Include="ScreenFilter.cpp" />
<ClCompile Include="SkyBox.cpp" />
<ClCompile Include="StateManager.cpp" />
<ClCompile Include="StdAfx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='MfcDebug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='MfcRelease|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='VTune|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TargaResource.cpp" />
<ClCompile Include="TextBar.cpp" />
<ClCompile Include="TextFileLoader.cpp" />
<ClCompile Include="TextTag.cpp" />
<ClCompile Include="Thread.cpp" />
<ClCompile Include="Util.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AttributeData.h" />
<ClInclude Include="AttributeInstance.h" />
<ClInclude Include="BlockTexture.h" />
<ClInclude Include="Camera.h" />
<ClInclude Include="CollisionData.h" />
<ClInclude Include="ColorTransitionHelper.h" />
<ClInclude Include="CullingManager.h" />
<ClInclude Include="Decal.h" />
<ClInclude Include="DibBar.h" />
<ClInclude Include="Dimm.h" />
<ClInclude Include="Dynamic.h" />
<ClInclude Include="EnvironmentMap.h" />
<ClInclude Include="Event.h" />
<ClInclude Include="FileLoaderThread.h" />
<ClInclude Include="FuncObject.h" />
<ClInclude Include="GrpBase.h" />
<ClInclude Include="GrpCollisionObject.h" />
<ClInclude Include="GrpColor.h" />
<ClInclude Include="GrpColorInstance.h" />
<ClInclude Include="GrpD3DXBuffer.h" />
<ClInclude Include="GrpDetector.h" />
<ClInclude Include="GrpDevice.h" />
<ClInclude Include="GrpDIB.h" />
<ClInclude Include="GrpExpandedImageInstance.h" />
<ClInclude Include="GrpFontTexture.h" />
<ClInclude Include="GrpImage.h" />
<ClInclude Include="GrpImageInstance.h" />
<ClInclude Include="GrpImageTexture.h" />
<ClInclude Include="GrpIndexBuffer.h" />
<ClInclude Include="GrpLightManager.h" />
<ClInclude Include="GrpMarkInstance.h" />
<ClInclude Include="GrpMath.h" />
<ClInclude Include="GrpObjectInstance.h" />
<ClInclude Include="GrpPixelShader.h" />
<ClInclude Include="GrpRatioInstance.h" />
<ClInclude Include="GrpScreen.h" />
<ClInclude Include="GrpShadowTexture.h" />
<ClInclude Include="GrpSubImage.h" />
<ClInclude Include="GrpText.h" />
<ClInclude Include="GrpTextInstance.h" />
<ClInclude Include="GrpTexture.h" />
<ClInclude Include="GrpVertexBuffer.h" />
<ClInclude Include="GrpVertexBufferDynamic.h" />
<ClInclude Include="GrpVertexBufferStatic.h" />
<ClInclude Include="GrpVertexShader.h" />
<ClInclude Include="IME.h" />
<ClInclude Include="Input.h" />
<ClInclude Include="JpegFile.h" />
<ClInclude Include="LensFlare.h" />
<ClInclude Include="lineintersect_utils.h" />
<ClInclude Include="MSApplication.h" />
<ClInclude Include="msctf.h" />
<ClInclude Include="MSWindow.h" />
<ClInclude Include="Mutex.h" />
<ClInclude Include="NetAddress.h" />
<ClInclude Include="NetDatagram.h" />
<ClInclude Include="NetDatagramReceiver.h" />
<ClInclude Include="NetDatagramSender.h" />
<ClInclude Include="NetDevice.h" />
<ClInclude Include="NetPacketHeaderMap.h" />
<ClInclude Include="NetStream.h" />
<ClInclude Include="parser.h" />
<ClInclude Include="PathStack.h" />
<ClInclude Include="Pool.h" />
<ClInclude Include="Profiler.h" />
<ClInclude Include="Ray.h" />
<ClInclude Include="Ref.h" />
<ClInclude Include="ReferenceObject.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="ResourceManager.h" />
<ClInclude Include="ScreenFilter.h" />
<ClInclude Include="SkyBox.h" />
<ClInclude Include="StateManager.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="TargaResource.h" />
<ClInclude Include="TextBar.h" />
<ClInclude Include="TextFileLoader.h" />
<ClInclude Include="TextTag.h" />
<ClInclude Include="Thread.h" />
<ClInclude Include="Util.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EterLocale\EterLocale.vcxproj">
<Project>{05207e97-c83a-49c6-8e08-403679963a7b}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,497 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{d97e45c0-442d-4d4d-a361-5ae9e7463e91}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{a527c376-150f-423a-bfd9-257d27d5e25a}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="Culling">
<UniqueIdentifier>{b51c8af0-c270-412e-a7e2-98ad72ea3a71}</UniqueIdentifier>
</Filter>
<Filter Include="Graphic">
<UniqueIdentifier>{1f8ec9f8-b236-4750-bb83-95bfdaa18a23}</UniqueIdentifier>
</Filter>
<Filter Include="Resource">
<UniqueIdentifier>{5bb276bb-6b88-4a52-9f31-e730687f5479}</UniqueIdentifier>
</Filter>
<Filter Include="Image">
<UniqueIdentifier>{43a3bda6-d33d-47e2-9ff4-c34f3512865e}</UniqueIdentifier>
</Filter>
<Filter Include="Network">
<UniqueIdentifier>{56d99402-a5d7-4201-8141-56845318e21c}</UniqueIdentifier>
</Filter>
<Filter Include="Font">
<UniqueIdentifier>{54f60fd9-6a88-448c-8617-8dc0f149cae7}</UniqueIdentifier>
</Filter>
<Filter Include="Font_New">
<UniqueIdentifier>{32ca945e-2b0a-4fa1-86a8-d9ea56d98e9c}</UniqueIdentifier>
</Filter>
<Filter Include="IME">
<UniqueIdentifier>{077d7e04-c39b-4103-9458-f39cffcef041}</UniqueIdentifier>
</Filter>
<Filter Include="Text">
<UniqueIdentifier>{b2bab8c6-295b-4b7e-ab32-3b8f7c757be7}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AttributeData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AttributeInstance.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CollisionData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ColorTransitionHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Decal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EnvironmentMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FileLoaderThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpCollisionObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpColor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpColorInstance.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpD3DXBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpDIB.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpIndexBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpLightManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpObjectInstance.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpPixelShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpRatioInstance.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpShadowTexture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpVertexBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpVertexBufferDynamic.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpVertexBufferStatic.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GrpVertexShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Input.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LensFlare.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="lineintersect_utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MSApplication.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MSWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mutex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="parser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PathStack.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ReferenceObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ScreenFilter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkyBox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TargaResource.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Thread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CullingManager.cpp">
<Filter>Culling</Filter>
</ClCompile>
<ClCompile Include="GrpBase.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="GrpDetector.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="GrpDevice.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="GrpMath.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="GrpScreen.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="JpegFile.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="StateManager.cpp">
<Filter>Graphic</Filter>
</ClCompile>
<ClCompile Include="Resource.cpp">
<Filter>Resource</Filter>
</ClCompile>
<ClCompile Include="ResourceManager.cpp">
<Filter>Resource</Filter>
</ClCompile>
<ClCompile Include="GrpExpandedImageInstance.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpImage.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpImageInstance.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpImageTexture.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpMarkInstance.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpSubImage.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="GrpTexture.cpp">
<Filter>Image</Filter>
</ClCompile>
<ClCompile Include="NetAddress.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetDatagram.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetDatagramReceiver.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetDatagramSender.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetDevice.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetPacketHeaderMap.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="NetStream.cpp">
<Filter>Network</Filter>
</ClCompile>
<ClCompile Include="GrpFontTexture.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="GrpText.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="GrpTextInstance.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="TextTag.cpp">
<Filter>Font</Filter>
</ClCompile>
<ClCompile Include="BlockTexture.cpp">
<Filter>Font_New</Filter>
</ClCompile>
<ClCompile Include="DibBar.cpp">
<Filter>Font_New</Filter>
</ClCompile>
<ClCompile Include="TextBar.cpp">
<Filter>Font_New</Filter>
</ClCompile>
<ClCompile Include="IME.cpp">
<Filter>IME</Filter>
</ClCompile>
<ClCompile Include="TextFileLoader.cpp">
<Filter>Text</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="AttributeData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AttributeInstance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Camera.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CollisionData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ColorTransitionHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Decal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Dynamic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EnvironmentMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FileLoaderThread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FuncObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpCollisionObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpColor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpColorInstance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpD3DXBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpDIB.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpIndexBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpLightManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpObjectInstance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpPixelShader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpRatioInstance.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpShadowTexture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpVertexBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpVertexBufferDynamic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpVertexBufferStatic.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GrpVertexShader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Input.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LensFlare.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lineintersect_utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MSApplication.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MSWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="parser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PathStack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Pool.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Profiler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Ray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Ref.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ReferenceObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScreenFilter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SkyBox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TargaResource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Thread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CullingManager.h">
<Filter>Culling</Filter>
</ClInclude>
<ClInclude Include="GrpBase.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="GrpDetector.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="GrpDevice.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="GrpMath.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="GrpScreen.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="JpegFile.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="StateManager.h">
<Filter>Graphic</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Resource</Filter>
</ClInclude>
<ClInclude Include="ResourceManager.h">
<Filter>Resource</Filter>
</ClInclude>
<ClInclude Include="GrpExpandedImageInstance.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpImage.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpImageInstance.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpImageTexture.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpMarkInstance.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpSubImage.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="GrpTexture.h">
<Filter>Image</Filter>
</ClInclude>
<ClInclude Include="NetAddress.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetDatagram.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetDatagramReceiver.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetDatagramSender.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetDevice.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetPacketHeaderMap.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="NetStream.h">
<Filter>Network</Filter>
</ClInclude>
<ClInclude Include="GrpFontTexture.h">
<Filter>Font</Filter>
</ClInclude>
<ClInclude Include="GrpText.h">
<Filter>Font</Filter>
</ClInclude>
<ClInclude Include="GrpTextInstance.h">
<Filter>Font</Filter>
</ClInclude>
<ClInclude Include="TextTag.h">
<Filter>Font</Filter>
</ClInclude>
<ClInclude Include="BlockTexture.h">
<Filter>Font_New</Filter>
</ClInclude>
<ClInclude Include="DibBar.h">
<Filter>Font_New</Filter>
</ClInclude>
<ClInclude Include="TextBar.h">
<Filter>Font_New</Filter>
</ClInclude>
<ClInclude Include="Dimm.h">
<Filter>IME</Filter>
</ClInclude>
<ClInclude Include="IME.h">
<Filter>IME</Filter>
</ClInclude>
<ClInclude Include="msctf.h">
<Filter>IME</Filter>
</ClInclude>
<ClInclude Include="TextFileLoader.h">
<Filter>Text</Filter>
</ClInclude>
</ItemGroup>
</Project>

69
src/EterLib/Event.h Normal file
View File

@ -0,0 +1,69 @@
#pragma once
class IEvent
{
public:
IEvent();
~IEvent();
virtual void Run() = 0;
void SetStartTime(float fTime) { m_fStartTime = fTime; }
float GetStartTime() { return m_fStartTime; }
protected:
float m_fStartTime;
};
class CEventManager : public CSingleton<CEventManager>
{
public:
CEventManager();
virtual ~CEventManager()
{
Destroy();
}
void Destroy()
{
while (!m_eventQueue.empty())
{
IEvent * pEvent = m_eventQueue.top();
m_eventQueue.pop();
delete pEvent;
}
}
void Register(IEvent * pEvent)
{
m_eventQueue.push(pEvent);
}
void Update(float fCurrentTime)
{
while (!m_eventQueue.empty())
{
IEvent * pEvent = m_eventQueue.top();
if (pEvent->GetStartTime() < fCurrentTime)
break;
m_eventQueue.pop();
float fTime = pEvent->GetStartTime();
pEvent->Run();
delete pEvent;
}
}
protected:
struct EventComparisonFunc
{
bool operator () (IEvent * left, IEvent * right) const
{
return left->GetStartTime() > right->GetStartTime();
}
};
typedef std::priority_queue<IEvent *, std::vector<IEvent *>, EventComparisonFunc> TEventQueue;
TEventQueue m_eventQueue;
};

View File

@ -0,0 +1,180 @@
#include "StdAfx.h"
#include "../EterPack/EterPackManager.h"
#include "FileLoaderThread.h"
#include "ResourceManager.h"
CFileLoaderThread::CFileLoaderThread() : m_bShutdowned(false), m_pArg(NULL), m_hThread(NULL), m_uThreadID(0)
{
}
CFileLoaderThread::~CFileLoaderThread()
{
Destroy();
}
int CFileLoaderThread::Create(void * arg)
{
Arg(arg);
m_hThread = (HANDLE) _beginthreadex(NULL, 0, EntryPoint, this, 0, &m_uThreadID);
if (!m_hThread)
return false;
SetThreadPriority(m_hThread, THREAD_PRIORITY_NORMAL);
return true;
}
UINT CFileLoaderThread::Run(void * arg)
{
if (!Setup())
return 0;
return (Execute(arg));
}
/* Static */
UINT CALLBACK CFileLoaderThread::EntryPoint(void * pThis)
{
CFileLoaderThread * pThread = (CFileLoaderThread *) pThis;
return pThread->Run(pThread->Arg());
}
//////////////////////////////////////////////////////////////////////////
void CFileLoaderThread::Destroy()
{
if (m_hSemaphore)
{
CloseHandle(m_hSemaphore);
m_hSemaphore = NULL;
}
stl_wipe(m_pRequestDeque);
stl_wipe(m_pCompleteDeque);
}
UINT CFileLoaderThread::Setup()
{
m_hSemaphore = CreateSemaphore(NULL, // no security attributes
0, // initial count
65535, // maximum count
NULL); // unnamed semaphore
if (!m_hSemaphore)
return 0;
return 1;
}
void CFileLoaderThread::Shutdown()
{
if (!m_hSemaphore)
return;
BOOL bRet;
m_bShutdowned = true;
do
{
bRet = ReleaseSemaphore(m_hSemaphore, 1, NULL);
}
while (!bRet);
WaitForSingleObject(m_hThread, 10000); // <20><><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD> <20>DZ⸦ 10<31><30> <20><><EFBFBD>ٸ<EFBFBD>
}
UINT CFileLoaderThread::Execute(void * /*pvArg*/)
{
while (!m_bShutdowned)
{
DWORD dwWaitResult;
dwWaitResult = WaitForSingleObject(m_hSemaphore, INFINITE);
if (m_bShutdowned)
break;
switch (dwWaitResult)
{
case WAIT_OBJECT_0:
{
Process();
}
break;
case WAIT_TIMEOUT:
TraceError("CFileLoaderThread::Execute: Timeout occured while time-out interval is INIFITE");
break;
}
}
Destroy();
return 1;
}
void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main thread
{
TData * pData = new TData;
pData->dwSize = 0;
pData->pvBuf = NULL;
pData->stFileName = c_rstFileName;
m_RequestMutex.Lock();
m_pRequestDeque.push_back(pData);
m_RequestMutex.Unlock();
++m_iRestSemCount;
if (!ReleaseSemaphore(m_hSemaphore, m_iRestSemCount, NULL))
TraceError("CFileLoaderThread::Request: ReleaseSemaphore error");
--m_iRestSemCount;
}
bool CFileLoaderThread::Fetch(TData ** ppData) // called in main thread
{
m_CompleteMutex.Lock();
if (m_pCompleteDeque.empty())
{
m_CompleteMutex.Unlock();
return false;
}
*ppData = m_pCompleteDeque.front();
m_pCompleteDeque.pop_front();
m_CompleteMutex.Unlock();
return true;
}
void CFileLoaderThread::Process() // called in loader thread
{
m_RequestMutex.Lock();
if (m_pRequestDeque.empty())
{
m_RequestMutex.Unlock();
return;
}
TData * pData = m_pRequestDeque.front();
m_pRequestDeque.pop_front();
m_RequestMutex.Unlock();
LPCVOID pvBuf;
if (CEterPackManager::Instance().Get(pData->File, pData->stFileName.c_str(), &pvBuf))
{
pData->dwSize = pData->File.Size();
pData->pvBuf = new char [pData->dwSize];
memcpy(pData->pvBuf, pvBuf, pData->dwSize);
}
m_CompleteMutex.Lock();
m_pCompleteDeque.push_back(pData);
m_CompleteMutex.Unlock();
Sleep(g_iLoadingDelayTime);
}

View File

@ -0,0 +1,63 @@
#ifndef __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__
#define __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__
#include <deque>
#include "Thread.h"
#include "Mutex.h"
#include "../eterBase/MappedFile.h"
class CFileLoaderThread
{
public:
typedef struct SData
{
std::string stFileName;
CMappedFile File;
LPVOID pvBuf;
DWORD dwSize;
} TData;
public:
CFileLoaderThread();
~CFileLoaderThread();
int Create(void * arg);
public:
void Request(std::string & c_rstFileName);
bool Fetch(TData ** ppData);
void Shutdown();
protected:
static UINT CALLBACK EntryPoint(void * pThis);
UINT Run(void * arg);
void * Arg() const { return m_pArg; }
void Arg(void * arg) { m_pArg = arg; }
HANDLE m_hThread;
private:
void * m_pArg;
unsigned m_uThreadID;
protected:
UINT Setup();
UINT Execute(void * pvArg);
void Destroy();
void Process();
private:
std::deque<TData *> m_pRequestDeque;
Mutex m_RequestMutex;
std::deque<TData *> m_pCompleteDeque;
Mutex m_CompleteMutex;
HANDLE m_hSemaphore;
int m_iRestSemCount;
bool m_bShutdowned;
};
#endif

49
src/EterLib/FuncObject.h Normal file
View File

@ -0,0 +1,49 @@
#pragma once
template<typename T>
class CFuncObject
{
public:
CFuncObject()
{
Clear();
}
virtual ~CFuncObject()
{
}
void Clear()
{
m_pSelfObject = NULL;
m_pFuncObject = NULL;
}
void Set(T* pSelfObject, void (T::*pFuncObject)())
{
m_pSelfObject = pSelfObject;
m_pFuncObject = pFuncObject;
}
bool IsEmpty()
{
if (m_pSelfObject != NULL)
return false;
if (m_pFuncObject != NULL)
return false;
return true;
}
void Run()
{
if (m_pSelfObject)
if (m_pFuncObject)
(m_pSelfObject->*m_pFuncObject)();
}
protected:
T * m_pSelfObject;
void (T::*m_pFuncObject) ();
};

512
src/EterLib/GrpBase.cpp Normal file
View File

@ -0,0 +1,512 @@
#include "StdAfx.h"
#include "../eterBase/Utils.h"
#include "../eterBase/Timer.h"
#include "GrpBase.h"
#include "Camera.h"
#include "StateManager.h"
void PixelPositionToD3DXVECTOR3(const D3DXVECTOR3& c_rkPPosSrc, D3DXVECTOR3* pv3Dst)
{
pv3Dst->x=+c_rkPPosSrc.x;
pv3Dst->y=-c_rkPPosSrc.y;
pv3Dst->z=+c_rkPPosSrc.z;
}
void D3DXVECTOR3ToPixelPosition(const D3DXVECTOR3& c_rv3Src, D3DXVECTOR3* pv3Dst)
{
pv3Dst->x=+c_rv3Src.x;
pv3Dst->y=-c_rv3Src.y;
pv3Dst->z=+c_rv3Src.z;
}
UINT CGraphicBase::ms_iD3DAdapterInfo=0;
UINT CGraphicBase::ms_iD3DDevInfo=0;
UINT CGraphicBase::ms_iD3DModeInfo=0;
D3D_CDisplayModeAutoDetector CGraphicBase::ms_kD3DDetector;
HWND CGraphicBase::ms_hWnd;
HDC CGraphicBase::ms_hDC;
LPDIRECT3D8 CGraphicBase::ms_lpd3d = NULL;
LPDIRECT3DDEVICE8 CGraphicBase::ms_lpd3dDevice = NULL;
ID3DXMatrixStack * CGraphicBase::ms_lpd3dMatStack = NULL;
D3DPRESENT_PARAMETERS CGraphicBase::ms_d3dPresentParameter;
D3DVIEWPORT8 CGraphicBase::ms_Viewport;
HRESULT CGraphicBase::ms_hLastResult = NULL;
int CGraphicBase::ms_iWidth;
int CGraphicBase::ms_iHeight;
DWORD CGraphicBase::ms_faceCount = 0;
D3DCAPS8 CGraphicBase::ms_d3dCaps;
DWORD CGraphicBase::ms_dwD3DBehavior = 0;
DWORD CGraphicBase::ms_ptVS = 0;
DWORD CGraphicBase::ms_pntVS = 0;
DWORD CGraphicBase::ms_pnt2VS = 0;
D3DXMATRIX CGraphicBase::ms_matIdentity;
D3DXMATRIX CGraphicBase::ms_matView;
D3DXMATRIX CGraphicBase::ms_matProj;
D3DXMATRIX CGraphicBase::ms_matInverseView;
D3DXMATRIX CGraphicBase::ms_matInverseViewYAxis;
D3DXMATRIX CGraphicBase::ms_matWorld;
D3DXMATRIX CGraphicBase::ms_matWorldView;
D3DXMATRIX CGraphicBase::ms_matScreen0;
D3DXMATRIX CGraphicBase::ms_matScreen1;
D3DXMATRIX CGraphicBase::ms_matScreen2;
D3DXVECTOR3 CGraphicBase::ms_vtPickRayOrig;
D3DXVECTOR3 CGraphicBase::ms_vtPickRayDir;
float CGraphicBase::ms_fFieldOfView;
float CGraphicBase::ms_fNearY;
float CGraphicBase::ms_fFarY;
float CGraphicBase::ms_fAspect;
DWORD CGraphicBase::ms_dwWavingEndTime;
int CGraphicBase::ms_iWavingPower;
DWORD CGraphicBase::ms_dwFlashingEndTime;
D3DXCOLOR CGraphicBase::ms_FlashingColor;
// Terrain picking<6E><67> Ray... CCamera <20>̿<EFBFBD><CCBF>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>.. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ray<61><79> <20><><EFBFBD><EFBFBD> <20>ʿ<EFBFBD>...
CRay CGraphicBase::ms_Ray;
bool CGraphicBase::ms_bSupportDXT = true;
bool CGraphicBase::ms_isLowTextureMemory = false;
bool CGraphicBase::ms_isHighTextureMemory = false;
// 2004.11.18.myevan.DynamicVertexBuffer<65><72> <20><>ü
/*
std::vector<TIndex> CGraphicBase::ms_lineIdxVector;
std::vector<TIndex> CGraphicBase::ms_lineTriIdxVector;
std::vector<TIndex> CGraphicBase::ms_lineRectIdxVector;
std::vector<TIndex> CGraphicBase::ms_lineCubeIdxVector;
std::vector<TIndex> CGraphicBase::ms_fillTriIdxVector;
std::vector<TIndex> CGraphicBase::ms_fillRectIdxVector;
std::vector<TIndex> CGraphicBase::ms_fillCubeIdxVector;
*/
LPD3DXMESH CGraphicBase::ms_lpSphereMesh = NULL;
LPD3DXMESH CGraphicBase::ms_lpCylinderMesh = NULL;
LPDIRECT3DVERTEXBUFFER8 CGraphicBase::ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
LPDIRECT3DINDEXBUFFER8 CGraphicBase::ms_alpd3dDefIB[DEFAULT_IB_NUM];
bool CGraphicBase::IsLowTextureMemory()
{
return ms_isLowTextureMemory;
}
bool CGraphicBase::IsHighTextureMemory()
{
return ms_isHighTextureMemory;
}
bool CGraphicBase::IsFastTNL()
{
if (ms_dwD3DBehavior & D3DCREATE_HARDWARE_VERTEXPROCESSING ||
ms_dwD3DBehavior & D3DCREATE_MIXED_VERTEXPROCESSING)
{
if (ms_d3dCaps.VertexShaderVersion>D3DVS_VERSION(1,0))
return true;
}
return false;
}
bool CGraphicBase::IsTLVertexClipping()
{
if (ms_d3dCaps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS)
return true;
return false;
}
void CGraphicBase::GetBackBufferSize(UINT* puWidth, UINT* puHeight)
{
*puWidth=ms_d3dPresentParameter.BackBufferWidth;
*puHeight=ms_d3dPresentParameter.BackBufferHeight;
}
void CGraphicBase::SetDefaultIndexBuffer(UINT eDefIB)
{
if (eDefIB>=DEFAULT_IB_NUM)
return;
STATEMANAGER.SetIndices(ms_alpd3dDefIB[eDefIB], 0);
}
bool CGraphicBase::SetPDTStream(SPDTVertex* pVertices, UINT uVtxCount)
{
return SetPDTStream((SPDTVertexRaw*)pVertices, uVtxCount);
}
bool CGraphicBase::SetPDTStream(SPDTVertexRaw* pSrcVertices, UINT uVtxCount)
{
if (!uVtxCount)
return false;
static DWORD s_dwVBPos=0;
if (s_dwVBPos>=PDT_VERTEXBUFFER_NUM)
s_dwVBPos=0;
IDirect3DVertexBuffer8* plpd3dFillRectVB=ms_alpd3dPDTVB[s_dwVBPos];
++s_dwVBPos;
assert(PDT_VERTEX_NUM>=uVtxCount);
if (uVtxCount >= PDT_VERTEX_NUM)
return false;
TPDTVertex* pDstVertices;
if (FAILED(
plpd3dFillRectVB->Lock(0, sizeof(TPDTVertex)*uVtxCount, (BYTE**)&pDstVertices, D3DLOCK_DISCARD)
))
{
STATEMANAGER.SetStreamSource(0, NULL, 0);
return false;
}
memcpy(pDstVertices, pSrcVertices, sizeof(TPDTVertex)*uVtxCount);
plpd3dFillRectVB->Unlock();
STATEMANAGER.SetStreamSource(0, plpd3dFillRectVB, sizeof(TPDTVertex));
return true;
}
DWORD CGraphicBase::GetAvailableTextureMemory()
{
assert(ms_lpd3dDevice!=NULL && "CGraphicBase::GetAvailableTextureMemory - D3DDevice is EMPTY");
static DWORD s_dwNextUpdateTime=0;
static DWORD s_dwTexMemSize=0;//ms_lpd3dDevice->GetAvailableTextureMem();
DWORD dwCurTime=ELTimer_GetMSec();
if (s_dwNextUpdateTime<dwCurTime)
{
s_dwNextUpdateTime=dwCurTime+5000;
s_dwTexMemSize=ms_lpd3dDevice->GetAvailableTextureMem();
}
return s_dwTexMemSize;
}
const D3DXMATRIX& CGraphicBase::GetViewMatrix()
{
return ms_matView;
}
const D3DXMATRIX & CGraphicBase::GetIdentityMatrix()
{
return ms_matIdentity;
}
void CGraphicBase::SetEyeCamera(float xEye, float yEye, float zEye,
float xCenter, float yCenter, float zCenter,
float xUp, float yUp, float zUp)
{
D3DXVECTOR3 vectorEye(xEye, yEye, zEye);
D3DXVECTOR3 vectorCenter(xCenter, yCenter, zCenter);
D3DXVECTOR3 vectorUp(xUp, yUp, zUp);
// CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
CCameraManager::Instance().GetCurrentCamera()->SetViewParams(vectorEye, vectorCenter, vectorUp);
UpdateViewMatrix();
}
void CGraphicBase::SetSimpleCamera(float x, float y, float z, float pitch, float roll)
{
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
D3DXVECTOR3 vectorEye(x, y, z);
pCamera->SetViewParams(D3DXVECTOR3(0.0f, y, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
pCamera->RotateEyeAroundTarget(pitch, roll);
pCamera->Move(vectorEye);
UpdateViewMatrix();
// This is levites's virtual(?) code which you should not trust.
ms_lpd3dDevice->GetTransform(D3DTS_WORLD, &ms_matWorld);
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
}
void CGraphicBase::SetAroundCamera(float distance, float pitch, float roll, float lookAtZ)
{
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
pCamera->SetViewParams(D3DXVECTOR3(0.0f, -distance, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
pCamera->RotateEyeAroundTarget(pitch, roll);
D3DXVECTOR3 v3Target = pCamera->GetTarget();
v3Target.z = lookAtZ;
pCamera->SetTarget(v3Target);
// pCamera->Move(v3Target);
UpdateViewMatrix();
// This is levites's virtual(?) code which you should not trust.
ms_lpd3dDevice->GetTransform(D3DTS_WORLD, &ms_matWorld);
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
}
void CGraphicBase::SetPositionCamera(float fx, float fy, float fz, float distance, float pitch, float roll)
{
// I wanna downward this code to the game control level. - [levites]
if (ms_dwWavingEndTime > CTimer::Instance().GetCurrentMillisecond())
{
if (ms_iWavingPower>0)
{
fx += float(rand() % ms_iWavingPower) / 10.0f;
fy += float(rand() % ms_iWavingPower) / 10.0f;
fz += float(rand() % ms_iWavingPower) / 10.0f;
}
}
CCamera * pCamera = CCameraManager::Instance().GetCurrentCamera();
if (!pCamera)
return;
pCamera->SetViewParams(D3DXVECTOR3(0.0f, -distance, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f));
pitch = fMIN(80.0f, fMAX(-80.0f, pitch) );
// Tracef("SetPosition Camera : %f, %f\n", pitch, roll);
pCamera->RotateEyeAroundTarget(pitch, roll);
pCamera->Move(D3DXVECTOR3(fx, fy, fz));
UpdateViewMatrix();
// This is levites's virtual(?) code which you should not trust.
STATEMANAGER.GetTransform(D3DTS_WORLD, &ms_matWorld);
D3DXMatrixMultiply(&ms_matWorldView, &ms_matWorld, &ms_matView);
}
void CGraphicBase::SetOrtho2D(float hres, float vres, float zres)
{
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_ORTHO_CAMERA);
D3DXMatrixOrthoOffCenterRH(&ms_matProj, 0, hres, vres, 0, 0, zres);
//UpdatePipeLineMatrix();
UpdateProjMatrix();
}
void CGraphicBase::SetOrtho3D(float hres, float vres, float zmin, float zmax)
{
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
D3DXMatrixOrthoRH(&ms_matProj, hres, vres, zmin, zmax);
//UpdatePipeLineMatrix();
UpdateProjMatrix();
}
void CGraphicBase::SetPerspective(float fov, float aspect, float nearz, float farz)
{
ms_fFieldOfView = fov;
//if (ms_d3dPresentParameter.BackBufferWidth>0 && ms_d3dPresentParameter.BackBufferHeight>0)
// ms_fAspect = float(ms_d3dPresentParameter.BackBufferWidth)/float(ms_d3dPresentParameter.BackBufferHeight);
//else
ms_fAspect = aspect;
ms_fNearY = nearz;
ms_fFarY = farz;
//CCameraManager::Instance().SetCurrentCamera(CCameraManager::DEFAULT_PERSPECTIVE_CAMERA);
D3DXMatrixPerspectiveFovRH(&ms_matProj, D3DXToRadian(fov), ms_fAspect, nearz, farz);
//UpdatePipeLineMatrix();
UpdateProjMatrix();
}
void CGraphicBase::UpdateProjMatrix()
{
STATEMANAGER.SetTransform(D3DTS_PROJECTION, &ms_matProj);
}
void CGraphicBase::UpdateViewMatrix()
{
CCamera* pkCamera=CCameraManager::Instance().GetCurrentCamera();
if (!pkCamera)
return;
ms_matView = pkCamera->GetViewMatrix();
STATEMANAGER.SetTransform(D3DTS_VIEW, &ms_matView);
D3DXMatrixInverse(&ms_matInverseView, NULL, &ms_matView);
ms_matInverseViewYAxis._11 = ms_matInverseView._11;
ms_matInverseViewYAxis._12 = ms_matInverseView._12;
ms_matInverseViewYAxis._21 = ms_matInverseView._21;
ms_matInverseViewYAxis._22 = ms_matInverseView._22;
}
void CGraphicBase::UpdatePipeLineMatrix()
{
UpdateProjMatrix();
UpdateViewMatrix();
}
void CGraphicBase::SetViewport(DWORD dwX, DWORD dwY, DWORD dwWidth, DWORD dwHeight, float fMinZ, float fMaxZ)
{
ms_Viewport.X = dwX;
ms_Viewport.Y = dwY;
ms_Viewport.Width = dwWidth;
ms_Viewport.Height = dwHeight;
ms_Viewport.MinZ = fMinZ;
ms_Viewport.MaxZ = fMaxZ;
}
void CGraphicBase::GetTargetPosition(float * px, float * py, float * pz)
{
*px = CCameraManager::Instance().GetCurrentCamera()->GetTarget().x;
*py = CCameraManager::Instance().GetCurrentCamera()->GetTarget().y;
*pz = CCameraManager::Instance().GetCurrentCamera()->GetTarget().z;
}
void CGraphicBase::GetCameraPosition(float * px, float * py, float * pz)
{
*px = CCameraManager::Instance().GetCurrentCamera()->GetEye().x;
*py = CCameraManager::Instance().GetCurrentCamera()->GetEye().y;
*pz = CCameraManager::Instance().GetCurrentCamera()->GetEye().z;
}
void CGraphicBase::GetMatrix(D3DXMATRIX* pRetMatrix) const
{
assert(ms_lpd3dMatStack != NULL);
*pRetMatrix = *ms_lpd3dMatStack->GetTop();
}
const D3DXMATRIX* CGraphicBase::GetMatrixPointer() const
{
assert(ms_lpd3dMatStack!=NULL);
return ms_lpd3dMatStack->GetTop();
}
void CGraphicBase::GetSphereMatrix(D3DXMATRIX * pMatrix, float fValue)
{
D3DXMatrixIdentity(pMatrix);
pMatrix->_11 = fValue * ms_matWorldView._11;
pMatrix->_21 = fValue * ms_matWorldView._21;
pMatrix->_31 = fValue * ms_matWorldView._31;
pMatrix->_41 = fValue;
pMatrix->_12 = -fValue * ms_matWorldView._12;
pMatrix->_22 = -fValue * ms_matWorldView._22;
pMatrix->_32 = -fValue * ms_matWorldView._32;
pMatrix->_42 = -fValue;
}
float CGraphicBase::GetFOV()
{
return ms_fFieldOfView;
}
void CGraphicBase::PushMatrix()
{
ms_lpd3dMatStack->Push();
}
void CGraphicBase::Scale(float x, float y, float z)
{
ms_lpd3dMatStack->Scale(x, y, z);
}
void CGraphicBase::Rotate(float degree, float x, float y, float z)
{
D3DXVECTOR3 vec(x, y, z);
ms_lpd3dMatStack->RotateAxis(&vec, D3DXToRadian(degree));
}
void CGraphicBase::RotateLocal(float degree, float x, float y, float z)
{
D3DXVECTOR3 vec(x, y, z);
ms_lpd3dMatStack->RotateAxisLocal(&vec, D3DXToRadian(degree));
}
void CGraphicBase::MultMatrix( const D3DXMATRIX* pMat)
{
ms_lpd3dMatStack->MultMatrix(pMat);
}
void CGraphicBase::MultMatrixLocal( const D3DXMATRIX* pMat)
{
ms_lpd3dMatStack->MultMatrixLocal(pMat);
}
void CGraphicBase::RotateYawPitchRollLocal(float fYaw, float fPitch, float fRoll)
{
ms_lpd3dMatStack->RotateYawPitchRollLocal(D3DXToRadian(fYaw), D3DXToRadian(fPitch), D3DXToRadian(fRoll));
}
void CGraphicBase::Translate(float x, float y, float z)
{
ms_lpd3dMatStack->Translate(x, y, z);
}
void CGraphicBase::LoadMatrix(const D3DXMATRIX& c_rSrcMatrix)
{
ms_lpd3dMatStack->LoadMatrix(&c_rSrcMatrix);
}
void CGraphicBase::PopMatrix()
{
ms_lpd3dMatStack->Pop();
}
DWORD CGraphicBase::GetColor(float r, float g, float b, float a)
{
BYTE argb[4] =
{
(BYTE) (255.0f * b),
(BYTE) (255.0f * g),
(BYTE) (255.0f * r),
(BYTE) (255.0f * a)
};
return *((DWORD *) argb);
}
void CGraphicBase::InitScreenEffect()
{
ms_dwWavingEndTime = 0;
ms_dwFlashingEndTime = 0;
ms_iWavingPower = 0;
ms_FlashingColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f);
}
void CGraphicBase::SetScreenEffectWaving(float fDuringTime, int iPower)
{
ms_dwWavingEndTime = CTimer::Instance().GetCurrentMillisecond() + long(fDuringTime * 1000.0f);
ms_iWavingPower = iPower;
}
void CGraphicBase::SetScreenEffectFlashing(float fDuringTime, const D3DXCOLOR & c_rColor)
{
ms_dwFlashingEndTime = CTimer::Instance().GetCurrentMillisecond() + long(fDuringTime * 1000.0f);
ms_FlashingColor = c_rColor;
}
DWORD CGraphicBase::GetFaceCount()
{
return ms_faceCount;
}
void CGraphicBase::ResetFaceCount()
{
ms_faceCount = 0;
}
HRESULT CGraphicBase::GetLastResult()
{
return ms_hLastResult;
}
CGraphicBase::CGraphicBase()
{
}
CGraphicBase::~CGraphicBase()
{
}

312
src/EterLib/GrpBase.h Normal file
View File

@ -0,0 +1,312 @@
#pragma once
#include "GrpDetector.h"
#include "Ray.h"
#include <vector>
void PixelPositionToD3DXVECTOR3(const D3DXVECTOR3& c_rkPPosSrc, D3DXVECTOR3* pv3Dst);
void D3DXVECTOR3ToPixelPosition(const D3DXVECTOR3& c_rv3Src, D3DXVECTOR3* pv3Dst);
class CGraphicTexture;
typedef WORD TIndex;
typedef struct SFace
{
TIndex indices[3];
} TFace;
typedef D3DXVECTOR3 TPosition;
typedef D3DXVECTOR3 TNormal;
typedef D3DXVECTOR2 TTextureCoordinate;
typedef DWORD TDiffuse;
typedef DWORD TAmbient;
typedef DWORD TSpecular;
typedef union UDepth
{
float f;
long l;
DWORD dw;
} TDepth;
typedef struct SVertex
{
float x, y, z;
DWORD color;
float u, v;
} TVertex;
struct STVertex
{
float x, y, z, rhw;
};
struct SPVertex
{
float x, y, z;
};
typedef struct SPDVertex
{
float x, y, z;
DWORD color;
} TPDVertex;
struct SPDTVertexRaw
{
float px, py, pz;
DWORD diffuse;
float u, v;
};
typedef struct SPTVertex
{
TPosition position;
TTextureCoordinate texCoord;
} TPTVertex;
typedef struct SPDTVertex
{
TPosition position;
TDiffuse diffuse;
TTextureCoordinate texCoord;
} TPDTVertex;
typedef struct SPNTVertex
{
TPosition position;
TNormal normal;
TTextureCoordinate texCoord;
} TPNTVertex;
typedef struct SPNT2Vertex
{
TPosition position;
TNormal normal;
TTextureCoordinate texCoord;
TTextureCoordinate texCoord2;
} TPNT2Vertex;
typedef struct SPDT2Vertex
{
TPosition position;
DWORD diffuse;
TTextureCoordinate texCoord;
TTextureCoordinate texCoord2;
} TPDT2Vertex;
typedef struct SNameInfo
{
DWORD name;
TDepth depth;
} TNameInfo;
typedef struct SBoundBox
{
float sx, sy, sz;
float ex, ey, ez;
int meshIndex;
int boneIndex;
} TBoundBox;
const WORD c_FillRectIndices[6] = { 0, 2, 1, 2, 3, 1 };
/*
enum EIndexCount
{
LINE_INDEX_COUNT = 2,
TRIANGLE_INDEX_COUNT = 2*3,
RECTANGLE_INDEX_COUNT = 2*4,
CUBE_INDEX_COUNT = 2*4*3,
FILLED_TRIANGLE_INDEX_COUNT = 3,
FILLED_RECTANGLE_INDEX_COUNT = 3*2,
FILLED_CUBE_INDEX_COUNT = 3*2*6,
};
*/
class CGraphicBase
{
public:
static DWORD GetAvailableTextureMemory();
static const D3DXMATRIX& GetViewMatrix();
static const D3DXMATRIX & GetIdentityMatrix();
enum
{
DEFAULT_IB_LINE,
DEFAULT_IB_LINE_TRI,
DEFAULT_IB_LINE_RECT,
DEFAULT_IB_LINE_CUBE,
DEFAULT_IB_FILL_TRI,
DEFAULT_IB_FILL_RECT,
DEFAULT_IB_FILL_CUBE,
DEFAULT_IB_NUM,
};
public:
CGraphicBase();
virtual ~CGraphicBase();
void SetSimpleCamera(float x, float y, float z, float pitch, float roll);
void SetEyeCamera(float xEye, float yEye, float zEye, float xCenter, float yCenter, float zCenter, float xUp, float yUp, float zUp);
void SetAroundCamera(float distance, float pitch, float roll, float lookAtZ = 0.0f);
void SetPositionCamera(float fx, float fy, float fz, float fDistance, float fPitch, float fRotation);
void MoveCamera(float fdeltax, float fdeltay, float fdeltaz);
void GetTargetPosition(float * px, float * py, float * pz);
void GetCameraPosition(float * px, float * py, float * pz);
void SetOrtho2D(float hres, float vres, float zres);
void SetOrtho3D(float hres, float vres, float zmin, float zmax);
void SetPerspective(float fov, float aspect, float nearz, float farz);
float GetFOV();
void GetClipPlane(float * fNearY, float * fFarY)
{
*fNearY = ms_fNearY;
*fFarY = ms_fFarY;
}
////////////////////////////////////////////////////////////////////////
void PushMatrix();
void MultMatrix( const D3DXMATRIX* pMat );
void MultMatrixLocal( const D3DXMATRIX* pMat );
void Translate(float x, float y, float z);
void Rotate(float degree, float x, float y, float z);
void RotateLocal(float degree, float x, float y, float z);
void RotateYawPitchRollLocal(float fYaw, float fPitch, float fRoll);
void Scale(float x, float y, float z);
void PopMatrix();
void LoadMatrix(const D3DXMATRIX & c_rSrcMatrix);
void GetMatrix(D3DXMATRIX * pRetMatrix) const;
const D3DXMATRIX * GetMatrixPointer() const;
// Special Routine
void GetSphereMatrix(D3DXMATRIX * pMatrix, float fValue = 0.1f);
////////////////////////////////////////////////////////////////////////
void InitScreenEffect();
void SetScreenEffectWaving(float fDuringTime, int iPower);
void SetScreenEffectFlashing(float fDuringTime, const D3DXCOLOR & c_rColor);
////////////////////////////////////////////////////////////////////////
DWORD GetColor(float r, float g, float b, float a = 1.0f);
DWORD GetFaceCount();
void ResetFaceCount();
HRESULT GetLastResult();
void UpdateProjMatrix();
void UpdateViewMatrix();
void SetViewport(DWORD dwX, DWORD dwY, DWORD dwWidth, DWORD dwHeight, float fMinZ, float fMaxZ);
static void GetBackBufferSize(UINT* puWidth, UINT* puHeight);
static bool IsTLVertexClipping();
static bool IsFastTNL();
static bool IsLowTextureMemory();
static bool IsHighTextureMemory();
static void SetDefaultIndexBuffer(UINT eDefIB);
static bool SetPDTStream(SPDTVertexRaw* pVertices, UINT uVtxCount);
static bool SetPDTStream(SPDTVertex* pVertices, UINT uVtxCount);
protected:
static D3DXMATRIX ms_matIdentity;
static D3DXMATRIX ms_matView;
static D3DXMATRIX ms_matProj;
static D3DXMATRIX ms_matInverseView;
static D3DXMATRIX ms_matInverseViewYAxis;
static D3DXMATRIX ms_matWorld;
static D3DXMATRIX ms_matWorldView;
protected:
//void UpdatePrePipeLineMatrix();
void UpdatePipeLineMatrix();
protected:
// <20><><EFBFBD><EFBFBD> D3DX Mesh <20><> (<28>÷<EFBFBD><C3B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ǥ<><C7A5>Ȱ <20><> <20><><EFBFBD><EFBFBD>)
static LPD3DXMESH ms_lpSphereMesh;
static LPD3DXMESH ms_lpCylinderMesh;
protected:
static HRESULT ms_hLastResult;
static int ms_iWidth;
static int ms_iHeight;
static UINT ms_iD3DAdapterInfo;
static UINT ms_iD3DDevInfo;
static UINT ms_iD3DModeInfo;
static D3D_CDisplayModeAutoDetector ms_kD3DDetector;
static HWND ms_hWnd;
static HDC ms_hDC;
static LPDIRECT3D8 ms_lpd3d;
static LPDIRECT3DDEVICE8 ms_lpd3dDevice;
static ID3DXMatrixStack* ms_lpd3dMatStack;
static D3DVIEWPORT8 ms_Viewport;
static DWORD ms_faceCount;
static D3DCAPS8 ms_d3dCaps;
static D3DPRESENT_PARAMETERS ms_d3dPresentParameter;
static DWORD ms_dwD3DBehavior;
static DWORD ms_ptVS;
static DWORD ms_pntVS;
static DWORD ms_pnt2VS;
static D3DXMATRIX ms_matScreen0;
static D3DXMATRIX ms_matScreen1;
static D3DXMATRIX ms_matScreen2;
//static D3DXMATRIX ms_matPrePipeLine;
static D3DXVECTOR3 ms_vtPickRayOrig;
static D3DXVECTOR3 ms_vtPickRayDir;
static float ms_fFieldOfView;
static float ms_fAspect;
static float ms_fNearY;
static float ms_fFarY;
// 2004.11.18.myevan.DynamicVertexBuffer<65><72> <20><>ü
/*
static std::vector<TIndex> ms_lineIdxVector;
static std::vector<TIndex> ms_lineTriIdxVector;
static std::vector<TIndex> ms_lineRectIdxVector;
static std::vector<TIndex> ms_lineCubeIdxVector;
static std::vector<TIndex> ms_fillTriIdxVector;
static std::vector<TIndex> ms_fillRectIdxVector;
static std::vector<TIndex> ms_fillCubeIdxVector;
*/
// Screen Effect - Waving, Flashing and so on..
static DWORD ms_dwWavingEndTime;
static int ms_iWavingPower;
static DWORD ms_dwFlashingEndTime;
static D3DXCOLOR ms_FlashingColor;
// Terrain picking<6E><67> Ray... CCamera <20>̿<EFBFBD><CCBF>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>.. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ray<61><79> <20><><EFBFBD><EFBFBD> <20>ʿ<EFBFBD>...
static CRay ms_Ray;
//
static bool ms_bSupportDXT;
static bool ms_isLowTextureMemory;
static bool ms_isHighTextureMemory;
enum
{
PDT_VERTEX_NUM = 16,
PDT_VERTEXBUFFER_NUM = 100,
};
static LPDIRECT3DVERTEXBUFFER8 ms_alpd3dPDTVB[PDT_VERTEXBUFFER_NUM];
static LPDIRECT3DINDEXBUFFER8 ms_alpd3dDefIB[DEFAULT_IB_NUM];
};

View File

@ -0,0 +1,240 @@
#include "StdAfx.h"
#include "GrpCollisionObject.h"
bool CGraphicCollisionObject::IntersectBoundBox(const D3DXMATRIX* c_pmatWorld, const TBoundBox& c_rboundBox, float* pu, float* pv, float* pt)
{
return IntersectCube(c_pmatWorld, c_rboundBox.sx, c_rboundBox.sy, c_rboundBox.sz, c_rboundBox.ex, c_rboundBox.ey, c_rboundBox.ez, ms_vtPickRayOrig, ms_vtPickRayDir, pu, pv, pt);
}
bool CGraphicCollisionObject::IntersectCube(const D3DXMATRIX* c_pmatWorld, float sx, float sy, float sz, float ex, float ey, float ez,
D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt)
{
TPosition posVertices[8];
posVertices[0] = TPosition(sx, sy, sz);
posVertices[1] = TPosition(ex, sy, sz);
posVertices[2] = TPosition(sx, ey, sz);
posVertices[3] = TPosition(ex, ey, sz);
posVertices[4] = TPosition(sx, sy, ez);
posVertices[5] = TPosition(ex, sy, ez);
posVertices[6] = TPosition(sx, ey, ez);
posVertices[7] = TPosition(ex, ey, ez);
static const WORD c_awFillCubeIndices[36] = {
0, 1, 2, 1, 3, 2,
2, 0, 6, 0, 4, 6,
0, 1, 4, 1, 5, 4,
1, 3, 5, 3, 7, 5,
3, 2, 7, 2, 6, 7,
4, 5, 6, 5, 7, 6,
};
return IntersectIndexedMesh(
c_pmatWorld,
posVertices,
sizeof(TPosition),
8,
c_awFillCubeIndices,
36,
RayOriginal,
RayDirection,
pu,
pv,
pt
);
}
const int c_iLimitVertexCount = 1024;
bool CGraphicCollisionObject::IntersectIndexedMesh(const D3DXMATRIX* c_pmatWorld, const void* vertices, int step, int vtxCount, const void* indices, int idxCount,
D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt)
{
static D3DXVECTOR3 s_v3PositionArray[c_iLimitVertexCount];
static DWORD s_dwPositionCount;
if (vtxCount > c_iLimitVertexCount)
{
Tracef("The vertex count of mesh which is worked collision detection is too much : %d / %d", vtxCount, c_iLimitVertexCount);
return false;
}
s_dwPositionCount = 0;
char* pcurVtx = (char*)vertices;
while (vtxCount--)
{
float* pos = (float*)pcurVtx;
D3DXVec3TransformCoord(&s_v3PositionArray[s_dwPositionCount++], (D3DXVECTOR3*)pos, c_pmatWorld);
pcurVtx += step;
}
WORD* pcurIdx = (WORD*)indices;
int triCount = idxCount / 3;
while (triCount--)
{
if (IntersectTriangle(RayOriginal, RayDirection,
s_v3PositionArray[pcurIdx[0]],
s_v3PositionArray[pcurIdx[1]],
s_v3PositionArray[pcurIdx[2]],
pu, pv, pt))
{
return true;
}
pcurIdx += 3;
}
return false;
}
bool CGraphicCollisionObject::IntersectMesh(const D3DXMATRIX * c_pmatWorld, const void * vertices, DWORD dwStep, DWORD dwvtxCount, D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt)
{
char * pcurVtx = (char *) vertices;
D3DXVECTOR3 v3Vertex[3];
for (DWORD i = 0; i < dwvtxCount; i += 3)
{
D3DXVec3TransformCoord(&v3Vertex[0], (D3DXVECTOR3*)pcurVtx, c_pmatWorld);
pcurVtx += dwStep;
D3DXVec3TransformCoord(&v3Vertex[1], (D3DXVECTOR3*)pcurVtx, c_pmatWorld);
pcurVtx += dwStep;
D3DXVec3TransformCoord(&v3Vertex[2], (D3DXVECTOR3*)pcurVtx, c_pmatWorld);
pcurVtx += dwStep;
if (IntersectTriangle(RayOriginal, RayDirection,
v3Vertex[0], v3Vertex[1], v3Vertex[2],
pu, pv, pt))
{
return true;
}
}
return false;
}
bool CGraphicCollisionObject::IntersectTriangle(const D3DXVECTOR3& c_orig,
const D3DXVECTOR3& c_dir,
const D3DXVECTOR3& c_v0,
const D3DXVECTOR3& c_v1,
const D3DXVECTOR3& c_v2,
float * pu,
float * pv,
float * pt)
{
D3DXVECTOR3 edge1 = c_v1 - c_v0;
D3DXVECTOR3 edge2 = c_v2 - c_v0;
D3DXVECTOR3 pvec;
D3DXVec3Cross(&pvec, &c_dir, &edge2);
FLOAT det = D3DXVec3Dot(&edge1, &pvec);
D3DXVECTOR3 tvec;
if (det > 0)
{
tvec = c_orig - c_v0;
}
else
{
tvec = c_v0 - c_orig;
det = -det;
}
if (det < 0.0001f)
return false;
float u, v, t;
u = D3DXVec3Dot(&tvec, &pvec);
if (u < 0.0f || u > det)
return false;
D3DXVECTOR3 qvec;
D3DXVec3Cross(&qvec, &tvec, &edge1);
v = D3DXVec3Dot(&c_dir, &qvec);
if (v < 0.0f || u + v > det)
return false;
t = D3DXVec3Dot(&edge2, &qvec);
FLOAT fInvDet = 1.0f / det;
t *= fInvDet;
u *= fInvDet;
v *= fInvDet;
D3DXVECTOR3 spot = edge1 * u + edge2 * v;
spot += c_v0;
*pu = spot.x;
*pv = spot.y;
*pt = t;
return true;
}
bool CGraphicCollisionObject::IntersectSphere(const D3DXVECTOR3 & c_rv3Position, float fRadius, const D3DXVECTOR3 & c_rv3RayOriginal, const D3DXVECTOR3 & c_rv3RayDirection)
{
D3DXVECTOR3 v3RayOriginal = c_rv3RayOriginal - c_rv3Position;
float a = D3DXVec3Dot(&c_rv3RayDirection, &c_rv3RayDirection);
float b = 2 * D3DXVec3Dot(&v3RayOriginal, &c_rv3RayDirection);
float c = D3DXVec3Dot(&v3RayOriginal, &v3RayOriginal) - fRadius * fRadius;
float D = b * b - 4 * a * c;
if (D >= 0)
return true;
return false;
}
bool CGraphicCollisionObject::IntersectCylinder(const D3DXVECTOR3 & c_rv3Position, float fRadius, float fHeight, const D3DXVECTOR3 & c_rv3RayOriginal, const D3DXVECTOR3 & c_rv3RayDirection)
{
D3DXVECTOR3 v3RayOriginal = c_rv3RayOriginal - c_rv3Position;
float a = c_rv3RayDirection.x * c_rv3RayDirection.x + c_rv3RayDirection.y * c_rv3RayDirection.y;
float b = 2 * (v3RayOriginal.x * c_rv3RayDirection.x + v3RayOriginal.y * c_rv3RayDirection.y);
float c = v3RayOriginal.x * v3RayOriginal.x + v3RayOriginal.y * v3RayOriginal.y - fRadius*fRadius;
float D = b * b - 4 * a * c;
if (D > 0)
if (0.0f != a)
{
float tPlus = (-b + sqrtf(D)) / (2 * a);
float tMinus = (-b - sqrtf(D)) / (2 * a);
float fzPlus = v3RayOriginal.z + tPlus * c_rv3RayDirection.z;
float fzMinus = v3RayOriginal.z + tMinus * c_rv3RayDirection.z;
if (fzPlus > 0.0f && fzPlus <= fHeight)
return true;
if (fzMinus > 0.0f && fzMinus <= fHeight)
return true;
if (fzMinus * fzPlus < 0.0f)
return true;
}
return false;
}
bool CGraphicCollisionObject::IntersectSphere(const D3DXVECTOR3 & c_rv3Position, float fRadius)
{
return CGraphicCollisionObject::IntersectSphere(c_rv3Position, fRadius, ms_vtPickRayOrig, ms_vtPickRayDir);
}
bool CGraphicCollisionObject::IntersectCylinder(const D3DXVECTOR3 & c_rv3Position, float fRadius, float fHeight)
{
return CGraphicCollisionObject::IntersectCylinder(c_rv3Position, fRadius, fHeight, ms_vtPickRayOrig, ms_vtPickRayDir);
}
CGraphicCollisionObject::CGraphicCollisionObject()
{
}
CGraphicCollisionObject::~CGraphicCollisionObject()
{
}

View File

@ -0,0 +1,25 @@
#pragma once
#include "GrpBase.h"
class CGraphicCollisionObject : public CGraphicBase
{
public:
CGraphicCollisionObject();
virtual ~CGraphicCollisionObject();
protected:
bool IntersectTriangle(const D3DXVECTOR3& c_orig, const D3DXVECTOR3& c_dir, const D3DXVECTOR3& c_v0, const D3DXVECTOR3& c_v1, const D3DXVECTOR3& c_v2, float* pu, float* pv, float* pt);
bool IntersectBoundBox(const D3DXMATRIX* c_pmatWorld, const TBoundBox& c_rboundBox, float* pu, float* pv, float* pt);
bool IntersectCube(const D3DXMATRIX* c_pmatWorld, float sx, float sy, float sz, float ex, float ey, float ez, D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt);
bool IntersectIndexedMesh(const D3DXMATRIX* c_pmatWorld, const void* vertices, int step, int vtxCount, const void* indices, int idxCount, D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt);
bool IntersectMesh(const D3DXMATRIX * c_pmatWorld, const void * vertices, DWORD dwStep, DWORD dwvtxCount, D3DXVECTOR3 & RayOriginal, D3DXVECTOR3 & RayDirection, float* pu, float* pv, float* pt);
bool IntersectSphere(const D3DXVECTOR3 & c_rv3Position, float fRadius, const D3DXVECTOR3 & c_rv3RayOriginal, const D3DXVECTOR3 & c_rv3RayDirection);
bool IntersectCylinder(const D3DXVECTOR3 & c_rv3Position, float fRadius, float fHeight, const D3DXVECTOR3 & c_rv3RayOriginal, const D3DXVECTOR3 & c_rv3RayDirection);
// NOTE : ms_vtPickRayOrig<69><67> ms_vtPickRayDir<69><72> CGraphicBGase<73><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִµ<D6B4>
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ڷ<EFBFBD> <20>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD> <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ°<D6B4>? Customize<7A><65> <20><><EFBFBD>ؼ<EFBFBD>? - [levites]
bool IntersectSphere(const D3DXVECTOR3 & c_rv3Position, float fRadius);
bool IntersectCylinder(const D3DXVECTOR3 & c_rv3Position, float fRadius, float fHeight);
};

77
src/EterLib/GrpColor.cpp Normal file
View File

@ -0,0 +1,77 @@
#include "StdAfx.h"
#include "GrpColor.h"
CGraphicColor::CGraphicColor()
{
Clear();
}
CGraphicColor::CGraphicColor(const CGraphicColor& c_rSrcColor)
{
Set(c_rSrcColor);
}
CGraphicColor::CGraphicColor(float r, float g, float b, float a)
{
Set(r, g, b, a);
}
CGraphicColor::CGraphicColor(DWORD color)
{
Set(color);
}
CGraphicColor::~CGraphicColor()
{
}
void CGraphicColor::Clear()
{
Set(1.0f, 1.0f, 1.0f, 1.0f);
}
void CGraphicColor::Set(float r, float g, float b, float a)
{
m_r=r;
m_g=g;
m_b=b;
m_a=a;
}
void CGraphicColor::Set(const CGraphicColor& c_rSrcColor)
{
m_r=c_rSrcColor.m_r;
m_g=c_rSrcColor.m_g;
m_b=c_rSrcColor.m_b;
m_a=c_rSrcColor.m_a;
}
void CGraphicColor::Blend(float p, const CGraphicColor& c_rSrcColor, const CGraphicColor& c_rDstColor)
{
float q=1.0f-p;
m_r=c_rSrcColor.m_r*q+c_rDstColor.m_r*p;
m_g=c_rSrcColor.m_g*q+c_rDstColor.m_g*p;
m_b=c_rSrcColor.m_b*q+c_rDstColor.m_b*p;
m_a=c_rSrcColor.m_a*q+c_rDstColor.m_a*p;
}
void CGraphicColor::Set(DWORD pack)
{
m_b = (pack & 0xff) / 255.0f; pack >>= 8;
m_g = (pack & 0xff) / 255.0f; pack >>= 8;
m_r = (pack & 0xff) / 255.0f; pack >>= 8;
m_a = (pack) / 255.0f;
}
DWORD CGraphicColor::GetPackValue() const
{
DWORD packValue=0;
packValue = int(255.0f * m_a);packValue <<= 8;
packValue |= int(255.0f * m_r);packValue <<= 8;
packValue |= int(255.0f * m_g);packValue <<= 8;
packValue |= int(255.0f * m_b);
return packValue;
}

28
src/EterLib/GrpColor.h Normal file
View File

@ -0,0 +1,28 @@
#pragma once
class CGraphicColor
{
public:
CGraphicColor(const CGraphicColor& c_rSrcColor);
CGraphicColor(float r, float g, float b, float a);
CGraphicColor(DWORD color);
CGraphicColor();
~CGraphicColor();
void Clear();
void Set(float r, float g, float b, float a);
void Set(const CGraphicColor& c_rSrcColor);
void Set(DWORD color);
void Blend(float p, const CGraphicColor& c_rSrcColor, const CGraphicColor& c_rDstColor);
DWORD GetPackValue() const;
protected:
float m_r;
float m_g;
float m_b;
float m_a;
};

View File

@ -0,0 +1,65 @@
#include "StdAfx.h"
#include "GrpColorInstance.h"
#include "../eterBase/Timer.h"
CGraphicColorInstance::CGraphicColorInstance()
{
m_baseTime=0;
m_blendTime=0;
}
CGraphicColorInstance::~CGraphicColorInstance()
{
}
void CGraphicColorInstance::Clear()
{
m_srcColor.Clear();
m_dstColor.Clear();
m_curColor.Clear();
m_baseTime=0;
m_blendTime=0;
}
void CGraphicColorInstance::SetColorReference(const CGraphicColor & c_rSrcColor)
{
m_srcColor = c_rSrcColor;
m_dstColor = c_rSrcColor;
m_curColor = c_rSrcColor;
}
void CGraphicColorInstance::BlendColorReference(DWORD blendTime, const CGraphicColor& c_rDstColor)
{
m_baseTime = GetCurrentTime();
m_blendTime = blendTime;
m_srcColor = m_curColor;
m_dstColor = c_rDstColor;
}
void CGraphicColorInstance::Update()
{
DWORD curTime = GetCurrentTime();
DWORD elapsedTime = curTime - m_baseTime;
if (elapsedTime < m_blendTime)
{
m_curColor.Blend(elapsedTime/float(m_blendTime), m_srcColor, m_dstColor);
}
else
{
m_curColor=m_dstColor;
}
}
DWORD CGraphicColorInstance::GetCurrentTime()
{
return CTimer::Instance().GetCurrentMillisecond();
}
const CGraphicColor& CGraphicColorInstance::GetCurrentColorReference() const
{
return m_curColor;
}

View File

@ -0,0 +1,33 @@
#pragma once
#include "GrpColor.h"
#include "Pool.h"
class CGraphicColorInstance
{
public:
CGraphicColorInstance();
virtual ~CGraphicColorInstance();
void Clear();
void SetColorReference(const CGraphicColor& c_rSrcColor);
void BlendColorReference(DWORD blendTime, const CGraphicColor& c_rDstColor);
void Update();
const CGraphicColor& GetCurrentColorReference() const;
protected:
DWORD GetCurrentTime();
protected:
CGraphicColor m_srcColor;
CGraphicColor m_dstColor;
CGraphicColor m_curColor;
DWORD m_baseTime;
DWORD m_blendTime;
};
typedef CDynamicPool<CGraphicColorInstance> TGraphicColorInstancePool;

View File

@ -0,0 +1,41 @@
#include "StdAfx.h"
#include "GrpD3DXBuffer.h"
#include "../eterBase/Stl.h"
CDirect3DXBuffer::CDirect3DXBuffer()
{
m_lpd3dxBuffer=NULL;
}
CDirect3DXBuffer::CDirect3DXBuffer(LPD3DXBUFFER lpd3dxBuffer)
{
m_lpd3dxBuffer=lpd3dxBuffer;
}
CDirect3DXBuffer::~CDirect3DXBuffer()
{
Destroy();
}
void CDirect3DXBuffer::Destroy()
{
safe_release(m_lpd3dxBuffer);
}
void CDirect3DXBuffer::Create(LPD3DXBUFFER lpd3dxBuffer)
{
Destroy();
m_lpd3dxBuffer=lpd3dxBuffer;
}
void*CDirect3DXBuffer::GetPointer()
{
assert(m_lpd3dxBuffer!=NULL);
return m_lpd3dxBuffer->GetBufferPointer();
}
int CDirect3DXBuffer::GetSize()
{
assert(m_lpd3dxBuffer!=NULL);
return m_lpd3dxBuffer->GetBufferSize();
}

View File

@ -0,0 +1,18 @@
#pragma once
class CDirect3DXBuffer
{
public:
CDirect3DXBuffer();
CDirect3DXBuffer(LPD3DXBUFFER lpd3dxBuffer);
virtual ~CDirect3DXBuffer();
void Destroy();
void Create(LPD3DXBUFFER lpd3dxBuffer);
void*GetPointer();
int GetSize();
protected:
LPD3DXBUFFER m_lpd3dxBuffer;
};

114
src/EterLib/GrpDIB.cpp Normal file
View File

@ -0,0 +1,114 @@
#include "StdAfx.h"
#include "GrpDIB.h"
CGraphicDib::CGraphicDib()
{
Initialize();
}
CGraphicDib::~CGraphicDib()
{
Destroy();
}
void CGraphicDib::Initialize()
{
m_hDC=NULL;
m_hBmp=NULL;
m_pvBuf=NULL;
m_width=0;
m_height=0;
}
void CGraphicDib::Destroy()
{
if (m_hBmp) DeleteObject(m_hBmp);
if (m_hDC) DeleteDC(m_hDC);
Initialize();
}
bool CGraphicDib::Create(HDC hDC, int width, int height)
{
Destroy();
m_width = width;
m_height = height;
ZeroMemory(&m_bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_bmi.bmiHeader.biWidth = m_width;
m_bmi.bmiHeader.biHeight = -m_height;
m_bmi.bmiHeader.biPlanes = 1;
m_bmi.bmiHeader.biBitCount = 32;
m_bmi.bmiHeader.biCompression = BI_RGB;
m_hDC=CreateCompatibleDC(hDC);
if (!m_hDC)
{
assert(!"CGraphicDib::Create CreateCompatibleDC Error");
return false;
}
m_hBmp=CreateDIBSection(m_hDC, &m_bmi, DIB_RGB_COLORS, &m_pvBuf, NULL, 0);
if (!m_hBmp)
{
assert(!"CGraphicDib::Create CreateDIBSection Error");
return false;
}
SelectObject(m_hDC, m_hBmp);
::SetTextColor(m_hDC, RGB(255, 255, 255));
return true;
}
HDC CGraphicDib::GetDCHandle()
{
return m_hDC;
}
void CGraphicDib::SetBkMode(int iBkMode)
{
::SetBkMode(m_hDC, iBkMode);
}
void CGraphicDib::TextOut(int ix, int iy, const char * c_szText)
{
::SetBkColor(m_hDC, 0);
::TextOut(m_hDC, ix, iy, c_szText, strlen(c_szText));
}
void CGraphicDib::Put(HDC hDC, int x, int y)
{
SetDIBitsToDevice(
hDC,
x,
y,
m_width,
m_height,
0,
0,
0,
m_height,
m_pvBuf,
&m_bmi,
DIB_RGB_COLORS
);
}
void* CGraphicDib::GetPointer()
{
return m_pvBuf;
}
int CGraphicDib::GetWidth()
{
return m_width;
}
int CGraphicDib::GetHeight()
{
return m_height;
}

35
src/EterLib/GrpDIB.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
class CGraphicDib
{
public:
CGraphicDib();
virtual ~CGraphicDib();
void Destroy();
bool Create(HDC hDC, int width, int height);
void SetBkMode(int iBkMode);
void TextOut(int ix, int iy, const char * c_szText);
void Put(HDC hDC, int x, int y);
int GetWidth();
int GetHeight();
void* GetPointer();
HDC GetDCHandle();
protected:
void Initialize();
protected:
HDC m_hDC;
HBITMAP m_hBmp;
BITMAPINFO m_bmi;
int m_width;
int m_height;
void * m_pvBuf;
};

647
src/EterLib/GrpDetector.cpp Normal file
View File

@ -0,0 +1,647 @@
#include "StdAfx.h"
#include "../eterBase/Stl.h"
#include "GrpDetector.h"
struct FIsEqualD3DDisplayMode
{
FIsEqualD3DDisplayMode(D3DDISPLAYMODE* pkD3DDMChk)
{
m_pkD3DDMChk=pkD3DDMChk;
}
BOOL operator() (D3DDISPLAYMODE& rkD3DDMTest)
{
if (rkD3DDMTest.Width!=m_pkD3DDMChk->Width)
return FALSE;
if (rkD3DDMTest.Height!=m_pkD3DDMChk->Height)
return FALSE;
if (rkD3DDMTest.Format!=m_pkD3DDMChk->Format)
return FALSE;
return TRUE;
}
D3DDISPLAYMODE* m_pkD3DDMChk;
};
static int CompareD3DDisplayModeOrder( const VOID* arg1, const VOID* arg2 )
{
D3DDISPLAYMODE* p1 = (D3DDISPLAYMODE*)arg1;
D3DDISPLAYMODE* p2 = (D3DDISPLAYMODE*)arg2;
if( p1->Format > p2->Format ) return -1;
if( p1->Format < p2->Format ) return +1;
if( p1->Width < p2->Width ) return -1;
if( p1->Width > p2->Width ) return +1;
if( p1->Height < p2->Height ) return -1;
if( p1->Height > p2->Height ) return +1;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
UINT D3D_CAdapterDisplayModeList::GetDisplayModeNum()
{
return m_uD3DDMNum;
}
UINT D3D_CAdapterDisplayModeList::GetPixelFormatNum()
{
return m_uD3DFmtNum;
}
const D3DDISPLAYMODE& D3D_CAdapterDisplayModeList::GetDisplayModer(UINT iD3DDM)
{
assert(iD3DDM<m_uD3DDMNum);
return m_akD3DDM[iD3DDM];
}
const D3DFORMAT& D3D_CAdapterDisplayModeList::GetPixelFormatr(UINT iD3DFmt)
{
assert(iD3DFmt<m_uD3DFmtNum);
return m_aeD3DFmt[iD3DFmt];
}
VOID D3D_CAdapterDisplayModeList::Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iD3DAdapterInfo)
{
D3DDISPLAYMODE* akD3DDM=m_akD3DDM;
D3DFORMAT* aeD3DFmt=m_aeD3DFmt;
UINT uD3DDMNum=0;
UINT uD3DFmtNum=0;
aeD3DFmt[uD3DFmtNum++]=eD3DFmtDefault;
UINT uAdapterModeNum=rkD3D.GetAdapterModeCount(iD3DAdapterInfo);
for (UINT iD3DAdapterInfoMode=0; iD3DAdapterInfoMode<uAdapterModeNum; iD3DAdapterInfoMode++)
{
D3DDISPLAYMODE kD3DDMCur;
rkD3D.EnumAdapterModes(iD3DAdapterInfo, iD3DAdapterInfoMode, &kD3DDMCur);
// IsFilterOutLowResolutionMode
if( kD3DDMCur.Width < FILTEROUT_LOWRESOLUTION_WIDTH || kD3DDMCur.Height < FILTEROUT_LOWRESOLUTION_HEIGHT )
continue;
// FindDisplayMode
D3DDISPLAYMODE* pkD3DDMEnd=akD3DDM+uD3DDMNum;
D3DDISPLAYMODE* pkD3DDMFind=std::find_if(akD3DDM, pkD3DDMEnd, FIsEqualD3DDisplayMode(&kD3DDMCur));
// IsNewDisplayMode
if (pkD3DDMFind==pkD3DDMEnd && uD3DDMNum<D3DDISPLAYMODE_MAX)
{
D3DDISPLAYMODE& rkD3DDMNew=akD3DDM[uD3DDMNum++];
rkD3DDMNew.Width=kD3DDMCur.Width;
rkD3DDMNew.Height=kD3DDMCur.Height;
rkD3DDMNew.Format=kD3DDMCur.Format;
// FindFormat
D3DFORMAT* peD3DFmtEnd=aeD3DFmt+uD3DFmtNum;
D3DFORMAT* peD3DFmtFind=std::find(aeD3DFmt, peD3DFmtEnd, kD3DDMCur.Format);
// IsNewFormat
if (peD3DFmtFind==peD3DFmtEnd && uD3DFmtNum<D3DFORMAT_MAX)
{
aeD3DFmt[uD3DFmtNum++]=kD3DDMCur.Format;
}
}
}
qsort(akD3DDM, uD3DDMNum, sizeof(D3DDISPLAYMODE), CompareD3DDisplayModeOrder);
m_uD3DFmtNum=uD3DFmtNum;
m_uD3DDMNum=uD3DDMNum;
}
/////////////////////////////////////////////////////////////////////////////////
VOID D3D_SModeInfo::GetString(std::string* pstEnumList)
{
UINT uScrDepthBits=16;
switch (m_eD3DFmtPixel)
{
case D3DFMT_X8R8G8B8:
case D3DFMT_A8R8G8B8:
case D3DFMT_R8G8B8:
uScrDepthBits=32;
break;
}
int iVP=0;
switch (m_dwD3DBehavior)
{
case D3DCREATE_HARDWARE_VERTEXPROCESSING:
iVP=1;
break;
case D3DCREATE_MIXED_VERTEXPROCESSING:
iVP=2;
break;
case D3DCREATE_SOFTWARE_VERTEXPROCESSING:
iVP=3;
break;
}
static const char* szVP[4]=
{
"UNKNOWN",
"HWVP",
"MXVP",
"SWVP",
};
char szText[1024+1];
_snprintf(szText, sizeof(szText), "%dx%dx%d %s\r\n", m_uScrWidth, m_uScrHeight, uScrDepthBits, szVP[iVP]);
pstEnumList->append(szText);
}
/////////////////////////////////////////////////////////////////////////////////
const CHAR* D3D_CDeviceInfo::msc_aszD3DDevDesc[D3DDEVICETYPE_NUM] = {"HAL", "REF"};
const D3DDEVTYPE D3D_CDeviceInfo::msc_aeD3DDevType[D3DDEVICETYPE_NUM]={D3DDEVTYPE_HAL, D3DDEVTYPE_REF};
UINT D3D_CDeviceInfo::GetD3DModeInfoNum()
{
return m_uD3DModeInfoNum;
}
D3D_SModeInfo* D3D_CDeviceInfo::GetD3DModeInfop(UINT iD3D_SModeInfo)
{
if (iD3D_SModeInfo >= m_uD3DModeInfoNum)
return NULL;
return &m_akD3DModeInfo[iD3D_SModeInfo];
}
BOOL D3D_CDeviceInfo::FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat )
{
UINT m_dwMinDepthBits = 16;
UINT m_dwMinStencilBits = 0;
if( m_dwMinDepthBits <= 16 && m_dwMinStencilBits == 0 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D16 ) ) )
{
*pDepthStencilFormat = D3DFMT_D16;
return TRUE;
}
}
}
if( m_dwMinDepthBits <= 15 && m_dwMinStencilBits <= 1 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D15S1 ) ) )
{
*pDepthStencilFormat = D3DFMT_D15S1;
return TRUE;
}
}
}
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits == 0 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D24X8 ) ) )
{
*pDepthStencilFormat = D3DFMT_D24X8;
return TRUE;
}
}
}
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 8 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D24S8 ) ) )
{
*pDepthStencilFormat = D3DFMT_D24S8;
return TRUE;
}
}
}
if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 4 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D24X4S4 ) ) )
{
*pDepthStencilFormat = D3DFMT_D24X4S4;
return TRUE;
}
}
}
if( m_dwMinDepthBits <= 32 && m_dwMinStencilBits == 0 )
{
if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType,
TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32 ) ) )
{
if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType,
TargetFormat, TargetFormat, D3DFMT_D32 ) ) )
{
*pDepthStencilFormat = D3DFMT_D32;
return TRUE;
}
}
}
return FALSE;
}
BOOL D3D_CDeviceInfo::Build(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, BOOL (*pfnConfirmDevice)(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt))
{
assert(pfnConfirmDevice!=NULL && "D3D_CDeviceInfo::Build");
const D3DDEVTYPE c_eD3DDevType=msc_aeD3DDevType[iDevType];
const TCHAR* c_szD3DDevDesc=msc_aszD3DDevDesc[iDevType];
m_eD3DDevType = c_eD3DDevType;
rkD3D.GetDeviceCaps(iD3DAdapterInfo, c_eD3DDevType, &m_kD3DCaps);
m_szDevDesc = c_szD3DDevDesc;
m_uD3DModeInfoNum=0;
m_canDoWindowed = FALSE;
m_isWindowed = FALSE;
m_eD3DMSTFullscreen = D3DMULTISAMPLE_NONE;
m_eD3DMSTWindowed = D3DMULTISAMPLE_NONE;
BOOL aisFormatConfirmed[20];
DWORD adwD3DBehavior[20];
D3DFORMAT aeD3DFmtDepthStencil[20];
BOOL isHALExists = FALSE;
BOOL isHALWindowedCompatible = FALSE;
BOOL isHALDesktopCompatible = FALSE;
BOOL isHALSampleCompatible = FALSE;
// GetFlagInfo
{
UINT uD3DFmtNum=rkD3DADMList.GetPixelFormatNum();
for (DWORD iFmt=0; iFmt<uD3DFmtNum; ++iFmt)
{
D3DFORMAT eD3DFmtPixel=rkD3DADMList.GetPixelFormatr(iFmt);
DWORD dwD3DBehavior=0;
BOOL isFormatConfirmed=FALSE;
aeD3DFmtDepthStencil[iFmt] = D3DFMT_UNKNOWN;
// SkipNoRenderTargetFormat;
if (FAILED(rkD3D.CheckDeviceType(iD3DAdapterInfo, m_eD3DDevType, eD3DFmtPixel, eD3DFmtPixel, FALSE)))
continue;
if (D3DDEVTYPE_HAL==m_eD3DDevType)
{
isHALExists=TRUE;
if (m_kD3DCaps.Caps2 & D3DCAPS2_CANRENDERWINDOWED)
{
isHALWindowedCompatible=TRUE;
if (iFmt==0)
isHALDesktopCompatible=TRUE;
}
}
// Confirm the device/format for HW vertex processing
if (m_kD3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
if (m_kD3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)
{
dwD3DBehavior=D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_PUREDEVICE;
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
isFormatConfirmed = TRUE;
}
if (FALSE == isFormatConfirmed)
{
dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
isFormatConfirmed = TRUE;
}
if (FALSE == isFormatConfirmed)
{
dwD3DBehavior = D3DCREATE_MIXED_VERTEXPROCESSING;
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
isFormatConfirmed = TRUE;
}
}
// Confirm the device/format for SW vertex processing
if (FALSE == isFormatConfirmed)
{
dwD3DBehavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
if (pfnConfirmDevice(m_kD3DCaps, dwD3DBehavior, eD3DFmtPixel))
isFormatConfirmed = TRUE;
}
if (isFormatConfirmed)
{
if (!FindDepthStencilFormat(rkD3D, iD3DAdapterInfo, c_eD3DDevType, eD3DFmtPixel, &aeD3DFmtDepthStencil[iFmt]))
isFormatConfirmed = TRUE;
}
adwD3DBehavior[iFmt]=dwD3DBehavior;
aisFormatConfirmed[iFmt]=isFormatConfirmed;
}
}
// BuildModeInfoList
{
UINT uD3DDMNum=rkD3DADMList.GetDisplayModeNum();
UINT uD3DFmtNum=rkD3DADMList.GetPixelFormatNum();
for (UINT iD3DDM=0; iD3DDM<uD3DDMNum; ++iD3DDM)
{
const D3DDISPLAYMODE& c_rkD3DDM=rkD3DADMList.GetDisplayModer(iD3DDM);
for (DWORD iFmt=0; iFmt<uD3DFmtNum; ++iFmt)
{
if (rkD3DADMList.GetPixelFormatr(iFmt)==c_rkD3DDM.Format)
{
if (aisFormatConfirmed[iFmt] == TRUE )
{
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[m_uD3DModeInfoNum++];
rkModeInfo.m_uScrWidth=c_rkD3DDM.Width;
rkModeInfo.m_uScrHeight=c_rkD3DDM.Height;
rkModeInfo.m_eD3DFmtPixel=c_rkD3DDM.Format;
rkModeInfo.m_dwD3DBehavior=adwD3DBehavior[iFmt];
rkModeInfo.m_eD3DFmtDepthStencil=aeD3DFmtDepthStencil[iFmt];
if( m_eD3DDevType == D3DDEVTYPE_HAL )
isHALSampleCompatible = TRUE;
}
}
}
}
}
// Check if the device is compatible with the desktop display mode
// (which was added initially as formats[0])
if (aisFormatConfirmed[0] && (m_kD3DCaps.Caps2 & D3DCAPS2_CANRENDERWINDOWED) )
{
m_canDoWindowed=TRUE;
m_isWindowed=TRUE;
}
if (m_uD3DModeInfoNum>0)
return TRUE;
return FALSE;
}
BOOL D3D_CDeviceInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo)
{
if (isWindowed)
if (!m_isWindowed)
return FALSE;
for (UINT iD3D_SModeInfo=0; iD3D_SModeInfo<m_uD3DModeInfoNum; ++iD3D_SModeInfo)
{
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[iD3D_SModeInfo];
if (rkModeInfo.m_uScrWidth==uScrWidth && rkModeInfo.m_uScrHeight==uScrHeight)
{
if (uScrDepthBits==16)
{
switch (rkModeInfo.m_eD3DFmtPixel)
{
case D3DFMT_R5G6B5:
case D3DFMT_X1R5G5B5:
case D3DFMT_A1R5G5B5:
*piD3DModeInfo=iD3D_SModeInfo;
return TRUE;
break;
}
}
else
{
switch (rkModeInfo.m_eD3DFmtPixel)
{
case D3DFMT_X8R8G8B8:
case D3DFMT_A8R8G8B8:
case D3DFMT_R8G8B8:
*piD3DModeInfo=iD3D_SModeInfo;
return TRUE;
break;
}
}
}
}
return FALSE;
}
VOID D3D_CDeviceInfo::GetString(std::string* pstEnumList)
{
char szText[1024+1];
_snprintf(szText, sizeof(szText), "%s\r\n========================================\r\n", m_szDevDesc);
pstEnumList->append(szText);
for (UINT iD3D_SModeInfo=0; iD3D_SModeInfo<m_uD3DModeInfoNum; ++iD3D_SModeInfo)
{
_snprintf(szText, sizeof(szText), "%d. ", iD3D_SModeInfo);
pstEnumList->append(szText);
D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[iD3D_SModeInfo];
rkModeInfo.GetString(pstEnumList);
}
pstEnumList->append("\r\n");
}
/////////////////////////////////////////////////////////////////////////////
D3DDISPLAYMODE& D3D_CAdapterInfo::GetDesktopD3DDisplayModer()
{
return m_kD3DDMDesktop;
}
D3DDISPLAYMODE* D3D_CAdapterInfo::GetDesktopD3DDisplayModep()
{
return &m_kD3DDMDesktop;
}
D3D_CDeviceInfo* D3D_CAdapterInfo::GetD3DDeviceInfop(UINT iD3DDevInfo)
{
if (iD3DDevInfo >= m_uD3DDevInfoNum)
return NULL;
return &m_akD3DDevInfo[iD3DDevInfo];
}
D3D_SModeInfo* D3D_CAdapterInfo::GetD3DModeInfop(UINT iD3DDevInfo, UINT iD3D_SModeInfo)
{
D3D_CDeviceInfo* pkD3DDevInfo=GetD3DDeviceInfop(iD3DDevInfo);
if (pkD3DDevInfo)
{
D3D_SModeInfo* pkD3DModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo);
if (pkD3DModeInfo)
return pkD3DModeInfo;
}
return NULL;
}
BOOL D3D_CAdapterInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo)
{
for (UINT iDevInfo=0; iDevInfo<m_uD3DDevInfoNum; ++iDevInfo)
{
D3D_CDeviceInfo& rkD3DDevInfo=m_akD3DDevInfo[iDevInfo];
if (rkD3DDevInfo.Find(uScrWidth, uScrHeight, uScrDepthBits, isWindowed, piD3DModeInfo))
{
*piD3DDevInfo=iDevInfo;
return TRUE;
}
}
return FALSE;
}
BOOL D3D_CAdapterInfo::Build(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, PFNCONFIRMDEVICE pfnConfirmDevice)
{
D3DDISPLAYMODE& rkD3DDMDesktop=m_kD3DDMDesktop;
if (FAILED(rkD3D.GetAdapterDisplayMode(iD3DAdapterInfo, &rkD3DDMDesktop)))
return FALSE;
rkD3D.GetAdapterIdentifier(iD3DAdapterInfo, D3DENUM_NO_WHQL_LEVEL, &m_kD3DAdapterIdentifier);
m_iCurD3DDevInfo=0;
m_uD3DDevInfoNum=0;
D3D_CAdapterDisplayModeList kD3DADMList;
kD3DADMList.Build(rkD3D, m_kD3DDMDesktop.Format, iD3DAdapterInfo);
D3D_CDeviceInfo* akD3DDevInfo=m_akD3DDevInfo;
for (UINT iDevType=0; iDevType<D3DDEVICETYPE_NUM; ++iDevType)
{
D3D_CDeviceInfo& rkD3DDevInfo=akD3DDevInfo[m_uD3DDevInfoNum];
if (rkD3DDevInfo.Build(rkD3D, iD3DAdapterInfo, iDevType, kD3DADMList, pfnConfirmDevice))
++m_uD3DDevInfoNum;
}
if (m_uD3DDevInfoNum>0)
return TRUE;
return FALSE;
}
VOID D3D_CAdapterInfo::GetString(std::string* pstEnumList)
{
for (UINT iDevInfo=0; iDevInfo<m_uD3DDevInfoNum; ++iDevInfo)
{
char szText[1024+1];
_snprintf(szText, sizeof(szText), "Device %d\r\n", iDevInfo);
pstEnumList->append(szText);
D3D_CDeviceInfo& rkD3DDevInfo=m_akD3DDevInfo[iDevInfo];
rkD3DDevInfo.GetString(pstEnumList);
}
}
/////////////////////////////////////////////////////////////////////////////
D3D_CDisplayModeAutoDetector::D3D_CDisplayModeAutoDetector()
{
m_uD3DAdapterInfoCount=0;
}
D3D_CDisplayModeAutoDetector::~D3D_CDisplayModeAutoDetector()
{
}
D3D_CAdapterInfo* D3D_CDisplayModeAutoDetector::GetD3DAdapterInfop(UINT iD3DAdapterInfo)
{
if (iD3DAdapterInfo >= m_uD3DAdapterInfoCount)
return NULL;
return &m_akD3DAdapterInfo[iD3DAdapterInfo];
}
D3D_SModeInfo* D3D_CDisplayModeAutoDetector::GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3D_SModeInfo)
{
D3D_CAdapterInfo* pkD3DAdapterInfo=GetD3DAdapterInfop(iD3DAdapterInfo);
if (pkD3DAdapterInfo)
{
D3D_CDeviceInfo* pkD3DDevInfo=pkD3DAdapterInfo->GetD3DDeviceInfop(iD3DDevInfo);
if (pkD3DDevInfo)
{
D3D_SModeInfo* pkD3D_SModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo);
if (pkD3D_SModeInfo)
return pkD3D_SModeInfo;
}
}
return NULL;
}
BOOL D3D_CDisplayModeAutoDetector::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo)
{
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<m_uD3DAdapterInfoCount; ++iD3DAdapterInfo)
{
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[iD3DAdapterInfo];
if (rkAdapterInfo.Find(uScrWidth, uScrHeight, uScrDepthBits, isWindowed, piD3DModeInfo, piD3DDevInfo))
{
*piD3DAdapterInfo=iD3DAdapterInfo;
return TRUE;
}
}
return FALSE;
}
BOOL D3D_CDisplayModeAutoDetector::Build(IDirect3D8& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice)
{
m_uD3DAdapterInfoCount=0;
UINT uTotalAdapterCount=rkD3D.GetAdapterCount();
uTotalAdapterCount=min(uTotalAdapterCount, D3DADAPTERINFO_NUM);
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<uTotalAdapterCount; ++iD3DAdapterInfo)
{
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[m_uD3DAdapterInfoCount];
if (rkAdapterInfo.Build(rkD3D, iD3DAdapterInfo, pfnConfirmDevice))
++m_uD3DAdapterInfoCount;
}
if (m_uD3DAdapterInfoCount>0)
return TRUE;
return FALSE;
}
VOID D3D_CDisplayModeAutoDetector::GetString(std::string* pstEnumList)
{
for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo<m_uD3DAdapterInfoCount; ++iD3DAdapterInfo)
{
char szText[1024+1];
_snprintf(szText, sizeof(szText), "Adapter %d\r\n", iD3DAdapterInfo);
pstEnumList->append(szText);
D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[iD3DAdapterInfo];
rkAdapterInfo.GetString(pstEnumList);
}
}

167
src/EterLib/GrpDetector.h Normal file
View File

@ -0,0 +1,167 @@
#pragma once
#include <d3d8.h>
#include <string>
typedef BOOL (*PFNCONFIRMDEVICE) (D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt);
enum
{
D3DDEVICETYPE_HAL,
D3DDEVICETYPE_REF,
D3DDEVICETYPE_NUM,
};
struct D3D_SModeInfo
{
UINT m_uScrWidth;
UINT m_uScrHeight;
UINT m_uScrDepthBit;
UINT m_dwD3DBehavior;
D3DFORMAT m_eD3DFmtPixel;
D3DFORMAT m_eD3DFmtDepthStencil;
VOID GetString(std::string* pstEnumList);
};
class D3D_CAdapterDisplayModeList
{
public:
D3D_CAdapterDisplayModeList() {}
~D3D_CAdapterDisplayModeList() {}
VOID Build(IDirect3D8& rkD3D, D3DFORMAT eD3DFmtDefault, UINT iAdapter);
UINT GetDisplayModeNum();
UINT GetPixelFormatNum();
const D3DDISPLAYMODE& GetDisplayModer(UINT iD3DDM);
const D3DFORMAT& GetPixelFormatr(UINT iD3DFmt);
protected:
enum
{
D3DDISPLAYMODE_MAX = 100,
D3DFORMAT_MAX = 20,
FILTEROUT_LOWRESOLUTION_WIDTH = 640,
FILTEROUT_LOWRESOLUTION_HEIGHT = 480,
};
protected:
D3DDISPLAYMODE m_akD3DDM[D3DDISPLAYMODE_MAX];
D3DFORMAT m_aeD3DFmt[D3DFORMAT_MAX];
UINT m_uD3DDMNum;
UINT m_uD3DFmtNum;
};
class D3D_CDeviceInfo
{
public:
D3D_CDeviceInfo() {}
~D3D_CDeviceInfo() {}
BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, PFNCONFIRMDEVICE pfnConfirmDevice);
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo);
UINT GetD3DModeInfoNum();
VOID GetString(std::string* pstEnumList);
BOOL FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iAdapter, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat);
D3D_SModeInfo& GetD3DModeInfor(UINT iD3DModeInfo);
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DModeInfo);
protected:
enum
{
D3DMODEINFO_NUM = 150,
};
protected:
const TCHAR* m_szDevDesc;
D3DDEVTYPE m_eD3DDevType;
D3DCAPS8 m_kD3DCaps;
BOOL m_canDoWindowed;
UINT m_iCurD3DModeInfo;
UINT m_uD3DModeInfoNum;
D3D_SModeInfo m_akD3DModeInfo[D3DMODEINFO_NUM];
BOOL m_isWindowed;
D3DMULTISAMPLE_TYPE m_eD3DMSTWindowed;
D3DMULTISAMPLE_TYPE m_eD3DMSTFullscreen;
protected:
static const CHAR* msc_aszD3DDevDesc[D3DDEVICETYPE_NUM];
static const D3DDEVTYPE msc_aeD3DDevType[D3DDEVICETYPE_NUM];
};
class D3D_CAdapterInfo
{
public:
D3D_CAdapterInfo() {}
~D3D_CAdapterInfo() {}
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo);
BOOL Build(IDirect3D8& rkD3D, UINT iAdapter, PFNCONFIRMDEVICE pfnConfirmDevice);
VOID GetString(std::string* pstEnumList);
D3DADAPTER_IDENTIFIER8& GetIdentifier()
{
return m_kD3DAdapterIdentifier;
}
D3DDISPLAYMODE& GetDesktopD3DDisplayModer();
D3DDISPLAYMODE* GetDesktopD3DDisplayModep();
D3D_CDeviceInfo* GetD3DDeviceInfop(UINT iD3DDevInfo);
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DDevInfo, UINT iD3DModeInfo);
protected:
enum
{
D3DDEVICEINFO_NUM = 5,
};
protected:
D3DADAPTER_IDENTIFIER8 m_kD3DAdapterIdentifier;
D3DDISPLAYMODE m_kD3DDMDesktop;
UINT m_iCurD3DDevInfo;
UINT m_uD3DDevInfoNum;
D3D_CDeviceInfo m_akD3DDevInfo[D3DDEVICEINFO_NUM];
};
class D3D_CDisplayModeAutoDetector
{
public:
D3D_CDisplayModeAutoDetector();
~D3D_CDisplayModeAutoDetector();
BOOL Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo);
BOOL Build(IDirect3D8& rkD3D, PFNCONFIRMDEVICE pfnConfirmDevice);
D3D_CAdapterInfo* GetD3DAdapterInfop(UINT iD3DAdapterInfo);
D3D_SModeInfo* GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3DModeInfo);
VOID GetString(std::string* pstEnumList);
protected:
enum
{
D3DADAPTERINFO_NUM = 10,
};
protected:
D3D_CAdapterInfo m_akD3DAdapterInfo[D3DADAPTERINFO_NUM];
UINT m_uD3DAdapterInfoCount;
};

764
src/EterLib/GrpDevice.cpp Normal file
View File

@ -0,0 +1,764 @@
#include "StdAfx.h"
#include "GrpDevice.h"
#include "../eterBase/Stl.h"
#include "../eterBase/Debug.h"
bool GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = false;
bool GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = false;
bool GRAPHICS_CAPS_HALF_SIZE_IMAGE = false;
bool GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER = false;
bool GRAPHICS_CAPS_SOFTWARE_TILING = false;
D3DPRESENT_PARAMETERS g_kD3DPP;
bool g_isBrowserMode=false;
RECT g_rcBrowser;
CGraphicDevice::CGraphicDevice()
: m_uBackBufferCount(0)
{
__Initialize();
}
CGraphicDevice::~CGraphicDevice()
{
Destroy();
}
void CGraphicDevice::__Initialize()
{
ms_iD3DAdapterInfo=D3DADAPTER_DEFAULT;
ms_iD3DDevInfo=D3DADAPTER_DEFAULT;
ms_iD3DModeInfo=D3DADAPTER_DEFAULT;
ms_lpd3d = NULL;
ms_lpd3dDevice = NULL;
ms_lpd3dMatStack = NULL;
ms_dwWavingEndTime = 0;
ms_dwFlashingEndTime = 0;
m_pStateManager = NULL;
__InitializeDefaultIndexBufferList();
__InitializePDTVertexBufferList();
}
void CGraphicDevice::RegisterWarningString(UINT uiMsg, const char * c_szString)
{
m_kMap_strWarningMessage[uiMsg] = c_szString;
}
void CGraphicDevice::__WarningMessage(HWND hWnd, UINT uiMsg)
{
if (m_kMap_strWarningMessage.end() == m_kMap_strWarningMessage.find(uiMsg))
return;
MessageBox(hWnd, m_kMap_strWarningMessage[uiMsg].c_str(), "Warning", MB_OK|MB_TOPMOST);
}
void CGraphicDevice::MoveWebBrowserRect(const RECT& c_rcWebPage)
{
g_rcBrowser=c_rcWebPage;
}
void CGraphicDevice::EnableWebBrowserMode(const RECT& c_rcWebPage)
{
if (!ms_lpd3dDevice)
return;
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
g_isBrowserMode=true;
if (D3DSWAPEFFECT_COPY==rkD3DPP.SwapEffect)
return;
g_kD3DPP=rkD3DPP;
g_rcBrowser=c_rcWebPage;
//rkD3DPP.Windowed=TRUE;
rkD3DPP.SwapEffect=D3DSWAPEFFECT_COPY;
rkD3DPP.BackBufferCount = 1;
rkD3DPP.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
if (FAILED(hr))
return;
STATEMANAGER.SetDefaultState();
}
void CGraphicDevice::DisableWebBrowserMode()
{
if (!ms_lpd3dDevice)
return;
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
g_isBrowserMode=false;
rkD3DPP=g_kD3DPP;
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
if (FAILED(hr))
return;
STATEMANAGER.SetDefaultState();
}
bool CGraphicDevice::ResizeBackBuffer(UINT uWidth, UINT uHeight)
{
if (!ms_lpd3dDevice)
return false;
D3DPRESENT_PARAMETERS& rkD3DPP=ms_d3dPresentParameter;
if (rkD3DPP.Windowed)
{
if (rkD3DPP.BackBufferWidth!=uWidth || rkD3DPP.BackBufferHeight!=uHeight)
{
rkD3DPP.BackBufferWidth=uWidth;
rkD3DPP.BackBufferHeight=uHeight;
IDirect3DDevice8& rkD3DDev=*ms_lpd3dDevice;
HRESULT hr=rkD3DDev.Reset(&rkD3DPP);
if (FAILED(hr))
{
return false;
}
STATEMANAGER.SetDefaultState();
}
}
return true;
}
DWORD CGraphicDevice::CreatePNTStreamVertexShader()
{
assert(ms_lpd3dDevice != NULL);
DWORD declVector[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3),
D3DVSD_REG(3, D3DVSDT_FLOAT3),
D3DVSD_REG(7, D3DVSDT_FLOAT2),
D3DVSD_END()
};
DWORD ret;
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
return 0;
return ret;
}
DWORD CGraphicDevice::CreatePNT2StreamVertexShader()
{
assert(ms_lpd3dDevice != NULL);
DWORD declVector[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3),
D3DVSD_REG(3, D3DVSDT_FLOAT3),
D3DVSD_REG(7, D3DVSDT_FLOAT2),
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
// D3DVSD_STREAM(1),
D3DVSD_END()
};
DWORD ret;
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
return 0;
return ret;
}
DWORD CGraphicDevice::CreatePTStreamVertexShader()
{
assert(ms_lpd3dDevice != NULL);
DWORD declVector[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3),
D3DVSD_STREAM(1),
D3DVSD_REG(7, D3DVSDT_FLOAT2),
D3DVSD_END()
};
DWORD ret;
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
return 0;
return (ret);
}
DWORD CGraphicDevice::CreateDoublePNTStreamVertexShader()
{
assert(ms_lpd3dDevice != NULL);
DWORD declVector[] =
{
D3DVSD_STREAM(0),
D3DVSD_REG(0, D3DVSDT_FLOAT3),
D3DVSD_REG(3, D3DVSDT_FLOAT3),
D3DVSD_REG(7, D3DVSDT_FLOAT2),
D3DVSD_STREAM(1),
D3DVSD_REG(D3DVSDE_POSITION2, D3DVSDT_FLOAT3),
D3DVSD_REG(D3DVSDE_NORMAL2, D3DVSDT_FLOAT3),
D3DVSD_REG(D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
D3DVSD_END()
};
DWORD ret;
if (FAILED(ms_lpd3dDevice->CreateVertexShader(&declVector[0], NULL, &ret, 0)))
return 0;
return ret;
}
CGraphicDevice::EDeviceState CGraphicDevice::GetDeviceState()
{
if (!ms_lpd3dDevice)
return DEVICESTATE_NULL;
HRESULT hr;
if (FAILED(hr = ms_lpd3dDevice->TestCooperativeLevel()))
{
if (D3DERR_DEVICELOST == hr)
return DEVICESTATE_BROKEN;
if (D3DERR_DEVICENOTRESET == hr)
return DEVICESTATE_NEEDS_RESET;
return DEVICESTATE_BROKEN;
}
return DEVICESTATE_OK;
}
bool CGraphicDevice::Reset()
{
HRESULT hr;
if (FAILED(hr = ms_lpd3dDevice->Reset(&ms_d3dPresentParameter)))
return false;
return true;
}
static LPDIRECT3DSURFACE8 s_lpStencil;
static DWORD s_MaxTextureWidth, s_MaxTextureHeight;
BOOL EL3D_ConfirmDevice(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT /*eD3DFmt*/)
{
// PUREDEVICE<43><45> GetTransform / GetViewport <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʴ´<CAB4>.
if (uBehavior & D3DCREATE_PUREDEVICE)
return FALSE;
if (uBehavior & D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
// DirectionalLight
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_DIRECTIONALLIGHTS))
return FALSE;
// PositionalLight
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_POSITIONALLIGHTS))
return FALSE;
// Software T&L Support - ATI NOT SUPPORT CLIP, USE DIRECTX SOFTWARE PROCESSING CLIPPING
if (GRAPHICS_CAPS_SOFTWARE_TILING)
{
if (!(rkD3DCaps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS))
return FALSE;
}
else
{
// Shadow/Terrain
if (!(rkD3DCaps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN))
return FALSE;
}
}
s_MaxTextureWidth = rkD3DCaps.MaxTextureWidth;
s_MaxTextureHeight = rkD3DCaps.MaxTextureHeight;
return TRUE;
}
DWORD GetMaxTextureWidth()
{
return s_MaxTextureWidth;
}
DWORD GetMaxTextureHeight()
{
return s_MaxTextureHeight;
}
bool CGraphicDevice::__IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo)
{
D3DADAPTER_IDENTIFIER8& rkD3DAdapterIdentifier=rkD3DAdapterInfo.GetIdentifier();
char szSrcDriver[256];
strncpy(szSrcDriver, rkD3DAdapterIdentifier.Driver, sizeof(szSrcDriver)-1);
DWORD dwSrcHighVersion=rkD3DAdapterIdentifier.DriverVersion.QuadPart>>32;
DWORD dwSrcLowVersion=rkD3DAdapterIdentifier.DriverVersion.QuadPart&0xffffffff;
bool ret=false;
FILE* fp=fopen("grpblk.txt", "r");
if (fp)
{
DWORD dwChkHighVersion;
DWORD dwChkLowVersion;
char szChkDriver[256];
char szLine[256];
while (fgets(szLine, sizeof(szLine)-1, fp))
{
sscanf(szLine, "%s %x %x", szChkDriver, &dwChkHighVersion, &dwChkLowVersion);
if (strcmp(szSrcDriver, szChkDriver)==0)
if (dwSrcHighVersion==dwChkHighVersion)
if (dwSrcLowVersion==dwChkLowVersion)
{
ret=true;
break;
}
szLine[0]='\0';
}
fclose(fp);
}
return ret;
}
int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /*iBit*/, int iReflashRate)
{
int iRet = CREATE_OK;
Destroy();
ms_iWidth = iHres;
ms_iHeight = iVres;
ms_hWnd = hWnd;
ms_hDC = GetDC(hWnd);
ms_lpd3d = Direct3DCreate8(D3D_SDK_VERSION);
if (!ms_lpd3d)
return CREATE_NO_DIRECTX;
if (!ms_kD3DDetector.Build(*ms_lpd3d, EL3D_ConfirmDevice))
return CREATE_ENUM;
if (!ms_kD3DDetector.Find(800, 600, 32, TRUE, &ms_iD3DModeInfo, &ms_iD3DDevInfo, &ms_iD3DAdapterInfo))
return CREATE_DETECT;
std::string stDevList;
ms_kD3DDetector.GetString(&stDevList);
//Tracen(stDevList.c_str());
//Tracenf("adapter %d, device %d, mode %d", ms_iD3DAdapterInfo, ms_iD3DDevInfo, ms_iD3DModeInfo);
D3D_CAdapterInfo * pkD3DAdapterInfo = ms_kD3DDetector.GetD3DAdapterInfop(ms_iD3DAdapterInfo);
if (!pkD3DAdapterInfo)
{
Tracenf("adapter %d is EMPTY", ms_iD3DAdapterInfo);
return CREATE_DETECT;
}
if (__IsInDriverBlackList(*pkD3DAdapterInfo))
{
iRet |= CREATE_BAD_DRIVER;
__WarningMessage(hWnd, CREATE_BAD_DRIVER);
}
D3D_SModeInfo * pkD3DModeInfo = pkD3DAdapterInfo->GetD3DModeInfop(ms_iD3DDevInfo, ms_iD3DModeInfo);
if (!pkD3DModeInfo)
{
Tracenf("device %d, mode %d is EMPTY", ms_iD3DDevInfo, ms_iD3DModeInfo);
return CREATE_DETECT;
}
D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
if (Windowed &&
strnicmp(rkD3DAdapterId.Driver, "3dfx", 4)==0 &&
22 == pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format)
{
return CREATE_FORMAT;
}
if (pkD3DModeInfo->m_dwD3DBehavior==D3DCREATE_SOFTWARE_VERTEXPROCESSING)
{
iRet |= CREATE_NO_TNL;
// DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
//__WarningMessage(hWnd, CREATE_NO_TNL);
// END_OF_DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
}
std::string stModeInfo;
pkD3DModeInfo->GetString(&stModeInfo);
//Tracen(stModeInfo.c_str());
int ErrorCorrection = 0;
RETRY:
ZeroMemory(&ms_d3dPresentParameter, sizeof(ms_d3dPresentParameter));
ms_d3dPresentParameter.Windowed = Windowed;
ms_d3dPresentParameter.BackBufferWidth = iHres;
ms_d3dPresentParameter.BackBufferHeight = iVres;
ms_d3dPresentParameter.hDeviceWindow = hWnd;
ms_d3dPresentParameter.BackBufferCount = m_uBackBufferCount;
ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
if (Windowed)
{
ms_d3dPresentParameter.BackBufferFormat = pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format;
}
else
{
ms_d3dPresentParameter.BackBufferFormat = pkD3DModeInfo->m_eD3DFmtPixel;
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = iReflashRate;
}
ms_d3dPresentParameter.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
ms_d3dPresentParameter.EnableAutoDepthStencil = TRUE;
ms_d3dPresentParameter.AutoDepthStencilFormat = pkD3DModeInfo->m_eD3DFmtDepthStencil;
ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;
if (FAILED(ms_hLastResult = ms_lpd3d->CreateDevice(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
hWnd,
// 2004. 1. 9 myevan <20><><EFBFBD>ؽ<EFBFBD> <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
pkD3DModeInfo->m_dwD3DBehavior,
&ms_d3dPresentParameter,
&ms_lpd3dDevice)))
{
switch (ms_hLastResult)
{
case D3DERR_INVALIDCALL:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_INVALIDCALL\nThe method call is invalid. For example, a method's parameter may have an invalid value.");
break;
case D3DERR_NOTAVAILABLE:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_NOTAVAILABLE\nThis device does not support the queried technique. ");
break;
case D3DERR_OUTOFVIDEOMEMORY:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_OUTOFVIDEOMEMORY\nDirect3D does not have enough display memory to perform the operation");
break;
default:
Tracenf("IDirect3DDevice.CreateDevice - ERROR %d", ms_hLastResult);
break;
}
if (ErrorCorrection)
return CREATE_DEVICE;
// 2004. 1. 9 myevan ū<>ǹ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ڵ<EFBFBD><DAB5>ε<EFBFBD>.. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ǥ<><C7A5><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
iReflashRate = 0;
++ErrorCorrection;
iRet = CREATE_REFRESHRATE;
goto RETRY;
}
// Check DXT Support Info
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT1) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT3) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT5) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if (FAILED((ms_hLastResult = ms_lpd3dDevice->GetDeviceCaps(&ms_d3dCaps))))
{
Tracenf("IDirect3DDevice.GetDeviceCaps - ERROR %d", ms_hLastResult);
return CREATE_GET_DEVICE_CAPS2;
}
if (!Windowed)
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, iHres, iVres, SWP_SHOWWINDOW);
//Tracef("vertex shader version : %X\n",(DWORD)ms_d3dCaps.VertexShaderVersion);
ms_lpd3dDevice->GetViewport(&ms_Viewport);
m_pStateManager = new CStateManager(ms_lpd3dDevice);
D3DXCreateMatrixStack(0, &ms_lpd3dMatStack);
ms_lpd3dMatStack->LoadIdentity();
ms_ptVS = CreatePTStreamVertexShader();
ms_pntVS = CreatePNTStreamVertexShader();
ms_pnt2VS = CreatePNT2StreamVertexShader();
D3DXMatrixIdentity(&ms_matIdentity);
D3DXMatrixIdentity(&ms_matView);
D3DXMatrixIdentity(&ms_matProj);
D3DXMatrixIdentity(&ms_matInverseView);
D3DXMatrixIdentity(&ms_matInverseViewYAxis);
D3DXMatrixIdentity(&ms_matScreen0);
D3DXMatrixIdentity(&ms_matScreen1);
D3DXMatrixIdentity(&ms_matScreen2);
ms_matScreen0._11 = 1;
ms_matScreen0._22 = -1;
ms_matScreen1._41 = 1;
ms_matScreen1._42 = 1;
ms_matScreen2._11 = (float) iHres / 2;
ms_matScreen2._22 = (float) iVres / 2;
D3DXCreateSphere(ms_lpd3dDevice, 1.0f, 32, 32, &ms_lpSphereMesh, NULL);
D3DXCreateCylinder(ms_lpd3dDevice, 1.0f, 1.0f, 1.0f, 8, 8, &ms_lpCylinderMesh, NULL);
ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff000000, 1.0f, 0);
if (!__CreateDefaultIndexBufferList())
return false;
if (!__CreatePDTVertexBufferList())
return false;
DWORD dwTexMemSize = GetAvailableTextureMemory();
if (dwTexMemSize < 64 * 1024 * 1024)
ms_isLowTextureMemory = true;
else
ms_isLowTextureMemory = false;
if (dwTexMemSize > 100 * 1024 * 1024)
ms_isHighTextureMemory = true;
else
ms_isHighTextureMemory = false;
if (ms_d3dCaps.TextureAddressCaps & D3DPTADDRESSCAPS_BORDER)
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=false;
else
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true;
//D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
if (strnicmp(rkD3DAdapterId.Driver, "SIS", 3) == 0)
{
GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = true;
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
ms_isLowTextureMemory = true;
}
else if (strnicmp(rkD3DAdapterId.Driver, "3dfx", 4) == 0)
{
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
ms_isLowTextureMemory = true;
}
return (iRet);
}
void CGraphicDevice::__InitializePDTVertexBufferList()
{
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
ms_alpd3dPDTVB[i]=NULL;
}
void CGraphicDevice::__DestroyPDTVertexBufferList()
{
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
{
if (ms_alpd3dPDTVB[i])
{
ms_alpd3dPDTVB[i]->Release();
ms_alpd3dPDTVB[i]=NULL;
}
}
}
bool CGraphicDevice::__CreatePDTVertexBufferList()
{
for (UINT i=0; i<PDT_VERTEXBUFFER_NUM; ++i)
{
if (FAILED(
ms_lpd3dDevice->CreateVertexBuffer(
sizeof(TPDTVertex)*PDT_VERTEX_NUM,
D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1,
D3DPOOL_SYSTEMMEM,
&ms_alpd3dPDTVB[i])
))
return false;
}
return true;
}
void CGraphicDevice::__InitializeDefaultIndexBufferList()
{
for (UINT i=0; i<DEFAULT_IB_NUM; ++i)
ms_alpd3dDefIB[i]=NULL;
}
void CGraphicDevice::__DestroyDefaultIndexBufferList()
{
for (UINT i=0; i<DEFAULT_IB_NUM; ++i)
if (ms_alpd3dDefIB[i])
{
ms_alpd3dDefIB[i]->Release();
ms_alpd3dDefIB[i]=NULL;
}
}
bool CGraphicDevice::__CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices)
{
assert(ms_alpd3dDefIB[eDefIB]==NULL);
if (FAILED(
ms_lpd3dDevice->CreateIndexBuffer(
sizeof(WORD)*uIdxCount,
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&ms_alpd3dDefIB[eDefIB])
)) return false;
WORD* dstIndices;
if (FAILED(
ms_alpd3dDefIB[eDefIB]->Lock(0, 0, (BYTE**)&dstIndices, 0)
)) return false;
memcpy(dstIndices, c_awIndices, sizeof(WORD)*uIdxCount);
ms_alpd3dDefIB[eDefIB]->Unlock();
return true;
}
bool CGraphicDevice::__CreateDefaultIndexBufferList()
{
static const WORD c_awLineIndices[2] = { 0, 1, };
static const WORD c_awLineTriIndices[6] = { 0, 1, 0, 2, 1, 2, };
static const WORD c_awLineRectIndices[8] = { 0, 1, 0, 2, 1, 3, 2, 3,};
static const WORD c_awLineCubeIndices[24] = {
0, 1, 0, 2, 1, 3, 2, 3,
0, 4, 1, 5, 2, 6, 3, 7,
4, 5, 4, 6, 5, 7, 6, 7,
};
static const WORD c_awFillTriIndices[3]= { 0, 1, 2, };
static const WORD c_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, };
static const WORD c_awFillCubeIndices[36] = {
0, 1, 2, 1, 3, 2,
2, 0, 6, 0, 4, 6,
0, 1, 4, 1, 5, 4,
1, 3, 5, 3, 7, 5,
3, 2, 7, 2, 6, 7,
4, 5, 6, 5, 7, 6,
};
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE, 2, c_awLineIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_TRI, 6, c_awLineTriIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_RECT, 8, c_awLineRectIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_LINE_CUBE, 24, c_awLineCubeIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_TRI, 3, c_awFillTriIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_RECT, 6, c_awFillRectIndices))
return false;
if (!__CreateDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE, 36, c_awFillCubeIndices))
return false;
return true;
}
void CGraphicDevice::InitBackBufferCount(UINT uBackBufferCount)
{
m_uBackBufferCount=uBackBufferCount;
}
void CGraphicDevice::Destroy()
{
__DestroyPDTVertexBufferList();
__DestroyDefaultIndexBufferList();
if (ms_hDC)
{
ReleaseDC(ms_hWnd, ms_hDC);
ms_hDC = NULL;
}
if (ms_ptVS)
{
ms_lpd3dDevice->DeleteVertexShader(ms_ptVS);
ms_ptVS = 0;;
}
if (ms_pntVS)
{
ms_lpd3dDevice->DeleteVertexShader(ms_pntVS);
ms_pntVS = 0;
}
if (ms_pnt2VS)
{
ms_lpd3dDevice->DeleteVertexShader(ms_pnt2VS);
ms_pnt2VS = 0;
}
safe_release(ms_lpSphereMesh);
safe_release(ms_lpCylinderMesh);
safe_release(ms_lpd3dMatStack);
safe_release(ms_lpd3dDevice);
safe_release(ms_lpd3d);
if (m_pStateManager)
{
delete m_pStateManager;
m_pStateManager = NULL;
}
__Initialize();
}

74
src/EterLib/GrpDevice.h Normal file
View File

@ -0,0 +1,74 @@
#pragma once
#include "GrpBase.h"
#include "GrpDetector.h"
#include "StateManager.h"
class CGraphicDevice : public CGraphicBase
{
public:
enum EDeviceState
{
DEVICESTATE_OK,
DEVICESTATE_BROKEN,
DEVICESTATE_NEEDS_RESET,
DEVICESTATE_NULL
};
enum ECreateReturnValues
{
CREATE_OK = (1 << 0),
CREATE_NO_DIRECTX = (1 << 1),
CREATE_GET_DEVICE_CAPS = (1 << 2),
CREATE_GET_DEVICE_CAPS2 = (1 << 3),
CREATE_DEVICE = (1 << 4),
CREATE_REFRESHRATE = (1 << 5),
CREATE_ENUM = (1 << 6), // 2003. 01. 09. myevan <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
CREATE_DETECT = (1 << 7), // 2003. 01. 09. myevan <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
CREATE_NO_TNL = (1 << 8),
CREATE_BAD_DRIVER = (1 << 9),
CREATE_FORMAT = (1 << 10),
};
CGraphicDevice();
virtual ~CGraphicDevice();
void InitBackBufferCount(UINT uBackBufferCount);
void Destroy();
int Create(HWND hWnd, int hres, int vres, bool Windowed = true, int bit = 32, int ReflashRate = 0);
EDeviceState GetDeviceState();
bool Reset();
void EnableWebBrowserMode(const RECT& c_rcWebPage);
void DisableWebBrowserMode();
void MoveWebBrowserRect(const RECT& c_rcWebPage);
bool ResizeBackBuffer(UINT uWidth, UINT uHeight);
void RegisterWarningString(UINT uiMsg, const char * c_szString);
protected:
void __Initialize();
bool __IsInDriverBlackList(D3D_CAdapterInfo& rkD3DAdapterInfo);
void __WarningMessage(HWND hWnd, UINT uiMsg);
void __InitializeDefaultIndexBufferList();
void __DestroyDefaultIndexBufferList();
bool __CreateDefaultIndexBufferList();
bool __CreateDefaultIndexBuffer(UINT eDefIB, UINT uIdxCount, const WORD* c_awIndices);
void __InitializePDTVertexBufferList();
void __DestroyPDTVertexBufferList();
bool __CreatePDTVertexBufferList();
DWORD CreatePTStreamVertexShader();
DWORD CreatePNTStreamVertexShader();
DWORD CreatePNT2StreamVertexShader();
DWORD CreateDoublePNTStreamVertexShader();
protected:
DWORD m_uBackBufferCount;
std::map<UINT, std::string> m_kMap_strWarningMessage;
CStateManager* m_pStateManager;
};

View File

@ -0,0 +1,236 @@
#include "StdAfx.h"
#include "../eterBase/CRC32.h"
#include "GrpExpandedImageInstance.h"
#include "StateManager.h"
CDynamicPool<CGraphicExpandedImageInstance> CGraphicExpandedImageInstance::ms_kPool;
void CGraphicExpandedImageInstance::CreateSystem(UINT uCapacity)
{
ms_kPool.Create(uCapacity);
}
void CGraphicExpandedImageInstance::DestroySystem()
{
ms_kPool.Destroy();
}
CGraphicExpandedImageInstance* CGraphicExpandedImageInstance::New()
{
return ms_kPool.Alloc();
}
void CGraphicExpandedImageInstance::Delete(CGraphicExpandedImageInstance* pkImgInst)
{
pkImgInst->Destroy();
ms_kPool.Free(pkImgInst);
}
void CGraphicExpandedImageInstance::OnRender()
{
CGraphicImage * pImage = m_roImage.GetPointer();
CGraphicTexture * pTexture = pImage->GetTexturePointer();
const RECT& c_rRect = pImage->GetRectReference();
float texReverseWidth = 1.0f / float(pTexture->GetWidth());
float texReverseHeight = 1.0f / float(pTexture->GetHeight());
float su = (c_rRect.left - m_RenderingRect.left) * texReverseWidth;
float sv = (c_rRect.top - m_RenderingRect.top) * texReverseHeight;
float eu = (c_rRect.left + m_RenderingRect.right + (c_rRect.right-c_rRect.left)) * texReverseWidth;
float ev = (c_rRect.top + m_RenderingRect.bottom + (c_rRect.bottom-c_rRect.top)) * texReverseHeight;
TPDTVertex vertices[4];
vertices[0].position.x = m_v2Position.x-0.5f;
vertices[0].position.y = m_v2Position.y-0.5f;
vertices[0].position.z = m_fDepth;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[0].diffuse = m_DiffuseColor;
vertices[1].position.x = m_v2Position.x-0.5f;
vertices[1].position.y = m_v2Position.y-0.5f;
vertices[1].position.z = m_fDepth;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[1].diffuse = m_DiffuseColor;
vertices[2].position.x = m_v2Position.x-0.5f;
vertices[2].position.y = m_v2Position.y-0.5f;
vertices[2].position.z = m_fDepth;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[2].diffuse = m_DiffuseColor;
vertices[3].position.x = m_v2Position.x-0.5f;
vertices[3].position.y = m_v2Position.y-0.5f;
vertices[3].position.z = m_fDepth;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
vertices[3].diffuse = m_DiffuseColor;
if (0.0f == m_fRotation)
{
float fimgWidth = float(pImage->GetWidth()) * m_v2Scale.x;
float fimgHeight = float(pImage->GetHeight()) * m_v2Scale.y;
vertices[0].position.x -= m_RenderingRect.left;
vertices[0].position.y -= m_RenderingRect.top;
vertices[1].position.x += fimgWidth + m_RenderingRect.right;
vertices[1].position.y -= m_RenderingRect.top;
vertices[2].position.x -= m_RenderingRect.left;
vertices[2].position.y += fimgHeight + m_RenderingRect.bottom;
vertices[3].position.x += fimgWidth + m_RenderingRect.right;
vertices[3].position.y += fimgHeight + m_RenderingRect.bottom;
if ((0.0f < m_v2Scale.x && 0.0f > m_v2Scale.y) || (0.0f > m_v2Scale.x && 0.0f < m_v2Scale.y)) {
STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
}
}
else
{
float fimgHalfWidth = float(pImage->GetWidth())/2.0f * m_v2Scale.x;
float fimgHalfHeight = float(pImage->GetHeight())/2.0f * m_v2Scale.y;
for (int i = 0; i < 4; ++i)
{
vertices[i].position.x += m_v2Origin.x;
vertices[i].position.y += m_v2Origin.y;
}
float fRadian = D3DXToRadian(m_fRotation);
vertices[0].position.x += (-fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
vertices[0].position.y += (-fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
vertices[1].position.x += (+fimgHalfWidth*cosf(fRadian)) - (-fimgHalfHeight*sinf(fRadian));
vertices[1].position.y += (+fimgHalfWidth*sinf(fRadian)) + (-fimgHalfHeight*cosf(fRadian));
vertices[2].position.x += (-fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
vertices[2].position.y += (-fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
vertices[3].position.x += (+fimgHalfWidth*cosf(fRadian)) - (+fimgHalfHeight*sinf(fRadian));
vertices[3].position.y += (+fimgHalfWidth*sinf(fRadian)) + (+fimgHalfHeight*cosf(fRadian));
}
switch (m_iRenderingMode)
{
case RENDERING_MODE_SCREEN:
case RENDERING_MODE_COLOR_DODGE:
STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
break;
case RENDERING_MODE_MODULATE:
STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
break;
}
// 2004.11.18.myevan.ctrl+alt+del <20>ݺ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ƨ<><C6A8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
if (CGraphicBase::SetPDTStream(vertices, 4))
{
CGraphicBase::SetDefaultIndexBuffer(CGraphicBase::DEFAULT_IB_FILL_RECT);
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
}
//STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
/////////////////////////////////////////////////////////////
switch (m_iRenderingMode)
{
case RENDERING_MODE_SCREEN:
case RENDERING_MODE_COLOR_DODGE:
case RENDERING_MODE_MODULATE:
STATEMANAGER.RestoreRenderState(D3DRS_SRCBLEND);
STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND);
break;
}
STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
}
void CGraphicExpandedImageInstance::SetDepth(float fDepth)
{
m_fDepth = fDepth;
}
void CGraphicExpandedImageInstance::SetOrigin()
{
SetOrigin(float(GetWidth()) / 2.0f, float(GetHeight()) / 2.0f);
}
void CGraphicExpandedImageInstance::SetOrigin(float fx, float fy)
{
m_v2Origin.x = fx;
m_v2Origin.y = fy;
}
void CGraphicExpandedImageInstance::SetRotation(float fRotation)
{
m_fRotation = fRotation;
}
void CGraphicExpandedImageInstance::SetScale(float fx, float fy)
{
m_v2Scale.x = fx;
m_v2Scale.y = fy;
}
void CGraphicExpandedImageInstance::SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom)
{
if (IsEmpty())
return;
float fWidth = float(GetWidth());
float fHeight = float(GetHeight());
m_RenderingRect.left = fWidth * fLeft;
m_RenderingRect.top = fHeight * fTop;
m_RenderingRect.right = fWidth * fRight;
m_RenderingRect.bottom = fHeight * fBottom;
}
void CGraphicExpandedImageInstance::SetRenderingMode(int iMode)
{
m_iRenderingMode = iMode;
}
DWORD CGraphicExpandedImageInstance::Type()
{
static DWORD s_dwType = GetCRC32("CGraphicExpandedImageInstance", strlen("CGraphicExpandedImageInstance"));
return (s_dwType);
}
void CGraphicExpandedImageInstance::OnSetImagePointer()
{
if (IsEmpty())
return;
SetOrigin(float(GetWidth()) / 2.0f, float(GetHeight()) / 2.0f);
}
BOOL CGraphicExpandedImageInstance::OnIsType(DWORD dwType)
{
if (CGraphicExpandedImageInstance::Type() == dwType)
return TRUE;
return CGraphicImageInstance::IsType(dwType);
}
void CGraphicExpandedImageInstance::Initialize()
{
m_iRenderingMode = RENDERING_MODE_NORMAL;
m_fDepth = 0.0f;
m_v2Origin.x = m_v2Origin.y = 0.0f;
m_v2Scale.x = m_v2Scale.y = 1.0f;
m_fRotation = 0.0f;
memset(&m_RenderingRect, 0, sizeof(RECT));
}
void CGraphicExpandedImageInstance::Destroy()
{
CGraphicImageInstance::Destroy();
Initialize();
}
CGraphicExpandedImageInstance::CGraphicExpandedImageInstance()
{
Initialize();
}
CGraphicExpandedImageInstance::~CGraphicExpandedImageInstance()
{
Destroy();
}

View File

@ -0,0 +1,61 @@
#pragma once
#include "GrpImageInstance.h"
class CGraphicExpandedImageInstance : public CGraphicImageInstance
{
public:
static DWORD Type();
static void DeleteExpandedImageInstance(CGraphicExpandedImageInstance * pkInstance)
{
pkInstance->Destroy();
ms_kPool.Free(pkInstance);
}
enum ERenderingMode
{
RENDERING_MODE_NORMAL,
RENDERING_MODE_SCREEN,
RENDERING_MODE_COLOR_DODGE,
RENDERING_MODE_MODULATE,
};
public:
CGraphicExpandedImageInstance();
virtual ~CGraphicExpandedImageInstance();
void Destroy();
void SetDepth(float fDepth);
void SetOrigin();
void SetOrigin(float fx, float fy);
void SetRotation(float fRotation);
void SetScale(float fx, float fy);
void SetRenderingRect(float fLeft, float fTop, float fRight, float fBottom);
void SetRenderingMode(int iMode);
protected:
void Initialize();
void OnRender();
void OnSetImagePointer();
BOOL OnIsType(DWORD dwType);
protected:
float m_fDepth;
D3DXVECTOR2 m_v2Origin;
D3DXVECTOR2 m_v2Scale;
float m_fRotation;
RECT m_RenderingRect;
int m_iRenderingMode;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicExpandedImageInstance* New();
static void Delete(CGraphicExpandedImageInstance* pkImgInst);
static CDynamicPool<CGraphicExpandedImageInstance> ms_kPool;
};

View File

@ -0,0 +1,314 @@
#include "StdAfx.h"
#include "GrpText.h"
#include "../eterBase/Stl.h"
#include "Util.h"
CGraphicFontTexture::CGraphicFontTexture()
{
Initialize();
}
CGraphicFontTexture::~CGraphicFontTexture()
{
Destroy();
}
void CGraphicFontTexture::Initialize()
{
CGraphicTexture::Initialize();
m_hFontOld = NULL;
m_hFont = NULL;
m_isDirty = false;
m_bItalic = false;
}
bool CGraphicFontTexture::IsEmpty() const
{
return m_fontMap.size() == 0;
}
void CGraphicFontTexture::Destroy()
{
HDC hDC = m_dib.GetDCHandle();
if (hDC)
SelectObject(hDC, m_hFontOld);
m_dib.Destroy();
m_lpd3dTexture = NULL;
CGraphicTexture::Destroy();
stl_wipe(m_pFontTextureVector);
m_charInfoMap.clear();
if (m_fontMap.size())
{
TFontMap::iterator i = m_fontMap.begin();
while(i != m_fontMap.end())
{
DeleteObject((HGDIOBJ)i->second);
++i;
}
m_fontMap.clear();
}
Initialize();
}
bool CGraphicFontTexture::CreateDeviceObjects()
{
return true;
}
void CGraphicFontTexture::DestroyDeviceObjects()
{
}
bool CGraphicFontTexture::Create(const char* c_szFontName, int fontSize, bool bItalic)
{
Destroy();
strncpy(m_fontName, c_szFontName, sizeof(m_fontName)-1);
m_fontSize = fontSize;
m_bItalic = bItalic;
m_x = 0;
m_y = 0;
m_step = 0;
DWORD width = 256,height = 256;
if (GetMaxTextureWidth() > 512)
width = 512;
if (GetMaxTextureHeight() > 512)
height = 512;
if (!m_dib.Create(ms_hDC, width, height))
return false;
HDC hDC = m_dib.GetDCHandle();
m_hFont = GetFont(GetDefaultCodePage());
m_hFontOld=(HFONT)SelectObject(hDC, m_hFont);
SetTextColor(hDC, RGB(255, 255, 255));
SetBkColor(hDC, 0);
if (!AppendTexture())
return false;
return true;
}
HFONT CGraphicFontTexture::GetFont(WORD codePage)
{
HFONT hFont = NULL;
TFontMap::iterator i = m_fontMap.find(codePage);
if(i != m_fontMap.end())
{
hFont = i->second;
}
else
{
LOGFONT logFont;
memset(&logFont, 0, sizeof(LOGFONT));
logFont.lfHeight = m_fontSize;
logFont.lfEscapement = 0;
logFont.lfOrientation = 0;
logFont.lfWeight = FW_NORMAL;
logFont.lfItalic = (BYTE) m_bItalic;
logFont.lfUnderline = FALSE;
logFont.lfStrikeOut = FALSE;
logFont.lfCharSet = GetCharsetFromCodePage(codePage);
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = ANTIALIASED_QUALITY;
logFont.lfPitchAndFamily = DEFAULT_PITCH;
//Tracenf("font: %s", GetFontFaceFromCodePage(codePage));
strcpy(logFont.lfFaceName, m_fontName); //GetFontFaceFromCodePage(codePage));
//strcpy(logFont.lfFaceName, GetFontFaceFromCodePage(codePage));
hFont = CreateFontIndirect(&logFont);
m_fontMap.insert(TFontMap::value_type(codePage, hFont));
}
return hFont;
}
bool CGraphicFontTexture::AppendTexture()
{
CGraphicImageTexture * pNewTexture = new CGraphicImageTexture;
if (!pNewTexture->Create(m_dib.GetWidth(), m_dib.GetHeight(), D3DFMT_A4R4G4B4))
{
delete pNewTexture;
return false;
}
m_pFontTextureVector.push_back(pNewTexture);
return true;
}
bool CGraphicFontTexture::UpdateTexture()
{
if(!m_isDirty)
return true;
m_isDirty = false;
CGraphicImageTexture * pFontTexture = m_pFontTextureVector.back();
if (!pFontTexture)
return false;
WORD* pwDst;
int pitch;
if (!pFontTexture->Lock(&pitch, (void**)&pwDst))
return false;
pitch /= 2;
int width = m_dib.GetWidth();
int height = m_dib.GetHeight();
DWORD * pdwSrc = (DWORD*)m_dib.GetPointer();
for (int y = 0; y < height; ++y, pwDst += pitch, pdwSrc += width)
for (int x = 0; x < width; ++x)
pwDst[x]=pdwSrc[x];
pFontTexture->Unlock();
return true;
}
CGraphicFontTexture::TCharacterInfomation* CGraphicFontTexture::GetCharacterInfomation(WORD codePage, wchar_t keyValue)
{
TCharacterKey code(codePage, keyValue);
TCharacterInfomationMap::iterator f = m_charInfoMap.find(code);
if (m_charInfoMap.end() == f)
{
return UpdateCharacterInfomation(code);
}
else
{
return &f->second;
}
}
CGraphicFontTexture::TCharacterInfomation* CGraphicFontTexture::UpdateCharacterInfomation(TCharacterKey code)
{
HDC hDC = m_dib.GetDCHandle();
SelectObject(hDC, GetFont(code.first));
wchar_t keyValue = code.second;
if (keyValue == 0x08)
keyValue = L' '; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٲ۴<D9B2> (<28>ƶ<EFBFBD> <20><><EFBFBD>½<EFBFBD> <20><> <20><><EFBFBD><EFBFBD>: NAME:\tTEXT -> TEXT\t:NAME <20><> <20><>ȯ<EFBFBD><C8AF> )
ABCFLOAT stABC;
SIZE size;
if (!GetTextExtentPoint32W(hDC, &keyValue, 1, &size) || !GetCharABCWidthsFloatW(hDC, keyValue, keyValue, &stABC))
return NULL;
size.cx = stABC.abcfB;
if( stABC.abcfA > 0.0f )
size.cx += ceilf(stABC.abcfA);
if( stABC.abcfC > 0.0f )
size.cx += ceilf(stABC.abcfC);
size.cx++;
LONG lAdvance = ceilf( stABC.abcfA + stABC.abcfB + stABC.abcfC );
int width = m_dib.GetWidth();
int height = m_dib.GetHeight();
if (m_x + size.cx >= (width - 1))
{
m_y += (m_step + 1);
m_step = 0;
m_x = 0;
if (m_y + size.cy >= (height - 1))
{
if (!UpdateTexture())
{
return NULL;
}
if (!AppendTexture())
return NULL;
m_y = 0;
}
}
TextOutW(hDC, m_x, m_y, &keyValue, 1);
int nChrX;
int nChrY;
int nChrWidth = size.cx;
int nChrHeight = size.cy;
int nDIBWidth = m_dib.GetWidth();
DWORD*pdwDIBData=(DWORD*)m_dib.GetPointer();
DWORD*pdwDIBBase=pdwDIBData+nDIBWidth*m_y+m_x;
DWORD*pdwDIBRow;
pdwDIBRow=pdwDIBBase;
for (nChrY=0; nChrY<nChrHeight; ++nChrY, pdwDIBRow+=nDIBWidth)
{
for (nChrX=0; nChrX<nChrWidth; ++nChrX)
{
pdwDIBRow[nChrX]=(pdwDIBRow[nChrX]&0xff) ? 0xffff : 0;
}
}
float rhwidth = 1.0f / float(width);
float rhheight = 1.0f / float(height);
TCharacterInfomation& rNewCharInfo = m_charInfoMap[code];
rNewCharInfo.index = m_pFontTextureVector.size() - 1;
rNewCharInfo.width = size.cx;
rNewCharInfo.height = size.cy;
rNewCharInfo.left = float(m_x) * rhwidth;
rNewCharInfo.top = float(m_y) * rhheight;
rNewCharInfo.right = float(m_x+size.cx) * rhwidth;
rNewCharInfo.bottom = float(m_y+size.cy) * rhheight;
rNewCharInfo.advance = (float) lAdvance;
m_x += size.cx;
if (m_step < size.cy)
m_step = size.cy;
m_isDirty = true;
return &rNewCharInfo;
}
bool CGraphicFontTexture::CheckTextureIndex(DWORD dwTexture)
{
if (dwTexture >= m_pFontTextureVector.size())
return false;
return true;
}
void CGraphicFontTexture::SelectTexture(DWORD dwTexture)
{
assert(CheckTextureIndex(dwTexture));
m_lpd3dTexture = m_pFontTextureVector[dwTexture]->GetD3DTexture();
}

View File

@ -0,0 +1,81 @@
#pragma once
#include "GrpTexture.h"
#include "GrpImageTexture.h"
#include "GrpDIB.h"
#include <vector>
#include <map>
class CGraphicFontTexture : public CGraphicTexture
{
public:
typedef std::pair<WORD,wchar_t> TCharacterKey;
typedef struct SCharacterInfomation
{
short index;
short width;
short height;
float left;
float top;
float right;
float bottom;
float advance;
} TCharacterInfomation;
typedef std::vector<TCharacterInfomation*> TPCharacterInfomationVector;
public:
CGraphicFontTexture();
virtual ~CGraphicFontTexture();
void Destroy();
bool Create(const char* c_szFontName, int fontSize, bool bItalic);
bool CreateDeviceObjects();
void DestroyDeviceObjects();
bool CheckTextureIndex(DWORD dwTexture);
void SelectTexture(DWORD dwTexture);
bool UpdateTexture();
TCharacterInfomation* GetCharacterInfomation(WORD codePage, wchar_t keyValue);
TCharacterInfomation* UpdateCharacterInfomation(TCharacterKey code);
bool IsEmpty() const;
protected:
void Initialize();
bool AppendTexture();
HFONT GetFont(WORD codePage);
protected:
typedef std::vector<CGraphicImageTexture*> TGraphicImageTexturePointerVector;
typedef std::map<TCharacterKey, TCharacterInfomation> TCharacterInfomationMap;
typedef std::map<WORD, HFONT> TFontMap;
protected:
CGraphicDib m_dib;
HFONT m_hFontOld;
HFONT m_hFont;
TGraphicImageTexturePointerVector m_pFontTextureVector;
TCharacterInfomationMap m_charInfoMap;
TFontMap m_fontMap;
int m_x;
int m_y;
int m_step;
bool m_isDirty;
TCHAR m_fontName[LF_FACESIZE];
LONG m_fontSize;
bool m_bItalic;
};

92
src/EterLib/GrpImage.cpp Normal file
View File

@ -0,0 +1,92 @@
#include "StdAfx.h"
#include "GrpImage.h"
CGraphicImage::CGraphicImage(const char * c_szFileName, DWORD dwFilter) :
CResource(c_szFileName),
m_dwFilter(dwFilter)
{
m_rect.bottom = m_rect.right = m_rect.top = m_rect.left = 0;
}
CGraphicImage::~CGraphicImage()
{
}
bool CGraphicImage::CreateDeviceObjects()
{
return m_imageTexture.CreateDeviceObjects();
}
void CGraphicImage::DestroyDeviceObjects()
{
m_imageTexture.DestroyDeviceObjects();
}
CGraphicImage::TType CGraphicImage::Type()
{
static TType s_type = StringToType("CGraphicImage");
return s_type;
}
bool CGraphicImage::OnIsType(TType type)
{
if (CGraphicImage::Type() == type)
return true;
return CResource::OnIsType(type);
}
int CGraphicImage::GetWidth() const
{
return m_rect.right - m_rect.left;
}
int CGraphicImage::GetHeight() const
{
return m_rect.bottom - m_rect.top;
}
const CGraphicTexture& CGraphicImage::GetTextureReference() const
{
return m_imageTexture;
}
CGraphicTexture* CGraphicImage::GetTexturePointer()
{
return &m_imageTexture;
}
const RECT& CGraphicImage::GetRectReference() const
{
return m_rect;
}
bool CGraphicImage::OnLoad(int iSize, const void * c_pvBuf)
{
if (!c_pvBuf)
return false;
m_imageTexture.SetFileName(CResource::GetFileName());
// Ư<><C6AF> <20><>ǻ<EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD> Unknown<77><6E><EFBFBD><EFBFBD> '<27><>'<27>ϸ<EFBFBD> ƨ<><C6A8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>-_-; -<2D><><EFBFBD><EFBFBD>
if (!m_imageTexture.CreateFromMemoryFile(iSize, c_pvBuf, D3DFMT_UNKNOWN, m_dwFilter))
return false;
m_rect.left = 0;
m_rect.top = 0;
m_rect.right = m_imageTexture.GetWidth();
m_rect.bottom = m_imageTexture.GetHeight();
return true;
}
void CGraphicImage::OnClear()
{
// Tracef("Image Destroy : %s\n", m_pszFileName);
m_imageTexture.Destroy();
memset(&m_rect, 0, sizeof(m_rect));
}
bool CGraphicImage::OnIsEmpty() const
{
return m_imageTexture.IsEmpty();
}

44
src/EterLib/GrpImage.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef __INC_GRPIMAGE_H__
#define __INC_GRPIMAGE_H__
#include "Ref.h"
#include "Resource.h"
#include "GrpImageTexture.h"
class CGraphicImage : public CResource
{
public:
typedef CRef<CGraphicImage> TRef;
public:
static TType Type();
public:
CGraphicImage(const char* c_szFileName, DWORD dwFilter = D3DX_FILTER_LINEAR);
virtual ~CGraphicImage();
virtual bool CreateDeviceObjects();
virtual void DestroyDeviceObjects();
int GetWidth() const;
int GetHeight() const;
const RECT & GetRectReference() const;
const CGraphicTexture & GetTextureReference() const;
CGraphicTexture * GetTexturePointer();
protected:
bool OnLoad(int iSize, const void * c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
protected:
CGraphicImageTexture m_imageTexture;
RECT m_rect;
DWORD m_dwFilter;
};
#endif

View File

@ -0,0 +1,222 @@
#include "StdAfx.h"
#include "GrpImageInstance.h"
#include "StateManager.h"
#include "../eterBase/CRC32.h"
//STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
//STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
//STATEMANAGER.RestoreRenderState(D3DRS_SRCBLEND);
//STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND);
CDynamicPool<CGraphicImageInstance> CGraphicImageInstance::ms_kPool;
void CGraphicImageInstance::CreateSystem(UINT uCapacity)
{
ms_kPool.Create(uCapacity);
}
void CGraphicImageInstance::DestroySystem()
{
ms_kPool.Destroy();
}
CGraphicImageInstance* CGraphicImageInstance::New()
{
return ms_kPool.Alloc();
}
void CGraphicImageInstance::Delete(CGraphicImageInstance* pkImgInst)
{
pkImgInst->Destroy();
ms_kPool.Free(pkImgInst);
}
void CGraphicImageInstance::Render()
{
if (IsEmpty())
return;
assert(!IsEmpty());
OnRender();
}
void CGraphicImageInstance::OnRender()
{
CGraphicImage * pImage = m_roImage.GetPointer();
CGraphicTexture * pTexture = pImage->GetTexturePointer();
float fimgWidth = pImage->GetWidth();
float fimgHeight = pImage->GetHeight();
const RECT& c_rRect = pImage->GetRectReference();
float texReverseWidth = 1.0f / float(pTexture->GetWidth());
float texReverseHeight = 1.0f / float(pTexture->GetHeight());
float su = c_rRect.left * texReverseWidth;
float sv = c_rRect.top * texReverseHeight;
float eu = (c_rRect.left + (c_rRect.right-c_rRect.left)) * texReverseWidth;
float ev = (c_rRect.top + (c_rRect.bottom-c_rRect.top)) * texReverseHeight;
TPDTVertex vertices[4];
vertices[0].position.x = m_v2Position.x-0.5f;
vertices[0].position.y = m_v2Position.y-0.5f;
vertices[0].position.z = 0.0f;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[0].diffuse = m_DiffuseColor;
vertices[1].position.x = m_v2Position.x + fimgWidth-0.5f;
vertices[1].position.y = m_v2Position.y-0.5f;
vertices[1].position.z = 0.0f;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[1].diffuse = m_DiffuseColor;
vertices[2].position.x = m_v2Position.x-0.5f;
vertices[2].position.y = m_v2Position.y + fimgHeight-0.5f;
vertices[2].position.z = 0.0f;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[2].diffuse = m_DiffuseColor;
vertices[3].position.x = m_v2Position.x + fimgWidth-0.5f;
vertices[3].position.y = m_v2Position.y + fimgHeight-0.5f;
vertices[3].position.z = 0.0f;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
vertices[3].diffuse = m_DiffuseColor;
// 2004.11.18.myevan.ctrl+alt+del <20>ݺ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ƨ<><C6A8><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
if (CGraphicBase::SetPDTStream(vertices, 4))
{
CGraphicBase::SetDefaultIndexBuffer(CGraphicBase::DEFAULT_IB_FILL_RECT);
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
}
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
////////////////////////////////////////////////////////////
}
const CGraphicTexture & CGraphicImageInstance::GetTextureReference() const
{
return m_roImage->GetTextureReference();
}
CGraphicTexture * CGraphicImageInstance::GetTexturePointer()
{
CGraphicImage* pkImage = m_roImage.GetPointer();
return pkImage ? pkImage->GetTexturePointer() : NULL;
}
CGraphicImage * CGraphicImageInstance::GetGraphicImagePointer()
{
return m_roImage.GetPointer();
}
int CGraphicImageInstance::GetWidth()
{
if (IsEmpty())
return 0;
return m_roImage->GetWidth();
}
int CGraphicImageInstance::GetHeight()
{
if (IsEmpty())
return 0;
return m_roImage->GetHeight();
}
void CGraphicImageInstance::SetDiffuseColor(float fr, float fg, float fb, float fa)
{
m_DiffuseColor.r = fr;
m_DiffuseColor.g = fg;
m_DiffuseColor.b = fb;
m_DiffuseColor.a = fa;
}
void CGraphicImageInstance::SetPosition(float fx, float fy)
{
m_v2Position.x = fx;
m_v2Position.y = fy;
}
void CGraphicImageInstance::SetImagePointer(CGraphicImage * pImage)
{
m_roImage.SetPointer(pImage);
OnSetImagePointer();
}
void CGraphicImageInstance::ReloadImagePointer(CGraphicImage * pImage)
{
if (m_roImage.IsNull())
{
SetImagePointer(pImage);
return;
}
CGraphicImage * pkImage = m_roImage.GetPointer();
if (pkImage)
pkImage->Reload();
}
bool CGraphicImageInstance::IsEmpty() const
{
if (!m_roImage.IsNull() && !m_roImage->IsEmpty())
return false;
return true;
}
bool CGraphicImageInstance::operator == (const CGraphicImageInstance & rhs) const
{
return (m_roImage.GetPointer() == rhs.m_roImage.GetPointer());
}
DWORD CGraphicImageInstance::Type()
{
static DWORD s_dwType = GetCRC32("CGraphicImageInstance", strlen("CGraphicImageInstance"));
return (s_dwType);
}
BOOL CGraphicImageInstance::IsType(DWORD dwType)
{
return OnIsType(dwType);
}
BOOL CGraphicImageInstance::OnIsType(DWORD dwType)
{
if (CGraphicImageInstance::Type() == dwType)
return TRUE;
return FALSE;
}
void CGraphicImageInstance::OnSetImagePointer()
{
}
void CGraphicImageInstance::Initialize()
{
m_DiffuseColor.r = m_DiffuseColor.g = m_DiffuseColor.b = m_DiffuseColor.a = 1.0f;
m_v2Position.x = m_v2Position.y = 0.0f;
}
void CGraphicImageInstance::Destroy()
{
m_roImage.SetPointer(NULL); // CRef <20><><EFBFBD><EFBFBD> <20><><EFBFBD>۷<EFBFBD><DBB7><EFBFBD> ī<><C4AB>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>.
Initialize();
}
CGraphicImageInstance::CGraphicImageInstance()
{
Initialize();
}
CGraphicImageInstance::~CGraphicImageInstance()
{
Destroy();
}

View File

@ -0,0 +1,60 @@
#pragma once
#include "GrpImage.h"
#include "GrpIndexBuffer.h"
#include "GrpVertexBufferDynamic.h"
#include "Pool.h"
class CGraphicImageInstance
{
public:
static DWORD Type();
BOOL IsType(DWORD dwType);
public:
CGraphicImageInstance();
virtual ~CGraphicImageInstance();
void Destroy();
void Render();
void SetDiffuseColor(float fr, float fg, float fb, float fa);
void SetPosition(float fx, float fy);
void SetImagePointer(CGraphicImage* pImage);
void ReloadImagePointer(CGraphicImage* pImage);
bool IsEmpty() const;
int GetWidth();
int GetHeight();
CGraphicTexture * GetTexturePointer();
const CGraphicTexture & GetTextureReference() const;
CGraphicImage * GetGraphicImagePointer();
bool operator == (const CGraphicImageInstance & rhs) const;
protected:
void Initialize();
virtual void OnRender();
virtual void OnSetImagePointer();
virtual BOOL OnIsType(DWORD dwType);
protected:
D3DXCOLOR m_DiffuseColor;
D3DXVECTOR2 m_v2Position;
CGraphicImage::TRef m_roImage;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicImageInstance* New();
static void Delete(CGraphicImageInstance* pkImgInst);
static CDynamicPool<CGraphicImageInstance> ms_kPool;
};

View File

@ -0,0 +1,329 @@
#include "StdAfx.h"
#include "../eterBase/MappedFile.h"
#include "../eterPack/EterPackManager.h"
#include "GrpImageTexture.h"
bool CGraphicImageTexture::Lock(int* pRetPitch, void** ppRetPixels, int level)
{
D3DLOCKED_RECT lockedRect;
if (FAILED(m_lpd3dTexture->LockRect(level, &lockedRect, NULL, 0)))
return false;
*pRetPitch = lockedRect.Pitch;
*ppRetPixels = (void*)lockedRect.pBits;
return true;
}
void CGraphicImageTexture::Unlock(int level)
{
assert(m_lpd3dTexture != NULL);
m_lpd3dTexture->UnlockRect(level);
}
void CGraphicImageTexture::Initialize()
{
CGraphicTexture::Initialize();
m_stFileName = "";
m_d3dFmt=D3DFMT_UNKNOWN;
m_dwFilter=0;
}
void CGraphicImageTexture::Destroy()
{
CGraphicTexture::Destroy();
Initialize();
}
bool CGraphicImageTexture::CreateDeviceObjects()
{
assert(ms_lpd3dDevice != NULL);
assert(m_lpd3dTexture == NULL);
if (m_stFileName.empty())
{
// <20><>Ʈ <20>ؽ<EFBFBD><D8BD><EFBFBD>
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, 0, m_d3dFmt, D3DPOOL_MANAGED, &m_lpd3dTexture)))
return false;
}
else
{
CMappedFile mappedFile;
LPCVOID c_pvMap;
if (!CEterPackManager::Instance().Get(mappedFile, m_stFileName.c_str(), &c_pvMap))
return false;
return CreateFromMemoryFile(mappedFile.Size(), c_pvMap, m_d3dFmt, m_dwFilter);
}
m_bEmpty = false;
return true;
}
bool CGraphicImageTexture::Create(UINT width, UINT height, D3DFORMAT d3dFmt, DWORD dwFilter)
{
assert(ms_lpd3dDevice != NULL);
Destroy();
m_width = width;
m_height = height;
m_d3dFmt = d3dFmt;
m_dwFilter = dwFilter;
return CreateDeviceObjects();
}
void CGraphicImageTexture::CreateFromTexturePointer(const CGraphicTexture * c_pSrcTexture)
{
if (m_lpd3dTexture)
m_lpd3dTexture->Release();
m_width = c_pSrcTexture->GetWidth();
m_height = c_pSrcTexture->GetHeight();
m_lpd3dTexture = c_pSrcTexture->GetD3DTexture();
if (m_lpd3dTexture)
m_lpd3dTexture->AddRef();
m_bEmpty = false;
}
bool CGraphicImageTexture::CreateDDSTexture(CDXTCImage & image, const BYTE * /*c_pbBuf*/)
{
int mipmapCount = image.m_dwMipMapCount == 0 ? 1 : image.m_dwMipMapCount;
D3DFORMAT format;
LPDIRECT3DTEXTURE8 lpd3dTexture;
D3DPOOL pool = ms_bSupportDXT ? D3DPOOL_MANAGED : D3DPOOL_SCRATCH;;
if(image.m_CompFormat == PF_DXT5)
format = D3DFMT_DXT5;
else if(image.m_CompFormat == PF_DXT3)
format = D3DFMT_DXT3;
else
format = D3DFMT_DXT1;
UINT uTexBias=0;
if (IsLowTextureMemory())
uTexBias=1;
UINT uMinMipMapIndex=0;
if (uTexBias>0)
{
if (mipmapCount>uTexBias)
{
uMinMipMapIndex=uTexBias;
image.m_nWidth>>=uTexBias;
image.m_nHeight>>=uTexBias;
mipmapCount-=uTexBias;
}
}
if (FAILED(D3DXCreateTexture( ms_lpd3dDevice, image.m_nWidth, image.m_nHeight,
mipmapCount, 0, format, pool, &lpd3dTexture)))
{
TraceError("CreateDDSTexture: Cannot creatre texture");
return false;
}
for (DWORD i = 0; i < mipmapCount; ++i)
{
D3DLOCKED_RECT lockedRect;
if (FAILED(lpd3dTexture->LockRect(i, &lockedRect, NULL, 0)))
{
TraceError("CreateDDSTexture: Cannot lock texture");
}
else
{
image.Copy(i+uMinMipMapIndex, (BYTE*)lockedRect.pBits, lockedRect.Pitch);
lpd3dTexture->UnlockRect(i);
}
}
if(ms_bSupportDXT)
{
m_lpd3dTexture = lpd3dTexture;
}
else
{
if(image.m_CompFormat == PF_DXT3 || image.m_CompFormat == PF_DXT5)
format = D3DFMT_A4R4G4B4;
else
format = D3DFMT_A1R5G5B5;
UINT imgWidth=image.m_nWidth;
UINT imgHeight=image.m_nHeight;
extern bool GRAPHICS_CAPS_HALF_SIZE_IMAGE;
if (GRAPHICS_CAPS_HALF_SIZE_IMAGE && uTexBias>0 && mipmapCount==0)
{
imgWidth>>=uTexBias;
imgHeight>>=uTexBias;
}
if (FAILED(D3DXCreateTexture( ms_lpd3dDevice, imgWidth, imgHeight,
mipmapCount, 0, format, D3DPOOL_MANAGED, &m_lpd3dTexture)))
{
TraceError("CreateDDSTexture: Cannot creatre texture");
return false;
}
IDirect3DTexture8* pkTexSrc=lpd3dTexture;
IDirect3DTexture8* pkTexDst=m_lpd3dTexture;
for(int i=0; i<mipmapCount; ++i) {
IDirect3DSurface8* ppsSrc = NULL;
IDirect3DSurface8* ppsDst = NULL;
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
{
if (SUCCEEDED(pkTexDst->GetSurfaceLevel(i, &ppsDst)))
{
D3DXLoadSurfaceFromSurface(ppsDst, NULL, NULL, ppsSrc, NULL, NULL, D3DX_FILTER_NONE, 0);
ppsDst->Release();
}
ppsSrc->Release();
}
}
lpd3dTexture->Release();
}
m_width = image.m_nWidth;
m_height = image.m_nHeight;
m_bEmpty = false;
return true;
}
bool CGraphicImageTexture::CreateFromMemoryFile(UINT bufSize, const void * c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter)
{
assert(ms_lpd3dDevice != NULL);
assert(m_lpd3dTexture == NULL);
static CDXTCImage image;
if (image.LoadHeaderFromMemory((const BYTE *) c_pvBuf)) // DDS<44>ΰ<EFBFBD> Ȯ<><C8AE>
{
return (CreateDDSTexture(image, (const BYTE *) c_pvBuf));
}
else
{
D3DXIMAGE_INFO imageInfo;
if (FAILED(D3DXCreateTextureFromFileInMemoryEx(
ms_lpd3dDevice,
c_pvBuf,
bufSize,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
d3dFmt,
D3DPOOL_MANAGED,
dwFilter,
dwFilter,
0xffff00ff,
&imageInfo,
NULL,
&m_lpd3dTexture)))
{
TraceError("CreateFromMemoryFile: Cannot create texture");
return false;
}
m_width = imageInfo.Width;
m_height = imageInfo.Height;
D3DFORMAT format=imageInfo.Format;
switch(imageInfo.Format) {
case D3DFMT_A8R8G8B8:
format = D3DFMT_A4R4G4B4;
break;
case D3DFMT_X8R8G8B8:
case D3DFMT_R8G8B8:
format = D3DFMT_A1R5G5B5;
break;
}
UINT uTexBias=0;
extern bool GRAPHICS_CAPS_HALF_SIZE_IMAGE;
if (GRAPHICS_CAPS_HALF_SIZE_IMAGE)
uTexBias=1;
if (IsLowTextureMemory())
if (uTexBias || format!=imageInfo.Format)
{
IDirect3DTexture8* pkTexSrc=m_lpd3dTexture;
IDirect3DTexture8* pkTexDst;
if (SUCCEEDED(D3DXCreateTexture(
ms_lpd3dDevice,
imageInfo.Width>>uTexBias,
imageInfo.Height>>uTexBias,
imageInfo.MipLevels,
0,
format,
D3DPOOL_MANAGED,
&pkTexDst)))
{
m_lpd3dTexture=pkTexDst;
for(int i=0; i<imageInfo.MipLevels; ++i) {
IDirect3DSurface8* ppsSrc = NULL;
IDirect3DSurface8* ppsDst = NULL;
if (SUCCEEDED(pkTexSrc->GetSurfaceLevel(i, &ppsSrc)))
{
if (SUCCEEDED(pkTexDst->GetSurfaceLevel(i, &ppsDst)))
{
D3DXLoadSurfaceFromSurface(ppsDst, NULL, NULL, ppsSrc, NULL, NULL, D3DX_FILTER_LINEAR, 0);
ppsDst->Release();
}
ppsSrc->Release();
}
}
pkTexSrc->Release();
}
}
}
m_bEmpty = false;
return true;
}
void CGraphicImageTexture::SetFileName(const char * c_szFileName)
{
m_stFileName=c_szFileName;
}
bool CGraphicImageTexture::CreateFromDiskFile(const char * c_szFileName, D3DFORMAT d3dFmt, DWORD dwFilter)
{
Destroy();
SetFileName(c_szFileName);
m_d3dFmt = d3dFmt;
m_dwFilter = dwFilter;
return CreateDeviceObjects();
}
CGraphicImageTexture::CGraphicImageTexture()
{
Initialize();
}
CGraphicImageTexture::~CGraphicImageTexture()
{
Destroy();
}

View File

@ -0,0 +1,34 @@
#pragma once
#include "GrpTexture.h"
#include "../eterImageLib/DXTCImage.h"
class CGraphicImageTexture : public CGraphicTexture
{
public:
CGraphicImageTexture();
virtual ~CGraphicImageTexture();
void Destroy();
bool Create(UINT width, UINT height, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
bool CreateDeviceObjects();
void CreateFromTexturePointer(const CGraphicTexture* c_pSrcTexture);
bool CreateFromDiskFile(const char* c_szFileName, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
bool CreateFromMemoryFile(UINT bufSize, const void* c_pvBuf, D3DFORMAT d3dFmt, DWORD dwFilter = D3DX_FILTER_LINEAR);
bool CreateDDSTexture(CDXTCImage & image, const BYTE * c_pbBuf);
void SetFileName(const char * c_szFileName);
bool Lock(int* pRetPitch, void** ppRetPixels, int level=0);
void Unlock(int level=0);
protected:
void Initialize();
D3DFORMAT m_d3dFmt;
DWORD m_dwFilter;
std::string m_stFileName;
};

View File

@ -0,0 +1,139 @@
#include "StdAfx.h"
#include "../eterBase/Stl.h"
#include "GrpIndexBuffer.h"
#include "StateManager.h"
LPDIRECT3DINDEXBUFFER8 CGraphicIndexBuffer::GetD3DIndexBuffer() const
{
assert(m_lpd3dIdxBuf!=NULL);
return m_lpd3dIdxBuf;
}
void CGraphicIndexBuffer::SetIndices(int startIndex) const
{
assert(ms_lpd3dDevice!=NULL);
STATEMANAGER.SetIndices(m_lpd3dIdxBuf, startIndex);
}
bool CGraphicIndexBuffer::Lock(void** pretIndices) const
{
assert(m_lpd3dIdxBuf!=NULL);
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0)))
return false;
return true;
}
void CGraphicIndexBuffer::Unlock() const
{
assert(m_lpd3dIdxBuf!=NULL);
m_lpd3dIdxBuf->Unlock();
}
bool CGraphicIndexBuffer::Lock(void** pretIndices)
{
assert(m_lpd3dIdxBuf!=NULL);
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)pretIndices, 0)))
return false;
return true;
}
void CGraphicIndexBuffer::Unlock()
{
assert(m_lpd3dIdxBuf!=NULL);
m_lpd3dIdxBuf->Unlock();
}
bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices)
{
assert(m_lpd3dIdxBuf!=NULL);
BYTE* dstIndices;
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, &dstIndices, 0)))
return false;
memcpy(dstIndices, srcIndices, bufSize);
m_lpd3dIdxBuf->Unlock();
return true;
}
bool CGraphicIndexBuffer::Create(int faceCount, TFace* faces)
{
int idxCount = faceCount * 3;
m_iidxCount = idxCount;
if (!Create(idxCount, D3DFMT_INDEX16))
return false;
WORD* dstIndices;
if (FAILED(m_lpd3dIdxBuf->Lock(0, 0, (BYTE**)&dstIndices, 0)))
return false;
for (int i = 0; i<faceCount; ++i, dstIndices+=3)
{
TFace * curFace=faces+i;
dstIndices[0]=curFace->indices[0];
dstIndices[1]=curFace->indices[1];
dstIndices[2]=curFace->indices[2];
}
m_lpd3dIdxBuf->Unlock();
return true;
}
bool CGraphicIndexBuffer::CreateDeviceObjects()
{
if (FAILED(ms_lpd3dDevice->CreateIndexBuffer(
m_dwBufferSize,
D3DUSAGE_WRITEONLY,
m_d3dFmt,
D3DPOOL_MANAGED,
&m_lpd3dIdxBuf)
))
return false;
return true;
}
void CGraphicIndexBuffer::DestroyDeviceObjects()
{
safe_release(m_lpd3dIdxBuf);
}
bool CGraphicIndexBuffer::Create(int idxCount, D3DFORMAT d3dFmt)
{
Destroy();
m_iidxCount = idxCount;
m_dwBufferSize = sizeof(WORD) * idxCount;
m_d3dFmt = d3dFmt;
return CreateDeviceObjects();
}
void CGraphicIndexBuffer::Destroy()
{
DestroyDeviceObjects();
}
void CGraphicIndexBuffer::Initialize()
{
m_lpd3dIdxBuf=NULL;
}
CGraphicIndexBuffer::CGraphicIndexBuffer()
{
Initialize();
}
CGraphicIndexBuffer::~CGraphicIndexBuffer()
{
Destroy();
}

View File

@ -0,0 +1,40 @@
#pragma once
#include "GrpBase.h"
class CGraphicIndexBuffer : public CGraphicBase
{
public:
CGraphicIndexBuffer();
virtual ~CGraphicIndexBuffer();
void Destroy();
bool Create(int idxCount, D3DFORMAT d3dFmt);
bool Create(int faceCount, TFace* faces);
bool CreateDeviceObjects();
void DestroyDeviceObjects();
bool Copy(int bufSize, const void* srcIndices);
bool Lock(void** pretIndices) const;
void Unlock() const;
bool Lock(void** pretIndices);
void Unlock();
void SetIndices(int startIndex=0) const;
LPDIRECT3DINDEXBUFFER8 GetD3DIndexBuffer() const;
int GetIndexCount() const {return m_iidxCount;}
protected:
void Initialize();
protected:
LPDIRECT3DINDEXBUFFER8 m_lpd3dIdxBuf;
DWORD m_dwBufferSize;
D3DFORMAT m_d3dFmt;
int m_iidxCount;
};

View File

@ -0,0 +1,345 @@
#include "StdAfx.h"
#include <algorithm>
#include "../eterBase/Timer.h"
#include "GrpLightManager.h"
#include "StateManager.h"
float CLightBase::ms_fCurTime = 0.0f;
CLightManager::CLightManager()
{
m_v3CenterPosition = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
m_dwLimitLightCount = LIGHT_LIMIT_DEFAULT;
}
CLightManager::~CLightManager()
{
}
void CLightManager::Destroy()
{
m_LightPool.Destroy();
}
void CLightManager::Initialize()
{
SetSkipIndex(1);
m_NonUsingLightIDDeque.clear();
m_LightMap.clear();
m_LightPool.FreeAll();
}
void CLightManager::RegisterLight(ELightType /*LightType*/, TLightID * poutLightID, D3DLIGHT8 & LightData)
{
CLight * pLight = m_LightPool.Alloc();
TLightID ID = NewLightID();
pLight->SetParameter(ID, LightData);
m_LightMap[ID] = pLight;
*poutLightID = ID;
}
void CLightManager::DeleteLight(TLightID LightID)
{
TLightMap::iterator itor = m_LightMap.find(LightID);
if (m_LightMap.end() == itor)
{
assert(!"CLightManager::DeleteLight - Failed to find light ID!");
return;
}
CLight * pLight = itor->second;
pLight->Clear();
m_LightPool.Free(pLight);
m_LightMap.erase(itor);
ReleaseLightID(LightID);
}
CLight * CLightManager::GetLight(TLightID LightID)
{
TLightMap::iterator itor = m_LightMap.find(LightID);
if (m_LightMap.end() == itor)
{
assert(!"CLightManager::SetLightData - Failed to find light ID!");
return NULL;
}
return itor->second;
}
void CLightManager::SetCenterPosition(const D3DXVECTOR3 & c_rv3Position)
{
m_v3CenterPosition = c_rv3Position;
}
void CLightManager::SetLimitLightCount(DWORD dwLightCount)
{
m_dwLimitLightCount = dwLightCount;
}
void CLightManager::SetSkipIndex(DWORD dwSkipIndex)
{
m_dwSkipIndex = dwSkipIndex;
}
struct LightComp
{
bool operator () (const CLight * l, const CLight * r) const
{
return l->GetDistance() < r->GetDistance();
}
};
// NOTE : FlushLight<68><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><> <20><> <20>ݵ<EFBFBD><DDB5><EFBFBD> RestoreLight<68><74> <20><><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD> <20>Ѵ<EFBFBD>.
void CLightManager::FlushLight()
{
Update();
m_LightSortVector.clear();
// NOTE: Dynamic<69><63> Static<69><63> <20>и<EFBFBD> <20><>Ű<EFBFBD><C5B0> CenterPosition<6F><6E> <20>ٲ𶧸<D9B2><F0B6A7B8><EFBFBD> Static<69><63>
// <20>ٽ<EFBFBD> Flush <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ȭ <20><> <20><> <20>ִ<EFBFBD>. - [levites]
// light<68><74><EFBFBD><EFBFBD> <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
TLightMap::iterator itor = m_LightMap.begin();
for (; itor != m_LightMap.end(); ++itor)
{
CLight * pLight = itor->second;
D3DXVECTOR3 v3LightPos(pLight->GetPosition());
D3DXVECTOR3 v3Distance(v3LightPos - m_v3CenterPosition);
pLight->SetDistance(D3DXVec3Length(&v3Distance));
m_LightSortVector.push_back(pLight);
}
// quick sort lights
std::sort(m_LightSortVector.begin(), m_LightSortVector.end(), LightComp());
// NOTE - <20>Ÿ<EFBFBD><C5B8><EFBFBD> <20><><EFBFBD>ĵ<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> Limit <20><><EFBFBD><EFBFBD> <20><>ŭ <20><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD> <20><><EFBFBD>ش<EFBFBD>.
STATEMANAGER.SaveRenderState(D3DRS_LIGHTING, TRUE);
for (DWORD k = 0; k < min(m_dwLimitLightCount, m_LightSortVector.size()); ++k)
{
m_LightSortVector[k]->Update();
m_LightSortVector[k]->SetDeviceLight(TRUE);
}
}
void CLightManager::RestoreLight()
{
STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING);
for (DWORD k = 0; k < min(m_dwLimitLightCount, m_LightSortVector.size()); ++k)
m_LightSortVector[k]->SetDeviceLight(FALSE);
}
TLightID CLightManager::NewLightID()
{
if (!m_NonUsingLightIDDeque.empty())
{
TLightID id = m_NonUsingLightIDDeque.back();
m_NonUsingLightIDDeque.pop_back();
return (id);
}
return m_dwSkipIndex + m_LightMap.size();
}
void CLightManager::ReleaseLightID(TLightID LightID)
{
m_NonUsingLightIDDeque.push_back(LightID);
}
void CLightManager::Update()
{
//static DWORD s_dwStartTime = ELTimer_GetMSec();
//ms_fCurTime = float(ELTimer_GetMSec() - s_dwStartTime) / 1000.0f;
ms_fCurTime = CTimer::Instance().GetCurrentSecond();
}
//////////////////////////////////////////////////////////////////////////
CLight::CLight()
{
Initialize();
}
CLight::~CLight()
{
Clear();
}
void CLight::Initialize()
{
m_LightID = 0;
m_isEdited = TRUE;
m_fDistance = 0.0f;
memset(&m_d3dLight, 0, sizeof(m_d3dLight));
m_d3dLight.Type = D3DLIGHT_POINT;
m_d3dLight.Attenuation0 = 0.0f;
m_d3dLight.Attenuation1 = 1.0f;
m_d3dLight.Attenuation2 = 0.0f;
}
void CLight::Clear()
{
if (m_LightID)
SetDeviceLight(FALSE);
Initialize();
}
void CLight::SetDeviceLight(BOOL bActive)
{
if (bActive && m_isEdited)
{
if (ms_lpd3dDevice)
ms_lpd3dDevice->SetLight(m_LightID, &m_d3dLight);
}
if (ms_lpd3dDevice)
{
ms_lpd3dDevice->LightEnable(m_LightID, bActive);
}
}
void CLight::SetParameter(TLightID id, const D3DLIGHT8 & c_rLight)
{
m_LightID = id;
m_d3dLight = c_rLight;
}
void CLight::SetDiffuseColor(float fr, float fg, float fb, float fa)
{
if (m_d3dLight.Diffuse.r == fr
&& m_d3dLight.Diffuse.g == fg
&& m_d3dLight.Diffuse.b == fb
&& m_d3dLight.Diffuse.a == fa
)
return;
m_d3dLight.Diffuse.r = fr;
m_d3dLight.Diffuse.g = fg;
m_d3dLight.Diffuse.b = fb;
m_d3dLight.Diffuse.a = fa;
m_isEdited = TRUE;
}
void CLight::SetAmbientColor(float fr, float fg, float fb, float fa)
{
if (m_d3dLight.Ambient.r == fr
&& m_d3dLight.Ambient.g == fg
&& m_d3dLight.Ambient.b == fb
&& m_d3dLight.Ambient.a == fa
)
return;
m_d3dLight.Ambient.r = fr;
m_d3dLight.Ambient.g = fg;
m_d3dLight.Ambient.b = fb;
m_d3dLight.Ambient.a = fa;
m_isEdited = TRUE;
}
void CLight::SetRange(float fRange)
{
if (m_d3dLight.Range == fRange)
return;
m_d3dLight.Range = fRange;
m_isEdited = TRUE;
}
const D3DVECTOR & CLight::GetPosition() const
{
return m_d3dLight.Position;
}
void CLight::SetPosition(float fx, float fy, float fz)
{
if (m_d3dLight.Position.x == fx && m_d3dLight.Position.y == fy && m_d3dLight.Position.z == fz)
return;
m_d3dLight.Position.x = fx;
m_d3dLight.Position.y = fy;
m_d3dLight.Position.z = fz;
m_isEdited = TRUE;
}
void CLight::SetDistance(float fDistance)
{
m_fDistance = fDistance;
}
void CLight::BlendDiffuseColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime)
{
D3DXCOLOR Color(m_d3dLight.Diffuse);
m_DiffuseColorTransitor.SetTransition(Color, c_rColor, ms_fCurTime + fDelayTime, fBlendTime);
}
void CLight::BlendAmbientColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime)
{
D3DXCOLOR Color(m_d3dLight.Ambient);
m_AmbientColorTransitor.SetTransition(Color, c_rColor, ms_fCurTime + fDelayTime, fBlendTime);
}
void CLight::BlendRange(float fRange, float fBlendTime, float fDelayTime)
{
m_RangeTransitor.SetTransition(m_d3dLight.Range, fRange, ms_fCurTime + fDelayTime, fBlendTime);
}
void CLight::Update()
{
if (m_AmbientColorTransitor.isActiveTime(ms_fCurTime))
{
if (!m_AmbientColorTransitor.isActive())
{
m_AmbientColorTransitor.SetActive();
m_AmbientColorTransitor.SetSourceValue(m_d3dLight.Ambient);
}
else
{
D3DXCOLOR Color;
m_AmbientColorTransitor.GetValue(ms_fCurTime, &Color);
SetAmbientColor(Color.r, Color.g, Color.b, Color.a);
}
}
if (m_DiffuseColorTransitor.isActiveTime(ms_fCurTime))
{
if (!m_DiffuseColorTransitor.isActive())
{
m_DiffuseColorTransitor.SetActive();
m_DiffuseColorTransitor.SetSourceValue(m_d3dLight.Diffuse);
}
else
{
D3DXCOLOR Color;
m_DiffuseColorTransitor.GetValue(ms_fCurTime, &Color);
SetDiffuseColor(Color.r, Color.g, Color.b, Color.a);
}
}
if (m_RangeTransitor.isActiveTime(ms_fCurTime))
{
if (!m_RangeTransitor.isActive())
{
m_RangeTransitor.SetActive();
m_RangeTransitor.SetSourceValue(m_d3dLight.Range);
}
else
{
float fRange;
m_RangeTransitor.GetValue(ms_fCurTime, &fRange);
SetRange(fRange);
}
}
}

View File

@ -0,0 +1,127 @@
#pragma once
#include "../eterBase/Singleton.h"
#include "GrpBase.h"
#include "Util.h"
#include "Pool.h"
#include <deque>
typedef DWORD TLightID;
enum ELightType
{
LIGHT_TYPE_STATIC, // Continuously turning on light
LIGHT_TYPE_DYNAMIC, // Immediately turning off light
};
class CLightBase
{
public:
CLightBase() {};
virtual ~CLightBase() {};
void SetCurrentTime();
protected:
static float ms_fCurTime;
};
class CLight : public CGraphicBase, public CLightBase
{
public:
CLight();
virtual ~CLight();
void Initialize();
void Clear();
void Update();
void SetParameter(TLightID id, const D3DLIGHT8 & c_rLight);
void SetDistance(float fDistance);
float GetDistance() const { return m_fDistance; }
TLightID GetLightID() { return m_LightID; }
BOOL isEdited() { return m_isEdited; }
void SetDeviceLight(BOOL bActive);
void SetDiffuseColor(float fr, float fg, float fb, float fa = 1.0f);
void SetAmbientColor(float fr, float fg, float fb, float fa = 1.0f);
void SetRange(float fRange);
void SetPosition(float fx, float fy, float fz);
const D3DVECTOR & GetPosition() const;
void BlendDiffuseColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime = 0.0f);
void BlendAmbientColor(const D3DXCOLOR & c_rColor, float fBlendTime, float fDelayTime = 0.0f);
void BlendRange(float fRange, float fBlendTime, float fDelayTime = 0.0f);
private:
TLightID m_LightID; // Light ID. equal to D3D light index
D3DLIGHT8 m_d3dLight;
BOOL m_isEdited;
float m_fDistance;
TTransitorColor m_DiffuseColorTransitor;
TTransitorColor m_AmbientColorTransitor;
TTransitorFloat m_RangeTransitor;
};
class CLightManager : public CGraphicBase, public CLightBase, public CSingleton<CLightManager>
{
public:
enum
{
LIGHT_LIMIT_DEFAULT = 3,
// LIGHT_MAX_NUM = 32,
};
typedef std::deque<TLightID> TLightIDDeque;
typedef std::map<TLightID, CLight *> TLightMap;
typedef std::vector<CLight *> TLightSortVector;
public:
CLightManager();
virtual ~CLightManager();
void Destroy();
void Initialize();
// NOTE : FlushLight<68><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><> <20><> <20>ݵ<EFBFBD><DDB5><EFBFBD> RestoreLight<68><74> <20><><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD> <20>Ѵ<EFBFBD>.
void Update();
void FlushLight();
void RestoreLight();
/////
void RegisterLight(ELightType LightType, TLightID * poutLightID, D3DLIGHT8 & LightData);
CLight * GetLight(TLightID LightID);
void DeleteLight(TLightID LightID);
/////
void SetCenterPosition(const D3DXVECTOR3 & c_rv3Position);
void SetLimitLightCount(DWORD dwLightCount);
void SetSkipIndex(DWORD dwSkipIndex);
protected:
TLightIDDeque m_NonUsingLightIDDeque;
TLightMap m_LightMap;
TLightSortVector m_LightSortVector;
D3DXVECTOR3 m_v3CenterPosition;
DWORD m_dwLimitLightCount;
DWORD m_dwSkipIndex;
protected:
TLightID NewLightID();
void ReleaseLightID(TLightID LightID);
CDynamicPool<CLight> m_LightPool;
};

View File

@ -0,0 +1,256 @@
#include "StdAfx.h"
#include "GrpMarkInstance.h"
#include "StateManager.h"
#include "ResourceManager.h"
#include "../eterBase/CRC32.h"
CDynamicPool<CGraphicMarkInstance> CGraphicMarkInstance::ms_kPool;
void CGraphicMarkInstance::SetImageFileName(const char* c_szFileName)
{
m_stImageFileName = c_szFileName;
}
const std::string& CGraphicMarkInstance::GetImageFileName()
{
return m_stImageFileName;
}
void CGraphicMarkInstance::CreateSystem(UINT uCapacity)
{
ms_kPool.Create(uCapacity);
}
void CGraphicMarkInstance::DestroySystem()
{
ms_kPool.Destroy();
}
CGraphicMarkInstance* CGraphicMarkInstance::New()
{
return ms_kPool.Alloc();
}
void CGraphicMarkInstance::Delete(CGraphicMarkInstance* pkImgInst)
{
pkImgInst->Destroy();
ms_kPool.Free(pkImgInst);
}
void CGraphicMarkInstance::Render()
{
if (IsEmpty())
return;
assert(!IsEmpty());
OnRender();
}
void CGraphicMarkInstance::OnRender()
{
CGraphicImage * pImage = m_roImage.GetPointer();
CGraphicTexture * pTexture = pImage->GetTexturePointer();
UINT uColCount = pImage->GetWidth() / MARK_WIDTH;
if (uColCount == 0)
return;
UINT uCol = m_uIndex % uColCount;
UINT uRow = m_uIndex / uColCount;
RECT kRect;
kRect.left=uCol*MARK_WIDTH;
kRect.top=uRow*MARK_HEIGHT;
kRect.right=kRect.left+MARK_WIDTH;
kRect.bottom=kRect.top+MARK_HEIGHT;
float texReverseWidth = 1.0f / float(pTexture->GetWidth());
float texReverseHeight = 1.0f / float(pTexture->GetHeight());
float su = kRect.left * texReverseWidth;
float sv = kRect.top * texReverseHeight;
float eu = kRect.right * texReverseWidth;
float ev = kRect.bottom * texReverseHeight;
float fRenderWidth=MARK_WIDTH*m_fScale;
float fRenderHeight=MARK_HEIGHT*m_fScale;
TPDTVertex vertices[4];
vertices[0].position.x = m_v2Position.x-0.5f;
vertices[0].position.y = m_v2Position.y-0.5f;
vertices[0].position.z = 0.0f;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[0].diffuse = m_DiffuseColor;
vertices[1].position.x = m_v2Position.x + fRenderWidth -0.5f;
vertices[1].position.y = m_v2Position.y-0.5f;
vertices[1].position.z = 0.0f;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[1].diffuse = m_DiffuseColor;
vertices[2].position.x = m_v2Position.x-0.5f;
vertices[2].position.y = m_v2Position.y + fRenderHeight -0.5f;
vertices[2].position.z = 0.0f;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[2].diffuse = m_DiffuseColor;
vertices[3].position.x = m_v2Position.x + fRenderWidth -0.5f;
vertices[3].position.y = m_v2Position.y + fRenderHeight -0.5f;
vertices[3].position.z = 0.0f;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
vertices[3].diffuse = m_DiffuseColor;
if (CGraphicBase::SetPDTStream(vertices, 4))
{
CGraphicBase::SetDefaultIndexBuffer(CGraphicBase::DEFAULT_IB_FILL_RECT);
STATEMANAGER.SetTexture(0, pTexture->GetD3DTexture());
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, c_FillRectIndices, D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
}
}
const CGraphicTexture & CGraphicMarkInstance::GetTextureReference() const
{
return m_roImage->GetTextureReference();
}
CGraphicTexture * CGraphicMarkInstance::GetTexturePointer()
{
return m_roImage->GetTexturePointer();
}
CGraphicImage * CGraphicMarkInstance::GetGraphicImagePointer()
{
return m_roImage.GetPointer();
}
void CGraphicMarkInstance::SetScale(float fScale)
{
m_fScale=fScale;
}
void CGraphicMarkInstance::SetIndex(UINT uIndex)
{
m_uIndex=uIndex;
}
int CGraphicMarkInstance::GetWidth()
{
if (IsEmpty())
return 0;
//return m_roImage->GetWidth();
return 16;
}
int CGraphicMarkInstance::GetHeight()
{
if (IsEmpty())
return 0;
//return m_roImage->GetHeight();
return 12;
}
void CGraphicMarkInstance::SetDiffuseColor(float fr, float fg, float fb, float fa)
{
m_DiffuseColor.r = fr;
m_DiffuseColor.g = fg;
m_DiffuseColor.b = fb;
m_DiffuseColor.a = fa;
}
void CGraphicMarkInstance::SetPosition(float fx, float fy)
{
m_v2Position.x = fx;
m_v2Position.y = fy;
}
void CGraphicMarkInstance::Load()
{
if (GetImageFileName().empty())
return;
CResource * pResource = CResourceManager::Instance().GetResourcePointer(GetImageFileName().c_str());
if (!pResource)
{
TraceError("CGraphicMarkinstance::Load - [%s] NOT EXIST", GetImageFileName().c_str());
return;
}
if (pResource->IsType(CGraphicImage::Type()))
SetImagePointer(static_cast<CGraphicImage*>(pResource));
}
void CGraphicMarkInstance::SetImagePointer(CGraphicImage * pImage)
{
m_roImage.SetPointer(pImage);
OnSetImagePointer();
}
bool CGraphicMarkInstance::IsEmpty() const
{
if (!m_roImage.IsNull() && !m_roImage->IsEmpty())
return false;
return true;
}
bool CGraphicMarkInstance::operator == (const CGraphicMarkInstance & rhs) const
{
return (m_roImage.GetPointer() == rhs.m_roImage.GetPointer());
}
DWORD CGraphicMarkInstance::Type()
{
static DWORD s_dwType = GetCRC32("CGraphicMarkInstance", strlen("CGraphicMarkInstance"));
return (s_dwType);
}
BOOL CGraphicMarkInstance::IsType(DWORD dwType)
{
return OnIsType(dwType);
}
BOOL CGraphicMarkInstance::OnIsType(DWORD dwType)
{
if (CGraphicMarkInstance::Type() == dwType)
return TRUE;
return FALSE;
}
void CGraphicMarkInstance::OnSetImagePointer()
{
}
void CGraphicMarkInstance::Initialize()
{
m_DiffuseColor.r = m_DiffuseColor.g = m_DiffuseColor.b = m_DiffuseColor.a = 1.0f;
m_v2Position.x = m_v2Position.y = 0.0f;
m_uIndex = 0;
m_fScale = 1.0f;
}
void CGraphicMarkInstance::Destroy()
{
m_roImage.SetPointer(NULL); // CRef <20><><EFBFBD><EFBFBD> <20><><EFBFBD>۷<EFBFBD><DBB7><EFBFBD> ī<><C4AB>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>.
Initialize();
}
CGraphicMarkInstance::CGraphicMarkInstance()
{
Initialize();
}
CGraphicMarkInstance::~CGraphicMarkInstance()
{
Destroy();
}

View File

@ -0,0 +1,77 @@
#pragma once
#include "GrpImage.h"
#include "Pool.h"
class CGraphicMarkInstance
{
public:
static DWORD Type();
BOOL IsType(DWORD dwType);
void SetImageFileName(const char* c_szFileName);
const std::string& GetImageFileName();
public:
CGraphicMarkInstance();
virtual ~CGraphicMarkInstance();
void Destroy();
void Render();
void SetDepth(float fDepth);
void SetDiffuseColor(float fr, float fg, float fb, float fa);
void SetPosition(float fx, float fy);
void SetIndex(UINT uIndex);
void SetScale(float fScale);
void Load();
bool IsEmpty() const;
int GetWidth();
int GetHeight();
CGraphicTexture * GetTexturePointer();
const CGraphicTexture & GetTextureReference() const;
CGraphicImage * GetGraphicImagePointer();
bool operator == (const CGraphicMarkInstance & rhs) const;
protected:
enum
{
MARK_WIDTH = 16,
MARK_HEIGHT = 12,
};
void Initialize();
virtual void OnRender();
virtual void OnSetImagePointer();
virtual BOOL OnIsType(DWORD dwType);
void SetImagePointer(CGraphicImage * pImage);
protected:
D3DXCOLOR m_DiffuseColor;
D3DXVECTOR2 m_v2Position;
UINT m_uIndex;
FLOAT m_fScale;
FLOAT m_fDepth;
CGraphicImage::TRef m_roImage;
std::string m_stImageFileName;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicMarkInstance* New();
static void Delete(CGraphicMarkInstance* pkImgInst);
static CDynamicPool<CGraphicMarkInstance> ms_kPool;
};

136
src/EterLib/GrpMath.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "StdAfx.h"
#include "GrpMath.h"
float CrossProduct2D(float x1, float y1, float x2, float y2)
{
return x1*y2-y1*x2;
}
bool IsInTriangle2D(float ax, float ay, float bx, float by, float cx, float cy, float tx, float ty)
{
float c1 = CrossProduct2D(bx-ax, by-ay, tx-ax, ty-ay);
float c2 = CrossProduct2D(cx-bx, cy-by, tx-bx, ty-by);
float c3 = CrossProduct2D(ax-cx, ay-cy, tx-cx, ty-cy);
if (c1 * c2 > 0.0f && c1 * c3 > 0.0f)
return true;
if (c1 * c2 * c3 == 0.0f)
{
if (tx < ax)
if (tx < bx)
if (tx < cx)
return false;
if (tx > ax)
if (tx > bx)
if (tx > cx)
return false;
if (ty < ay)
if (ty < by)
if (ty < cy)
return false;
if (ty > ay)
if (ty > by)
if (ty > cy)
return false;
return true;
}
return false;
}
D3DXVECTOR3* D3DXVec3Rotation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXQUATERNION* c_pqtRot)
{
D3DXQUATERNION qtSrc(c_pvtSrc->x, c_pvtSrc->y, c_pvtSrc->z, 0);
D3DXQUATERNION qtRet;
D3DXQuaternionConjugate(&qtRet, c_pqtRot);
D3DXQuaternionMultiply(&qtRet, &qtSrc, &qtRet);
D3DXQuaternionMultiply(&qtRet, c_pqtRot, &qtRet);
pvtOut->x=qtRet.x;
pvtOut->y=qtRet.y;
pvtOut->z=qtRet.z;
return pvtOut;
}
void GetRotationFromMatrix(D3DXVECTOR3 * pRotation, const D3DXMATRIX * c_pMatrix)
{
float sx = c_pMatrix->_32;
float cx = sqrtf(1.0f - sx * sx);
if (cx < 0.00001f)
{
if (sx > 0)
pRotation->x = D3DX_PI / 2;
else
pRotation->x = -D3DX_PI / 2;
pRotation->y = atan2f(c_pMatrix->_31, c_pMatrix->_11);
pRotation->z = 0.0f;
}
else
{
pRotation->x = atan2f(sx, cx);
pRotation->y = atan2f(-c_pMatrix->_31, c_pMatrix->_33);
pRotation->z = atan2f(-c_pMatrix->_12, c_pMatrix->_22);
}
}
void GetPivotAndRotationFromMatrix(D3DXMATRIX * pMatrix, D3DXVECTOR3 * pPivot, D3DXVECTOR3 * pRotation)
{
float sx = pMatrix->_32;
float cx = sqrtf(1.0f - sx * sx);
float x, y, z;
if (cx < 0.00001f)
{
if (sx > 0)
x = D3DX_PI / 2;
else
x = -D3DX_PI / 2;
y = atan2f(pMatrix->_31, pMatrix->_11);
z = 0.0f;
}
else
{
x = atan2f(sx, cx);
y = atan2f(-pMatrix->_31, pMatrix->_33);
z = atan2f(-pMatrix->_12, pMatrix->_22);
}
pRotation->x = x;
pRotation->y = y;
pRotation->z = z;
pPivot->x = pMatrix->_41;
pPivot->y = pMatrix->_42;
pPivot->z = pMatrix->_43;
}
// NOTE : must be optimized!
void ExtractMovement(D3DXMATRIX * pTargetMatrix, D3DXMATRIX * pSourceMatrix)
{
D3DXVECTOR3 v3Pivot;
D3DXVECTOR3 v3Rotation;
GetPivotAndRotationFromMatrix(pSourceMatrix, &v3Pivot, &v3Rotation);
D3DXMATRIX matRotationX;
D3DXMatrixRotationX(&matRotationX, v3Rotation.x);
D3DXMATRIX matRotationY;
D3DXMatrixRotationY(&matRotationY, v3Rotation.y);
D3DXMATRIX matRotationZ;
D3DXMatrixRotationZ(&matRotationZ, v3Rotation.z);
D3DXMATRIX matTranslation;
D3DXMatrixTranslation(&matTranslation, v3Pivot.x, v3Pivot.y, v3Pivot.z);
*pTargetMatrix = matRotationX * matRotationY * matRotationZ * matTranslation;
}

118
src/EterLib/GrpMath.h Normal file
View File

@ -0,0 +1,118 @@
#pragma once
float CrossProduct2D(float x1, float y1, float x2, float y2);
bool IsInTriangle2D(float ax, float ay, float bx, float by, float cx, float cy, float tx, float ty);
D3DXVECTOR3* D3DXVec3Rotation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXQUATERNION* c_pqtRot);
D3DXVECTOR3* D3DXVec3Translation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXVECTOR3* c_pvtTrans);
void GetRotationFromMatrix(D3DXVECTOR3 * pRotation, const D3DXMATRIX * c_pMatrix);
void GetPivotAndRotationFromMatrix(D3DXMATRIX * pMatrix, D3DXVECTOR3 * pPivot, D3DXVECTOR3 * pRotation);
void ExtractMovement(D3DXMATRIX * pTargetMatrix, D3DXMATRIX * pSourceMatrix);
inline D3DXVECTOR3* D3DXVec3Blend(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc1, const D3DXVECTOR3* c_pvtSrc2, float d)
{
pvtOut->x=c_pvtSrc1->x+d*(c_pvtSrc2->x-c_pvtSrc1->x);
pvtOut->y=c_pvtSrc1->y+d*(c_pvtSrc2->y-c_pvtSrc1->y);
pvtOut->z=c_pvtSrc1->z+d*(c_pvtSrc2->z-c_pvtSrc1->z);
return pvtOut;
}
inline D3DXQUATERNION* D3DXQuaternionBlend(D3DXQUATERNION* pqtOut, const D3DXQUATERNION* c_pqtSrc1, const D3DXQUATERNION* c_pqtSrc2, float d)
{
pqtOut->x=c_pqtSrc1->x+d*(c_pqtSrc2->x-c_pqtSrc1->x);
pqtOut->y=c_pqtSrc1->y+d*(c_pqtSrc2->y-c_pqtSrc1->y);
pqtOut->z=c_pqtSrc1->z+d*(c_pqtSrc2->z-c_pqtSrc1->z);
pqtOut->w=c_pqtSrc1->w+d*(c_pqtSrc2->w-c_pqtSrc1->w);
return pqtOut;
}
inline float ClampDegree(float fDegree)
{
if (fDegree >= 360.0f)
fDegree -= 360.0f;
if (fDegree < 0.0f)
fDegree += 360.0f;
return fDegree;
}
inline float GetVector3Distance(const D3DXVECTOR3 & c_rv3Source, const D3DXVECTOR3 & c_rv3Target)
{
return (c_rv3Source.x-c_rv3Target.x)*(c_rv3Source.x-c_rv3Target.x) + (c_rv3Source.y-c_rv3Target.y)*(c_rv3Source.y-c_rv3Target.y);
}
inline D3DXQUATERNION SafeRotationNormalizedArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
if (vFrom == vTo)
return D3DXQUATERNION(0.0f,0.0f,0.0f,1.0f);
if (vFrom == -vTo)
return D3DXQUATERNION(0.0f,0.0f,1.0f,0.0f);
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &vFrom, &vTo);
float d = D3DXVec3Dot(&vFrom, &vTo);
float s = sqrtf((1+d)*2);
return D3DXQUATERNION(c.x/s,c.y/s,c.z/s,s*0.5f);
}
inline D3DXQUATERNION RotationNormalizedArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
D3DXVECTOR3 c;
D3DXVec3Cross(&c, &vFrom, &vTo);
float d = D3DXVec3Dot(&vFrom, &vTo);
float s = sqrtf((1+d)*2);
return D3DXQUATERNION(c.x/s,c.y/s,c.z/s,s*0.5f);
}
inline D3DXQUATERNION RotationArc(const D3DXVECTOR3 & vFrom , const D3DXVECTOR3 & vTo)
{
D3DXVECTOR3 vnFrom, vnTo;
D3DXVec3Normalize(&vnFrom, &vFrom);
D3DXVec3Normalize(&vnTo, &vTo);
return RotationNormalizedArc(vnFrom, vnTo);
}
inline float square_distance_between_linesegment_and_point(const D3DXVECTOR3& p1,const D3DXVECTOR3& p2,const D3DXVECTOR3& x)
{
float l = D3DXVec3LengthSq(&(p2-p1));
float d = D3DXVec3Dot(&(x-p1),&(p2-p1));
if (d<=0.0f)
{
return D3DXVec3LengthSq(&(x-p1));
}
else if (d>=l)
{
return D3DXVec3LengthSq(&(x-p2));
}
else
{
D3DXVECTOR3 c;
return D3DXVec3LengthSq(D3DXVec3Cross(&c,&(x-p1),&(p2-p1)))/l;
}
}
inline D3DXVECTOR3 * Vec3TransformQuaternionSafe(D3DXVECTOR3* pvout, const D3DXVECTOR3* pv, const D3DXQUATERNION* pq)
{
D3DXVECTOR3 v;
D3DXVec3Cross(&v,pv,(D3DXVECTOR3*)pq);
v *= -2*pq->w;
v += (pq->w*pq->w - D3DXVec3LengthSq((D3DXVECTOR3*)pq))*(*pv);
v += 2*D3DXVec3Dot((D3DXVECTOR3*)pq,pv)*(*(D3DXVECTOR3*)pq);
*pvout = v;
return pvout;
}
inline D3DXVECTOR3 * Vec3TransformQuaternion(D3DXVECTOR3* pvout, const D3DXVECTOR3* pv, const D3DXQUATERNION* pq)
{
D3DXVec3Cross(pvout,pv,(D3DXVECTOR3*)pq);
*pvout *= -2*pq->w;
*pvout += (pq->w*pq->w - D3DXVec3LengthSq((D3DXVECTOR3*)pq))*(*pv);
*pvout += 2*D3DXVec3Dot((D3DXVECTOR3*)pq,pv)*(*(D3DXVECTOR3*)pq);
return pvout;
}

View File

@ -0,0 +1,441 @@
#include "StdAfx.h"
#include "GrpObjectInstance.h"
#include "../eterBase/Timer.h"
void CGraphicObjectInstance::OnInitialize()
{
ZeroMemory(m_abyPortalID, sizeof(m_abyPortalID));
}
void CGraphicObjectInstance::Clear()
{
if (m_CullingHandle)
{
CCullingManager::Instance().Unregister(m_CullingHandle);
m_CullingHandle = NULL;
}
ClearHeightInstance();
m_isVisible = TRUE;
m_v3Position.x = m_v3Position.y = m_v3Position.z = 0.0f;
m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 0.0f;
//m_fRotation = 0.0f;
m_fYaw = m_fPitch = m_fRoll = 0.0f;
D3DXMatrixIdentity(&m_worldMatrix);
ZeroMemory(m_abyPortalID, sizeof(m_abyPortalID));
OnClear();
}
bool CGraphicObjectInstance::Render()
{
/*
if (m_CullingHandle)
{
SpherePack * ps = m_CullingHandle->GetParent();
CScreen s;
s.SetColorOperation();
//s.SetDiffuseColor(1,isShow()?1:0,0);
//s.RenderCircle2d(m_CullingHandle->GetCenter().x,m_CullingHandle->GetCenter().y,m_CullingHandle->GetCenter().z,m_CullingHandle->GetRadius());
s.SetDiffuseColor(1,isShow()?1:0,ps->HasSpherePackFlag(SPF_PARTIAL)?1:0);
s.RenderCircle2d(ps->GetCenter().x,ps->GetCenter().y,ps->GetCenter().z,ps->GetRadius());
}
//*/
if (!isShow())
return false;
OnRender();
return true;
}
void CGraphicObjectInstance::BlendRender()
{
if (!isShow())
return;
OnBlendRender();
}
void CGraphicObjectInstance::RenderToShadowMap()
{
if (!isShow())
return;
OnRenderToShadowMap();
}
void CGraphicObjectInstance::RenderShadow()
{
if (!isShow())
return;
OnRenderShadow();
}
void CGraphicObjectInstance::RenderPCBlocker()
{
if (!isShow())
return;
OnRenderPCBlocker();
}
void CGraphicObjectInstance::Update()
{
OnUpdate();
UpdateBoundingSphere();
}
void CGraphicObjectInstance::Deform()
{
if (!isShow())
return;
OnDeform();
}
void CGraphicObjectInstance::Transform()
{
m_worldMatrix = m_mRotation;
m_worldMatrix._41 += m_v3Position.x;
m_worldMatrix._42 += m_v3Position.y;
m_worldMatrix._43 += m_v3Position.z;
}
const D3DXVECTOR3 & CGraphicObjectInstance::GetPosition() const
{
return m_v3Position;
}
const D3DXVECTOR3 & CGraphicObjectInstance::GetScale() const
{
return m_v3Scale;
}
float CGraphicObjectInstance::GetRotation()
{
return GetRoll();
}
float CGraphicObjectInstance::GetYaw()
{
return m_fYaw;
}
float CGraphicObjectInstance::GetPitch()
{
return m_fPitch;
}
float CGraphicObjectInstance::GetRoll()
{
return m_fRoll;
}
D3DXMATRIX & CGraphicObjectInstance::GetTransform()
{
return m_worldMatrix;
}
void CGraphicObjectInstance::SetRotationQuaternion(const D3DXQUATERNION &q)
{
D3DXMatrixRotationQuaternion(&m_mRotation, &q);
}
void CGraphicObjectInstance::SetRotationMatrix(const D3DXMATRIX & m)
{
m_mRotation = m;
}
void CGraphicObjectInstance::SetRotation(float fRotation)
{
m_fYaw = 0;
m_fPitch = 0;
m_fRoll = fRotation;
D3DXMatrixRotationZ(&m_mRotation, D3DXToRadian(fRotation));
}
void CGraphicObjectInstance::SetRotation(float fYaw, float fPitch, float fRoll)
{
//m_fRotation = fRotation;
m_fYaw = fYaw;
m_fPitch = fPitch;
m_fRoll = fRoll;
D3DXMatrixRotationYawPitchRoll(&m_mRotation, D3DXToRadian(fYaw), D3DXToRadian(fPitch), D3DXToRadian(fRoll));
}
void CGraphicObjectInstance::SetPosition(float x, float y, float z)
{
m_v3Position.x = x;
m_v3Position.y = y;
m_v3Position.z = z;
}
void CGraphicObjectInstance::SetPosition(const D3DXVECTOR3 & newposition)
{
m_v3Position = newposition;
}
void CGraphicObjectInstance::SetScale(float x, float y, float z)
{
m_v3Scale.x = x;
m_v3Scale.y = y;
m_v3Scale.z = z;
}
void CGraphicObjectInstance::Show()
{
m_isVisible = true;
}
void CGraphicObjectInstance::Hide()
{
m_isVisible = false;
}
bool CGraphicObjectInstance::isShow()
{
return m_isVisible;
}
//
//////////////////////////////////////////////////////////////////////////
D3DXVECTOR4 & CGraphicObjectInstance::GetWTBBoxVertex(const unsigned char & c_rucNumTBBoxVertex)
{
return m_v4TBBox[c_rucNumTBBoxVertex];
}
bool CGraphicObjectInstance::isIntersect(const CRay & c_rRay, float * pu, float * pv, float * pt)
{
D3DXVECTOR3 v3Start, v3Dir;
float fRayRange;
c_rRay.GetStartPoint(&v3Start);
c_rRay.GetDirection(&v3Dir, &fRayRange);
TPosition posVertices[8];
posVertices[0] = TPosition(m_v3TBBoxMin.x, m_v3TBBoxMin.y, m_v3TBBoxMin.z);
posVertices[1] = TPosition(m_v3TBBoxMax.x, m_v3TBBoxMin.y, m_v3TBBoxMin.z);
posVertices[2] = TPosition(m_v3TBBoxMin.x, m_v3TBBoxMax.y, m_v3TBBoxMin.z);
posVertices[3] = TPosition(m_v3TBBoxMax.x, m_v3TBBoxMax.y, m_v3TBBoxMin.z);
posVertices[4] = TPosition(m_v3TBBoxMin.x, m_v3TBBoxMin.y, m_v3TBBoxMax.z);
posVertices[5] = TPosition(m_v3TBBoxMax.x, m_v3TBBoxMin.y, m_v3TBBoxMax.z);
posVertices[6] = TPosition(m_v3TBBoxMin.x, m_v3TBBoxMax.y, m_v3TBBoxMax.z);
posVertices[7] = TPosition(m_v3TBBoxMax.x, m_v3TBBoxMax.y, m_v3TBBoxMax.z);
TIndex Indices[36] = {0, 1, 2, 1, 3, 2,
2, 0, 6, 0, 4, 6,
0, 1, 4, 1, 5, 4,
1, 3, 5, 3, 7, 5,
3, 2, 7, 2, 6, 7,
4, 5, 6, 5, 7, 6};
int triCount = 12;
WORD* pcurIdx = (WORD*)Indices;
while (triCount--)
{
if (IntersectTriangle(v3Start, v3Dir,
posVertices[pcurIdx[0]],
posVertices[pcurIdx[1]],
posVertices[pcurIdx[2]],
pu, pv, pt))
{
return true;
}
pcurIdx += 3;
}
return false;
}
CGraphicObjectInstance::CGraphicObjectInstance()
{
m_CullingHandle = 0;
Initialize();
}
void CGraphicObjectInstance::Initialize()
{
if (m_CullingHandle)
CCullingManager::Instance().Unregister(m_CullingHandle);
m_CullingHandle = 0;
m_pHeightAttributeInstance = NULL;
m_isVisible = TRUE;
m_BlockCamera = false;
m_v3Position.x = m_v3Position.y = m_v3Position.z = 0.0f;
m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 0.0f;
m_fYaw = m_fPitch = m_fRoll = 0.0f;
D3DXMatrixIdentity(&m_worldMatrix);
D3DXMatrixIdentity(&m_mRotation);
OnInitialize();
}
CGraphicObjectInstance::~CGraphicObjectInstance()
{
Initialize();
}
void CGraphicObjectInstance::UpdateBoundingSphere()
{
if (m_CullingHandle)
{
Vector3d center;
float radius;
GetBoundingSphere(center,radius);
if (radius != m_CullingHandle->GetRadius())
m_CullingHandle->NewPosRadius(center,radius);
else
m_CullingHandle->NewPos(center);
}
}
void CGraphicObjectInstance::RegisterBoundingSphere()
{
if (m_CullingHandle)
CCullingManager::Instance().Unregister(m_CullingHandle);
m_CullingHandle = CCullingManager::Instance().Register(this);
}
void CGraphicObjectInstance::AddCollision(const CStaticCollisionData * pscd, const D3DXMATRIX* pMat)
{
m_StaticCollisionInstanceVector.push_back(CBaseCollisionInstance::BuildCollisionInstance(pscd, pMat));
}
void CGraphicObjectInstance::ClearCollision()
{
CCollisionInstanceVector::iterator it;
for(it = m_StaticCollisionInstanceVector.begin();it!=m_StaticCollisionInstanceVector.end();++it)
{
(*it)->Destroy();
}
m_StaticCollisionInstanceVector.clear();
}
bool CGraphicObjectInstance::CollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
CCollisionInstanceVector::const_iterator it;
for(it = m_StaticCollisionInstanceVector.begin();it!=m_StaticCollisionInstanceVector.end();++it)
{
if ((*it)->CollisionDynamicSphere(s))
return true;
}
return false;
}
bool CGraphicObjectInstance::MovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
CCollisionInstanceVector::const_iterator it;
for(it = m_StaticCollisionInstanceVector.begin();it!=m_StaticCollisionInstanceVector.end();++it)
{
if ((*it)->MovementCollisionDynamicSphere(s))
return true;
}
return false;
}
D3DXVECTOR3 CGraphicObjectInstance::GetCollisionMovementAdjust(const CDynamicSphereInstance & s) const
{
CCollisionInstanceVector::const_iterator it;
for(it = m_StaticCollisionInstanceVector.begin();it!=m_StaticCollisionInstanceVector.end();++it)
{
if ((*it)->MovementCollisionDynamicSphere(s))
return (*it)->GetCollisionMovementAdjust(s);
}
return D3DXVECTOR3(0.0f,0.0f,0.0f);
}
void CGraphicObjectInstance::UpdateCollisionData(const CStaticCollisionDataVector * pscdVector)
{
ClearCollision();
OnUpdateCollisionData(pscdVector);
}
DWORD CGraphicObjectInstance::GetCollisionInstanceCount()
{
return m_StaticCollisionInstanceVector.size();
}
CBaseCollisionInstance * CGraphicObjectInstance::GetCollisionInstanceData(DWORD dwIndex)
{
if (dwIndex>m_StaticCollisionInstanceVector.size())
{
return 0;
}
return m_StaticCollisionInstanceVector[dwIndex];
}
//////////////////////////////////////////////////////////////////////////
// Height
void CGraphicObjectInstance::SetHeightInstance(CAttributeInstance * pAttributeInstance)
{
m_pHeightAttributeInstance = pAttributeInstance;
}
void CGraphicObjectInstance::ClearHeightInstance()
{
m_pHeightAttributeInstance = NULL;
}
void CGraphicObjectInstance::UpdateHeightInstance(CAttributeInstance * pAttributeInstance)
{
ClearHeightInstance();
OnUpdateHeighInstance(pAttributeInstance);
}
bool CGraphicObjectInstance::IsObjectHeight()
{
if (m_pHeightAttributeInstance)
return true;
return false;
}
bool CGraphicObjectInstance::GetObjectHeight(float fX, float fY, float * pfHeight)
{
if (!m_pHeightAttributeInstance)
return false;
return OnGetObjectHeight(fX, fY, pfHeight);
}
void CGraphicObjectInstance::SetPortal(DWORD dwIndex, int iID)
{
if (dwIndex >= PORTAL_ID_MAX_NUM)
{
assert(dwIndex < PORTAL_ID_MAX_NUM);
return;
}
m_abyPortalID[dwIndex] = iID;
}
int CGraphicObjectInstance::GetPortal(DWORD dwIndex)
{
if (dwIndex >= PORTAL_ID_MAX_NUM)
{
assert(dwIndex < PORTAL_ID_MAX_NUM);
return 0;
}
return m_abyPortalID[dwIndex];
}

View File

@ -0,0 +1,161 @@
#pragma once
#include "GrpColorInstance.h"
#include "GrpScreen.h"
#include "CullingManager.h"
#include "CollisionData.h"
#include "AttributeInstance.h"
enum
{
THING_OBJECT = 0xadf21f13,
TREE_OBJECT = 0x8ac9f7a6,
ACTOR_OBJECT = 0x29a76c24,
EFFECT_OBJECT = 0x1cfa97c6,
DUNGEON_OBJECT = 0x18326035,
};
enum
{
PORTAL_ID_MAX_NUM = 8,
};
class CGraphicObjectInstance : public CGraphicCollisionObject
{
public:
CGraphicObjectInstance();
virtual ~CGraphicObjectInstance();
virtual int GetType() const = 0;
public:
const D3DXVECTOR3 & GetPosition() const;
const D3DXVECTOR3 & GetScale() const;
float GetRotation();
float GetYaw();
float GetPitch();
float GetRoll();
void SetPosition(float x, float y, float z);
void SetPosition(const D3DXVECTOR3 & newposition);
void SetScale(float x, float y, float z);
void SetRotation(float fRotation);
void SetRotation(float fYaw, float fPitch, float fRoll);
void SetRotationQuaternion(const D3DXQUATERNION &q);
void SetRotationMatrix(const D3DXMATRIX & m);
void Clear();
void Update();
bool Render();
void BlendRender();
void RenderToShadowMap();
void RenderShadow();
void RenderPCBlocker();
void Deform();
void Transform();
void Show();
void Hide();
bool isShow();
// Camera Block
void BlockCamera(bool bBlock) {m_BlockCamera = bBlock;}
bool BlockCamera() { return m_BlockCamera; }
// Ray Test
bool isIntersect(const CRay & c_rRay, float * pu, float * pv, float * pt);
// Bounding Box
D3DXVECTOR4 & GetWTBBoxVertex(const unsigned char & c_rucNumTBBoxVertex);
D3DXVECTOR3 & GetTBBoxMin() { return m_v3TBBoxMin; }
D3DXVECTOR3 & GetTBBoxMax() { return m_v3TBBoxMax; }
D3DXVECTOR3 & GetBBoxMin() { return m_v3BBoxMin; }
D3DXVECTOR3 & GetBBoxMax() { return m_v3BBoxMax; }
// Matrix
D3DXMATRIX & GetTransform();
const D3DXMATRIX& GetWorldMatrix() { return m_worldMatrix; }
// Portal
void SetPortal(DWORD dwIndex, int iID);
int GetPortal(DWORD dwIndex);
// Initialize
void Initialize();
virtual void OnInitialize();
// Bounding Sphere
public:
void UpdateBoundingSphere();
void RegisterBoundingSphere();
virtual bool GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius) = 0;
virtual void OnRender() = 0;
virtual void OnBlendRender() = 0;
virtual void OnRenderToShadowMap() = 0;
virtual void OnRenderShadow() = 0;
virtual void OnRenderPCBlocker() = 0;
virtual void OnClear(){}
virtual void OnUpdate(){}
virtual void OnDeform(){}
protected:
D3DXVECTOR3 m_v3Position;
D3DXVECTOR3 m_v3Scale;
float m_fYaw;
float m_fPitch;
float m_fRoll;
D3DXMATRIX m_mRotation;
bool m_isVisible;
D3DXMATRIX m_worldMatrix;
// Camera Block
bool m_BlockCamera;
// Bounding Box
D3DXVECTOR4 m_v4TBBox[8];
D3DXVECTOR3 m_v3TBBoxMin, m_v3TBBoxMax;
D3DXVECTOR3 m_v3BBoxMin, m_v3BBoxMax;
// Portal
BYTE m_abyPortalID[PORTAL_ID_MAX_NUM];
// Culling
CCullingManager::CullingHandle m_CullingHandle;
// Static Collision Data
public:
void AddCollision(const CStaticCollisionData * pscd, const D3DXMATRIX * pMat);
void ClearCollision();
bool CollisionDynamicSphere(const CDynamicSphereInstance & s) const;
bool MovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const;
D3DXVECTOR3 GetCollisionMovementAdjust(const CDynamicSphereInstance & s) const;
void UpdateCollisionData(const CStaticCollisionDataVector * pscdVector = 0);
protected:
CCollisionInstanceVector m_StaticCollisionInstanceVector;
virtual void OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector) = 0;
// using in WorldEditor
public:
DWORD GetCollisionInstanceCount();
CBaseCollisionInstance * GetCollisionInstanceData(DWORD dwIndex);
// Height Data
public:
void SetHeightInstance(CAttributeInstance * pAttributeInstance);
void ClearHeightInstance();
void UpdateHeightInstance(CAttributeInstance * pAttributeInstance = 0);
bool IsObjectHeight();
bool GetObjectHeight(float fX, float fY, float * pfHeight);
protected:
CAttributeInstance * m_pHeightAttributeInstance;
virtual void OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance) = 0;
virtual bool OnGetObjectHeight(float fX, float fY, float * pfHeight) = 0;
};

View File

@ -0,0 +1,55 @@
#include "StdAfx.h"
#include "GrpPixelShader.h"
#include "GrpD3DXBuffer.h"
#include "StateManager.h"
CPixelShader::CPixelShader()
{
Initialize();
}
CPixelShader::~CPixelShader()
{
Destroy();
}
void CPixelShader::Initialize()
{
m_handle=0;
}
void CPixelShader::Destroy()
{
if (m_handle)
{
if (ms_lpd3dDevice)
ms_lpd3dDevice->DeletePixelShader(m_handle);
m_handle=0;
}
}
bool CPixelShader::CreateFromDiskFile(const char* c_szFileName)
{
Destroy();
LPD3DXBUFFER lpd3dxShaderBuffer;
LPD3DXBUFFER lpd3dxErrorBuffer;
if (FAILED(
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
))
return false;
CDirect3DXBuffer shaderBuffer(lpd3dxShaderBuffer);
CDirect3DXBuffer errorBuffer(lpd3dxErrorBuffer);
if (FAILED(ms_lpd3dDevice->CreatePixelShader((DWORD*)shaderBuffer.GetPointer(), &m_handle)))
return false;
return true;
}
void CPixelShader::Set()
{
STATEMANAGER.SetPixelShader(m_handle);
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "GrpBase.h"
class CPixelShader : public CGraphicBase
{
public:
CPixelShader();
virtual ~CPixelShader();
void Destroy();
bool CreateFromDiskFile(const char* c_szFileName);
void Set();
protected:
void Initialize();
protected:
DWORD m_handle;
};

View File

@ -0,0 +1,67 @@
#include "StdAfx.h"
#include "GrpRatioInstance.h"
#include "../eterBase/Timer.h"
CGraphicRatioInstance::CGraphicRatioInstance()
{
m_baseTime = 0;
m_blendTime = 0;
}
CGraphicRatioInstance::~CGraphicRatioInstance()
{
}
void CGraphicRatioInstance::Clear()
{
m_curRatio = 0.0f;
m_srcRatio = 0.0f;
m_dstRatio = 0.0f;
m_baseTime = 0;
m_blendTime = 0;
}
void CGraphicRatioInstance::SetRatioReference(const float& c_rRatio)
{
m_curRatio = c_rRatio;
m_srcRatio = m_curRatio;
m_dstRatio = m_curRatio;
}
void CGraphicRatioInstance::BlendRatioReference(DWORD blendTime, const float& c_rDstRatio)
{
m_baseTime = GetTime();
m_blendTime = blendTime;
m_srcRatio = m_curRatio;
m_dstRatio = c_rDstRatio;
}
void CGraphicRatioInstance::Update()
{
DWORD curTime = GetTime();
DWORD elapsedTime = curTime - m_baseTime;
if (elapsedTime < m_blendTime)
{
float diff = m_dstRatio - m_srcRatio;
float rate = elapsedTime / float(m_blendTime);
m_curRatio = diff * rate + m_srcRatio;
}
else
{
m_curRatio = m_dstRatio;
}
}
DWORD CGraphicRatioInstance::GetTime()
{
return CTimer::Instance().GetCurrentMillisecond();
}
const float& CGraphicRatioInstance::GetCurrentRatioReference() const
{
return m_curRatio;
}

View File

@ -0,0 +1,28 @@
#pragma once
class CGraphicRatioInstance
{
public:
CGraphicRatioInstance();
virtual ~CGraphicRatioInstance();
void Clear();
void SetRatioReference(const float& ratio);
void BlendRatioReference(DWORD blendTime, const float& ratio);
void Update();
const float& GetCurrentRatioReference() const;
protected:
DWORD GetTime();
protected:
float m_curRatio;
float m_srcRatio;
float m_dstRatio;
DWORD m_baseTime;
DWORD m_blendTime;
};

858
src/EterLib/GrpScreen.cpp Normal file
View File

@ -0,0 +1,858 @@
#include "StdAfx.h"
#include "GrpScreen.h"
#include "Camera.h"
#include "StateManager.h"
DWORD CScreen::ms_diffuseColor = 0xffffffff;
DWORD CScreen::ms_clearColor = 0L;
DWORD CScreen::ms_clearStencil = 0L;
float CScreen::ms_clearDepth = 1.0f;
Frustum CScreen::ms_frustum;
extern bool GRAPHICS_CAPS_CAN_NOT_DRAW_LINE;
void CScreen::RenderLine3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
if (GRAPHICS_CAPS_CAN_NOT_DRAW_LINE)
return;
assert(ms_lpd3dDevice != NULL);
SPDTVertexRaw vertices[2] =
{
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f }
};
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
if (SetPDTStream(vertices, 2))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 1);
}
}
void CScreen::RenderBox3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
if (GRAPHICS_CAPS_CAN_NOT_DRAW_LINE)
return;
assert(ms_lpd3dDevice != NULL);
SPDTVertexRaw vertices[8] =
{
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f }, // 0
{ ex, sy, sz, ms_diffuseColor, 0.0f, 0.0f }, // 1
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f }, // 0
{ sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f }, // 2
{ ex, sy, sz, ms_diffuseColor, 0.0f, 0.0f }, // 1
{ ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f }, // 3
{ sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f }, // 2
{ ex+1.0f, ey, ez, ms_diffuseColor, 0.0f, 0.0f } // 3, (x<><78> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3)
};
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
if (SetPDTStream(vertices, 8))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitive(D3DPT_LINELIST, 0, 4);
}
}
void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
assert(ms_lpd3dDevice != NULL);
SPDTVertexRaw vertices[4] =
{
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
{ ex, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
};
if (SetPDTStream(vertices, 4))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
void CScreen::RenderBar3d(const D3DXVECTOR3 * c_pv3Positions)
{
assert(ms_lpd3dDevice != NULL);
SPDTVertexRaw vertices[4] =
{
{ c_pv3Positions[0].x, c_pv3Positions[0].y, c_pv3Positions[0].z, ms_diffuseColor, 0.0f, 0.0f },
{ c_pv3Positions[2].x, c_pv3Positions[2].y, c_pv3Positions[2].z, ms_diffuseColor, 0.0f, 0.0f },
{ c_pv3Positions[1].x, c_pv3Positions[1].y, c_pv3Positions[1].z, ms_diffuseColor, 0.0f, 0.0f },
{ c_pv3Positions[3].x, c_pv3Positions[3].y, c_pv3Positions[3].z, ms_diffuseColor, 0.0f, 0.0f },
};
if (SetPDTStream(vertices, 4))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
void CScreen::RenderGradationBar3d(float sx, float sy, float sz, float ex, float ey, float ez, DWORD dwStartColor, DWORD dwEndColor)
{
assert(ms_lpd3dDevice != NULL);
if (sx==ex) return;
if (sy==ey) return;
SPDTVertexRaw vertices[4] =
{
{ sx, sy, sz, dwStartColor, 0.0f, 0.0f },
{ sx, ey, ez, dwEndColor, 0.0f, 0.0f },
{ ex, sy, sz, dwStartColor, 0.0f, 0.0f },
{ ex, ey, ez, dwEndColor, 0.0f, 0.0f },
};
if (SetPDTStream(vertices, 4))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
void CScreen::RenderLineCube(float sx, float sy, float sz, float ex, float ey, float ez)
{
SPDTVertexRaw vertices[8] =
{
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ sx, ey, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, sz, ms_diffuseColor, 0.0f, 0.0f },
{ sx, sy, ez, ms_diffuseColor, 0.0f, 0.0f },
{ ex, sy, ez, ms_diffuseColor, 0.0f, 0.0f },
{ sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
};
if (SetPDTStream(vertices, 8))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
SetDefaultIndexBuffer(DEFAULT_IB_LINE_CUBE);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_LINELIST, 0, 8, 0, 4*3);
}
}
void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float ez)
{
SPDTVertexRaw vertices[8] =
{
{ sx, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, sy, sz, ms_diffuseColor, 0.0f, 0.0f },
{ sx, ey, sz, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, sz, ms_diffuseColor, 0.0f, 0.0f },
{ sx, sy, ez, ms_diffuseColor, 0.0f, 0.0f },
{ ex, sy, ez, ms_diffuseColor, 0.0f, 0.0f },
{ sx, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
{ ex, ey, ez, ms_diffuseColor, 0.0f, 0.0f },
};
if (SetPDTStream(vertices, 8))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 8, 0, 4*3);
}
}
void CScreen::RenderCube(float sx, float sy, float sz, float ex, float ey, float ez, D3DXMATRIX matRotation)
{
D3DXVECTOR3 v3Center = D3DXVECTOR3((sx + ex) * 0.5f, (sy + ey) * 0.5f, (sz + ez) * 0.5f);
D3DXVECTOR3 v3Vertex[8] =
{
D3DXVECTOR3(sx, sy, sz),
D3DXVECTOR3(ex, sy, sz),
D3DXVECTOR3(sx, ey, sz),
D3DXVECTOR3(ex, ey, sz),
D3DXVECTOR3(sx, sy, ez),
D3DXVECTOR3(ex, sy, ez),
D3DXVECTOR3(sx, ey, ez),
D3DXVECTOR3(ex, ey, ez),
};
SPDTVertexRaw vertices[8];
for(int i = 0; i < 8; i++)
{
v3Vertex[i] = v3Vertex[i] - v3Center;
D3DXVec3TransformCoord(&v3Vertex[i], &v3Vertex[i], &matRotation);
v3Vertex[i] = v3Vertex[i] + v3Center;
vertices[i].px = v3Vertex[i].x;
vertices[i].py = v3Vertex[i].y;
vertices[i].pz = v3Vertex[i].z;
vertices[i].diffuse = ms_diffuseColor;
vertices[i].u = 0.0f; vertices[i].v = 0.0f;
}
if (SetPDTStream(vertices, 8))
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
SetDefaultIndexBuffer(DEFAULT_IB_FILL_CUBE);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 8, 0, 4*3);
}
}
void CScreen::RenderLine2d(float sx, float sy, float ex, float ey, float z)
{
RenderLine3d(sx, sy, z, ex, ey, z);
}
void CScreen::RenderBox2d(float sx, float sy, float ex, float ey, float z)
{
RenderBox3d(sx, sy, z, ex, ey, z);
}
void CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float z)
{
RenderBar3d(sx, sy, z, ex, ey, z);
}
void CScreen::RenderGradationBar2d(float sx, float sy, float ex, float ey, DWORD dwStartColor, DWORD dwEndColor, float ez)
{
RenderGradationBar3d(sx, sy, ez, ex, ey, ez, dwStartColor, dwEndColor);
}
void CScreen::RenderCircle2d(float fx, float fy, float fz, float fRadius, int iStep)
{
int count;
float theta, delta;
float x, y, z;
std::vector<D3DXVECTOR3> pts;
pts.clear();
pts.resize(iStep);
theta = 0.0;
delta = 2 * D3DX_PI / float(iStep);
for (count=0; count<iStep; count++)
{
x = fx + fRadius * cosf(theta);
y = fy + fRadius * sinf(theta);
z = fz;
pts[count] = D3DXVECTOR3(x, y, z);
theta += delta;
}
for (count=0; count<iStep - 1; count++)
{
RenderLine3d(pts[count].x, pts[count].y, pts[count].z, pts[count + 1].x, pts[count + 1].y, pts[count + 1].z);
}
RenderLine3d(pts[iStep - 1].x, pts[iStep - 1].y, pts[iStep - 1].z, pts[0].x, pts[0].y, pts[0].z);
}
void CScreen::RenderCircle3d(float fx, float fy, float fz, float fRadius, int iStep)
{
int count;
float theta, delta;
std::vector<D3DXVECTOR3> pts;
pts.clear();
pts.resize(iStep);
theta = 0.0;
delta = 2 * D3DX_PI / float(iStep);
const D3DXMATRIX & c_rmatInvView = CCameraManager::Instance().GetCurrentCamera()->GetBillboardMatrix();
for (count=0; count<iStep; count++)
{
pts[count] = D3DXVECTOR3(fRadius * cosf(theta), fRadius * sinf(theta), 0.0f);
D3DXVec3TransformCoord(&pts[count], &pts[count], &c_rmatInvView);
theta += delta;
}
for (count=0; count<iStep - 1; count++)
{
RenderLine3d(fx+pts[count].x, fy+pts[count].y, fz+pts[count].z,
fx+pts[count + 1].x, fy+pts[count + 1].y, fz+pts[count + 1].z);
}
RenderLine3d(fx+pts[iStep - 1].x, fy+pts[iStep - 1].y, fz+pts[iStep - 1].z,
fx+pts[0].x, fy+pts[0].y, fz+pts[0].z);
}
class CD3DXMeshRenderingOption : public CScreen
{
public:
DWORD m_dwVS;
CD3DXMeshRenderingOption(D3DFILLMODE d3dFillMode, const D3DXMATRIX & c_rmatWorld)
{
ms_lpd3dDevice->GetVertexShader(&m_dwVS);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
STATEMANAGER.SetRenderState(D3DRS_FILLMODE, d3dFillMode);
STATEMANAGER.SaveTransform(D3DTS_WORLD, &c_rmatWorld);
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
}
virtual ~CD3DXMeshRenderingOption()
{
ms_lpd3dDevice->SetVertexShader(m_dwVS);
STATEMANAGER.RestoreTransform(D3DTS_WORLD);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP);
STATEMANAGER.SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
}
};
void CScreen::RenderD3DXMesh(LPD3DXMESH lpMesh, const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, D3DFILLMODE d3dFillMode)
{
D3DXMATRIX matTranslation;
D3DXMATRIX matScaling;
D3DXMatrixTranslation(&matTranslation, fx, fy, fz);
D3DXMatrixScaling(&matScaling, fRadius, fRadius, fRadius);
D3DXMATRIX matWorld;
matWorld = matScaling * matTranslation;
if (c_pmatWorld)
{
matWorld *= *c_pmatWorld;
}
CD3DXMeshRenderingOption SetRenderingOption(d3dFillMode, matWorld);
LPDIRECT3DINDEXBUFFER8 lpIndexBuffer;
LPDIRECT3DVERTEXBUFFER8 lpVertexBuffer;
lpMesh->GetIndexBuffer(&lpIndexBuffer);
lpMesh->GetVertexBuffer(&lpVertexBuffer);
STATEMANAGER.SetVertexShader(lpMesh->GetFVF());
STATEMANAGER.SetIndices(lpIndexBuffer, 0);
STATEMANAGER.SetStreamSource(0, lpVertexBuffer, 24);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, lpMesh->GetNumVertices(), 0, lpMesh->GetNumFaces());
}
void CScreen::RenderSphere(const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, D3DFILLMODE d3dFillMode)
{
RenderD3DXMesh(ms_lpSphereMesh, c_pmatWorld, fx, fy, fz, fRadius, d3dFillMode);
}
void CScreen::RenderCylinder(const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, float /*fLength*/, D3DFILLMODE d3dFillMode)
{
RenderD3DXMesh(ms_lpCylinderMesh, c_pmatWorld, fx, fy, fz, fRadius, d3dFillMode);
}
void CScreen::RenderTextureBox(float sx, float sy, float ex, float ey, float z, float su, float sv, float eu, float ev)
{
assert(ms_lpd3dDevice != NULL);
TPDTVertex vertices[4];
vertices[0].position = TPosition(sx, sy, z);
vertices[0].diffuse = ms_diffuseColor;
vertices[0].texCoord = TTextureCoordinate(su, sv);
vertices[1].position = TPosition(ex, sy, z);
vertices[1].diffuse = ms_diffuseColor;
vertices[1].texCoord = TTextureCoordinate(eu, sv);
vertices[2].position = TPosition(sx, ey, z);
vertices[2].diffuse = ms_diffuseColor;
vertices[2].texCoord = TTextureCoordinate(su, ev);
vertices[3].position = TPosition(ex, ey, z);
vertices[3].diffuse = ms_diffuseColor;
vertices[3].texCoord = TTextureCoordinate(eu, ev);
#ifdef WORLD_EDITOR
STATEMANAGER.SetTransform(D3DTS_WORLD, ms_lpd3dMatStack->GetTop());
#endif
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT);
if (SetPDTStream(vertices, 4))
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ms_fillRectIdxVector[0], D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
}
void CScreen::RenderBillboard(D3DXVECTOR3 * Position, D3DXCOLOR & Color)
{
assert(ms_lpd3dDevice != NULL);
TPDTVertex vertices[4];
vertices[0].position = TPosition(Position[0].x, Position[0].y, Position[0].z);
vertices[0].diffuse = Color;
vertices[0].texCoord = TTextureCoordinate(0, 0);
vertices[1].position = TPosition(Position[1].x, Position[1].y, Position[1].z);
vertices[1].diffuse = Color;
vertices[1].texCoord = TTextureCoordinate(1, 0);
vertices[2].position = TPosition(Position[2].x, Position[2].y, Position[2].z);
vertices[2].diffuse = Color;
vertices[2].texCoord = TTextureCoordinate(0, 1);
vertices[3].position = TPosition(Position[3].x, Position[3].y, Position[3].z);
vertices[3].diffuse = Color;
vertices[3].texCoord = TTextureCoordinate(1, 1);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
// 2004.11.18.myevan.DrawIndexPrimitiveUP -> DynamicVertexBuffer
SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT);
if (SetPDTStream(vertices, 4))
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
//OLD: STATEMANAGER.DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 4, 2, &ms_fillRectIdxVector[0], D3DFMT_INDEX16, vertices, sizeof(TPDTVertex));
}
void CScreen::DrawMinorGrid(float xMin, float yMin, float xMax, float yMax, float xminorStep, float yminorStep, float zPos)
{
float x, y;
for (y = yMin; y <= yMax; y += yminorStep)
RenderLine2d(xMin, y, xMax, y, zPos);
for (x = xMin; x <= xMax; x += xminorStep)
RenderLine2d(x, yMin, x, yMax, zPos);
}
void CScreen::DrawGrid(float xMin, float yMin, float xMax, float yMax, float xmajorStep, float ymajorStep, float xminorStep, float yminorStep, float zPos)
{
xMin*=xminorStep;
xMax*=xminorStep;
yMin*=yminorStep;
yMax*=yminorStep;
xmajorStep*=xminorStep;
ymajorStep*=yminorStep;
float x, y;
SetDiffuseColor(0.5f, 0.5f, 0.5f);
DrawMinorGrid(xMin, yMin, xMax, yMax, xminorStep, yminorStep, zPos);
SetDiffuseColor(0.7f, 0.7f, 0.7f);
for (y = 0.0f; y >= yMin; y -= ymajorStep)
RenderLine2d(xMin, y, xMax, y, zPos);
for (y = 0.0f; y <= yMax; y += ymajorStep)
RenderLine2d(xMin, y, xMax, y, zPos);
for (x = 0.0f; x >= xMin; x -= xmajorStep)
RenderLine2d(x, yMin, x, yMax, zPos);
for (x = 0.0f; x <= yMax; x += xmajorStep)
RenderLine2d(x, yMin, x, yMax, zPos);
SetDiffuseColor(1.0f, 1.0f, 1.0f);
RenderLine2d(xMin, 0.0f, xMax, 0.0f, zPos);
RenderLine2d(0.0f, yMin, 0.0f, yMax, zPos);
}
void CScreen::SetCursorPosition(int x, int y, int hres, int vres)
{
D3DXVECTOR3 v;
v.x = -(((2.0f * x) / hres) - 1) / ms_matProj._11;
v.y = (((2.0f * y) / vres) - 1) / ms_matProj._22;
v.z = 1.0f;
D3DXMATRIX matViewInverse=ms_matInverseView;
//D3DXMatrixInverse(&matViewInverse, NULL, &ms_matView);
ms_vtPickRayDir.x = v.x * matViewInverse._11 +
v.y * matViewInverse._21 +
v.z * matViewInverse._31;
ms_vtPickRayDir.y = v.x * matViewInverse._12 +
v.y * matViewInverse._22 +
v.z * matViewInverse._32;
ms_vtPickRayDir.z = v.x * matViewInverse._13 +
v.y * matViewInverse._23 +
v.z * matViewInverse._33;
ms_vtPickRayOrig.x = matViewInverse._41;
ms_vtPickRayOrig.y = matViewInverse._42;
ms_vtPickRayOrig.z = matViewInverse._43;
// // 2003. 9. 9 <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
// // <20><><EFBFBD><EFBFBD> picking<6E><67> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>... <20>Ѥ<EFBFBD>; <20><><EFBFBD><EFBFBD> <20>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʿ<EFBFBD>...
ms_Ray.SetStartPoint(ms_vtPickRayOrig);
ms_Ray.SetDirection(-ms_vtPickRayDir, 51200.0f);
// // 2003. 9. 9 <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
}
bool CScreen::GetCursorPosition(float* px, float* py, float* pz)
{
if (!GetCursorXYPosition(px, py)) return false;
if (!GetCursorZPosition(pz)) return false;
return true;
}
bool CScreen::GetCursorXYPosition(float* px, float* py)
{
D3DXVECTOR3 v3Eye = CCameraManager::Instance().GetCurrentCamera()->GetEye();
TPosition posVertices[4];
posVertices[0] = TPosition(v3Eye.x-90000000.0f, v3Eye.y+90000000.0f, 0.0f);
posVertices[1] = TPosition(v3Eye.x-90000000.0f, v3Eye.y-90000000.0f, 0.0f);
posVertices[2] = TPosition(v3Eye.x+90000000.0f, v3Eye.y+90000000.0f, 0.0f);
posVertices[3] = TPosition(v3Eye.x+90000000.0f, v3Eye.y-90000000.0f, 0.0f);
static const WORD sc_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, };
float u, v, t;
for (int i = 0; i < 2; ++i)
{
if (IntersectTriangle(ms_vtPickRayOrig, ms_vtPickRayDir,
posVertices[sc_awFillRectIndices[i*3+0]],
posVertices[sc_awFillRectIndices[i*3+1]],
posVertices[sc_awFillRectIndices[i*3+2]],
&u, &v, &t))
{
*px = ms_vtPickRayOrig.x + ms_vtPickRayDir.x * t;
*py = ms_vtPickRayOrig.y + ms_vtPickRayDir.y * t;
return true;
}
}
return false;
}
bool CScreen::GetCursorZPosition(float* pz)
{
D3DXVECTOR3 v3Eye = CCameraManager::Instance().GetCurrentCamera()->GetEye();
TPosition posVertices[4];
posVertices[0] = TPosition(v3Eye.x-90000000.0f, 0.0f, v3Eye.z+90000000.0f);
posVertices[1] = TPosition(v3Eye.x-90000000.0f, 0.0f, v3Eye.z-90000000.0f);
posVertices[2] = TPosition(v3Eye.x+90000000.0f, 0.0f, v3Eye.z+90000000.0f);
posVertices[3] = TPosition(v3Eye.x+90000000.0f, 0.0f, v3Eye.z-90000000.0f);
static const WORD sc_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, };
float u, v, t;
for (int i = 0; i < 2; ++i)
{
if (IntersectTriangle(ms_vtPickRayOrig, ms_vtPickRayDir,
posVertices[sc_awFillRectIndices[i*3+0]],
posVertices[sc_awFillRectIndices[i*3+1]],
posVertices[sc_awFillRectIndices[i*3+2]],
&u, &v, &t))
{
*pz = ms_vtPickRayOrig.z + ms_vtPickRayDir.z * t;
return true;
}
}
return false;
}
void CScreen::GetPickingPosition(float t, float* x, float* y, float* z)
{
*x = ms_vtPickRayOrig.x + ms_vtPickRayDir.x * t;
*y = ms_vtPickRayOrig.y + ms_vtPickRayDir.y * t;
*z = ms_vtPickRayOrig.z + ms_vtPickRayDir.z * t;
}
void CScreen::SetDiffuseColor(DWORD diffuseColor)
{
ms_diffuseColor = diffuseColor;
}
void CScreen::SetDiffuseColor(float r, float g, float b, float a)
{
ms_diffuseColor = GetColor(r, g, b, a);
}
void CScreen::SetClearColor(float r, float g, float b, float a)
{
ms_clearColor = GetColor(r, g, b, a);
}
void CScreen::SetClearDepth(float depth)
{
ms_clearDepth = depth;
}
void CScreen::SetClearStencil(DWORD stencil)
{
ms_clearStencil = stencil;
}
void CScreen::ClearDepthBuffer()
{
assert(ms_lpd3dDevice != NULL);
ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_ZBUFFER, ms_clearColor, ms_clearDepth, ms_clearStencil);
}
void CScreen::Clear()
{
assert(ms_lpd3dDevice != NULL);
ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, ms_clearColor, ms_clearDepth, ms_clearStencil);
}
BOOL CScreen::IsLostDevice()
{
if (!ms_lpd3dDevice)
return TRUE;
IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice;
HRESULT hrTestCooperativeLevel = rkD3DDev.TestCooperativeLevel();
if (FAILED(hrTestCooperativeLevel))
return TRUE;
return FALSE;
}
BOOL CScreen::RestoreDevice()
{
if (!ms_lpd3dDevice)
return FALSE;
UINT iD3DAdapterInfo = ms_iD3DAdapterInfo;
IDirect3D8 & rkD3D = *ms_lpd3d;
IDirect3DDevice8 & rkD3DDev = *ms_lpd3dDevice;
D3DPRESENT_PARAMETERS & rkD3DPP = ms_d3dPresentParameter;
D3D_CDisplayModeAutoDetector & rkD3DDetector = ms_kD3DDetector;
HRESULT hrTestCooperativeLevel = rkD3DDev.TestCooperativeLevel();
if (FAILED(hrTestCooperativeLevel))
{
if (D3DERR_DEVICELOST == hrTestCooperativeLevel)
{
return FALSE;
}
if (D3DERR_DEVICENOTRESET == hrTestCooperativeLevel)
{
D3D_CAdapterInfo* pkD3DAdapterInfo = rkD3DDetector.GetD3DAdapterInfop(ms_iD3DAdapterInfo);
if (!pkD3DAdapterInfo)
return FALSE;
D3DDISPLAYMODE & rkD3DDMDesktop = pkD3DAdapterInfo->GetDesktopD3DDisplayModer();
if (FAILED(rkD3D.GetAdapterDisplayMode(iD3DAdapterInfo, &rkD3DDMDesktop)))
return FALSE;
rkD3DPP.BackBufferFormat = rkD3DDMDesktop.Format;
HRESULT hrReset = rkD3DDev.Reset(&rkD3DPP);
if (FAILED(hrReset))
{
return FALSE;
}
STATEMANAGER.SetDefaultState();
}
}
return TRUE;
}
bool CScreen::Begin()
{
assert(ms_lpd3dDevice != NULL);
ResetFaceCount();
if (!STATEMANAGER.BeginScene())
{
Tracenf("BeginScene FAILED\n");
return false;
}
return true;
}
void CScreen::End()
{
STATEMANAGER.EndScene();
}
extern bool g_isBrowserMode;
extern RECT g_rcBrowser;
void CScreen::Show(HWND hWnd)
{
assert(ms_lpd3dDevice != NULL);
if (g_isBrowserMode)
{
RECT rcTop={0, 0, ms_d3dPresentParameter.BackBufferWidth, g_rcBrowser.top};
RECT rcBottom={0, g_rcBrowser.bottom, ms_d3dPresentParameter.BackBufferWidth, ms_d3dPresentParameter.BackBufferHeight};
RECT rcLeft={0, g_rcBrowser.top, g_rcBrowser.left, g_rcBrowser.bottom};
RECT rcRight={g_rcBrowser.right, g_rcBrowser.top, ms_d3dPresentParameter.BackBufferWidth, g_rcBrowser.bottom};
ms_lpd3dDevice->Present(&rcTop, &rcTop, hWnd, NULL);
ms_lpd3dDevice->Present(&rcBottom, &rcBottom, hWnd, NULL);
ms_lpd3dDevice->Present(&rcLeft, &rcLeft, hWnd, NULL);
ms_lpd3dDevice->Present(&rcRight, &rcRight, hWnd, NULL);
}
else
{
HRESULT hr=ms_lpd3dDevice->Present(NULL, NULL, hWnd, NULL);
if (D3DERR_DEVICELOST == hr)
RestoreDevice();
}
}
void CScreen::Show(RECT * pSrcRect)
{
assert(ms_lpd3dDevice != NULL);
ms_lpd3dDevice->Present(pSrcRect, NULL, NULL, NULL);
}
void CScreen::Show(RECT * pSrcRect, HWND hWnd)
{
assert(ms_lpd3dDevice != NULL);
ms_lpd3dDevice->Present(pSrcRect, NULL, hWnd, NULL);
}
void CScreen::ProjectPosition(float x, float y, float z, float * pfX, float * pfY)
{
D3DXVECTOR3 Input(x, y, z);
D3DXVECTOR3 Output;
D3DXVec3Project(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matWorld);
*pfX = Output.x;
*pfY = Output.y;
}
void CScreen::ProjectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ)
{
D3DXVECTOR3 Input(x, y, z);
D3DXVECTOR3 Output;
D3DXVec3Project(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matWorld);
*pfX = Output.x;
*pfY = Output.y;
*pfZ = Output.z;
}
void CScreen::UnprojectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ)
{
D3DXVECTOR3 Input(x, y, z);
D3DXVECTOR3 Output;
D3DXVec3Unproject(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matWorld);
*pfX = Output.x;
*pfY = Output.y;
*pfZ = Output.z;
}
void CScreen::SetColorOperation()
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
void CScreen::SetDiffuseOperation()
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
void CScreen::SetBlendOperation()
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
void CScreen::SetOneColorOperation(D3DXCOLOR & rColor)
{
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, rColor);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
}
void CScreen::SetAddColorOperation(D3DXCOLOR & rColor)
{
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, rColor);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
}
void CScreen::Identity()
{
STATEMANAGER.SetTransform(D3DTS_WORLD, &ms_matIdentity);
}
CScreen::CScreen()
{
}
CScreen::~CScreen()
{
}
//void BuildViewFrustum() { ms_frustum.BuildViewFrustum(ms_matView*ms_matProj); }
void CScreen::BuildViewFrustum()
{
const D3DXVECTOR3& c_rv3Eye=CCameraManager::Instance().GetCurrentCamera()->GetEye();
const D3DXVECTOR3& c_rv3View=CCameraManager::Instance().GetCurrentCamera()->GetView();
ms_frustum.BuildViewFrustum2(
ms_matView*ms_matProj,
ms_fNearY,
ms_fFarY,
ms_fFieldOfView,
ms_fAspect,
c_rv3Eye, c_rv3View);
}

82
src/EterLib/GrpScreen.h Normal file
View File

@ -0,0 +1,82 @@
#pragma once
#include "GrpCollisionObject.h"
#include "../SphereLib/frustum.h"
class CScreen : public CGraphicCollisionObject
{
public:
CScreen();
virtual ~CScreen();
void ClearDepthBuffer();
void Clear();
bool Begin();
void End();
void Show(HWND hWnd = NULL);
void Show(RECT * pSrcRect);
void Show(RECT * pSrcRect, HWND hWnd);
void RenderLine2d(float sx, float sy, float ex, float ey, float z=0.0f);
void RenderBox2d(float sx, float sy, float ex, float ey, float z=0.0f);
void RenderBar2d(float sx, float sy, float ex, float ey, float z=0.0f);
void RenderGradationBar2d(float sx, float sy, float ex, float ey, DWORD dwStartColor, DWORD dwEndColor, float ez=0.0f);
void RenderCircle2d(float fx, float fy, float fz, float fRadius, int iStep = 50);
void RenderCircle3d(float fx, float fy, float fz, float fRadius, int iStep = 50);
void RenderLine3d(float sx, float sy, float sz, float ex, float ey, float ez);
void RenderBox3d(float sx, float sy, float sz, float ex, float ey, float ez);
void RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez);
void RenderBar3d(const D3DXVECTOR3 * c_pv3Positions);
void RenderGradationBar3d(float sx, float sy, float sz, float ex, float ey, float ez, DWORD dwStartColor, DWORD dwEndColor);
void RenderLineCube(float sx, float sy, float sz, float ex, float ey, float ez);
void RenderCube(float sx, float sy, float sz, float ex, float ey, float ez);
void RenderCube(float sx, float sy, float sz, float ex, float ey, float ez, D3DXMATRIX matRotation);
void RenderTextureBox(float sx, float sy, float ex, float ey, float z=0.0f, float su=0.0f, float sv=0.0f, float eu=1.0f, float ev=1.0f);
void RenderBillboard(D3DXVECTOR3 * Position, D3DXCOLOR & Color);
void DrawMinorGrid(float xMin, float yMin, float xMax, float yMax, float xminorStep, float yminorStep, float zPos=0);
void DrawGrid(float xMin, float yMin, float xMax, float yMax, float xmajorStep, float ymajorStep, float xminorStep, float yminorStep, float zPos=0);
void RenderD3DXMesh(LPD3DXMESH lpMesh, const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, D3DFILLMODE d3dFillMode);
void RenderSphere(const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
void RenderCylinder(const D3DXMATRIX * c_pmatWorld, float fx, float fy, float fz, float fRadius, float fLength, D3DFILLMODE d3dFillMode = D3DFILL_SOLID);
void SetColorOperation();
void SetDiffuseOperation();
void SetBlendOperation();
void SetOneColorOperation(D3DXCOLOR & rColor);
void SetAddColorOperation(D3DXCOLOR & rColor);
void SetDiffuseColor(DWORD diffuseColor);
void SetDiffuseColor(float r, float g, float b, float a=1.0f);
void SetClearColor(float r, float g, float b, float a=1.0f);
void SetClearDepth(float depth);
void SetClearStencil(DWORD stencil);
void SetCursorPosition(int x, int y, int hres, int vres); // creates picking ray
bool GetCursorPosition(float* px, float* py, float* pz);
bool GetCursorXYPosition(float* px, float* py);
bool GetCursorZPosition(float* pz);
void GetPickingPosition(float t, float* x, float* y, float* z);
void ProjectPosition(float x, float y, float z, float * pfX, float * pfY);
void ProjectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ);
void UnprojectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ);
BOOL IsLostDevice();
BOOL RestoreDevice();
void BuildViewFrustum();
static void Identity();
static Frustum & GetFrustum() { return ms_frustum; }
protected:
static DWORD ms_diffuseColor;
static DWORD ms_clearColor;
static DWORD ms_clearStencil;
static float ms_clearDepth;
static Frustum ms_frustum;
};

View File

@ -0,0 +1,191 @@
#include "StdAfx.h"
#include "GrpShadowTexture.h"
#include "StateManager.h"
//////////////////////////////////////////////////////////////////////////
void CGraphicShadowTexture::Destroy()
{
CGraphicTexture::Destroy();
if (m_lpd3dShadowSurface)
{
m_lpd3dShadowSurface->Release();
m_lpd3dShadowSurface = NULL;
}
if (m_lpd3dDepthSurface)
{
m_lpd3dDepthSurface->Release();
m_lpd3dDepthSurface = NULL;
}
if (m_lpd3dShadowTexture)
{
m_lpd3dShadowTexture->Release();
m_lpd3dShadowTexture = NULL;
}
Initialize();
}
bool CGraphicShadowTexture::Create(int width, int height)
{
Destroy();
m_width = width;
m_height = height;
if (FAILED(ms_lpd3dDevice->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_lpd3dShadowTexture)))
return false;
if (FAILED(m_lpd3dShadowTexture->GetSurfaceLevel(0, &m_lpd3dShadowSurface)))
return false;
if (FAILED(ms_lpd3dDevice->CreateDepthStencilSurface(m_width, m_height, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_lpd3dDepthSurface)))
return false;
return true;
}
void CGraphicShadowTexture::Set(int stage) const
{
STATEMANAGER.SetTexture(stage, m_lpd3dShadowTexture);
}
const D3DXMATRIX& CGraphicShadowTexture::GetLightVPMatrixReference() const
{
return m_d3dLightVPMatrix;
}
LPDIRECT3DTEXTURE8 CGraphicShadowTexture::GetD3DTexture() const
{
return m_lpd3dShadowTexture;
}
void CGraphicShadowTexture::Begin()
{
D3DXMatrixMultiply(&m_d3dLightVPMatrix, &ms_matView, &ms_matProj);
ms_lpd3dDevice->GetRenderTarget(&m_lpd3dOldBackBufferSurface);
ms_lpd3dDevice->GetDepthStencilSurface(&m_lpd3dOldDepthBufferSurface);
ms_lpd3dDevice->GetViewport(&m_d3dOldViewport);
ms_lpd3dDevice->SetRenderTarget(m_lpd3dShadowSurface, m_lpd3dDepthSurface);
D3DVIEWPORT8 d3dViewport;
d3dViewport.MinZ = 0.0f;
d3dViewport.MaxZ = 1.0f;
d3dViewport.X = 0;
d3dViewport.Y = 0;
d3dViewport.Width = m_width;
d3dViewport.Height = m_height;
ms_lpd3dDevice->SetViewport(&d3dViewport);
ms_lpd3dDevice->BeginScene();
ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L);
STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
STATEMANAGER.SaveRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, true);
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, true);
STATEMANAGER.SaveRenderState(D3DRS_TEXTUREFACTOR, 0xbb000000);
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
}
void CGraphicShadowTexture::End()
{
assert(m_lpd3dOldBackBufferSurface != NULL);
assert(m_lpd3dOldDepthBufferSurface != NULL);
ms_lpd3dDevice->EndScene();
ms_lpd3dDevice->SetRenderTarget(m_lpd3dOldBackBufferSurface, m_lpd3dOldDepthBufferSurface);
ms_lpd3dDevice->SetViewport(&m_d3dOldViewport);
m_lpd3dOldBackBufferSurface->Release();
m_lpd3dOldDepthBufferSurface->Release();
m_lpd3dOldBackBufferSurface = NULL;
m_lpd3dOldDepthBufferSurface = NULL;
STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE);
STATEMANAGER.RestoreRenderState(D3DRS_ZFUNC);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE);
STATEMANAGER.RestoreRenderState(D3DRS_TEXTUREFACTOR);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG2);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAARG1);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAARG2);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSU);
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ADDRESSV);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG1);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLORARG2);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLOROP);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAARG1);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAARG2);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ALPHAOP);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MINFILTER);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MAGFILTER);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_MIPFILTER);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV);
}
void CGraphicShadowTexture::Initialize()
{
CGraphicTexture::Initialize();
m_lpd3dShadowSurface = NULL;
m_lpd3dDepthSurface = NULL;
m_lpd3dOldBackBufferSurface = NULL;
m_lpd3dOldDepthBufferSurface = NULL;
m_lpd3dShadowTexture = NULL;
}
CGraphicShadowTexture::CGraphicShadowTexture()
{
Initialize();
}
CGraphicShadowTexture::~CGraphicShadowTexture()
{
Destroy();
}

View File

@ -0,0 +1,35 @@
#pragma once
#include "GrpTexture.h"
class CGraphicShadowTexture : public CGraphicTexture
{
public:
CGraphicShadowTexture();
virtual ~CGraphicShadowTexture();
void Destroy();
bool Create(int width, int height);
void Begin();
void End();
void Set(int stage = 0) const;
const D3DXMATRIX& GetLightVPMatrixReference() const;
LPDIRECT3DTEXTURE8 GetD3DTexture() const;
protected:
void Initialize();
protected:
D3DXMATRIX m_d3dLightVPMatrix;
D3DVIEWPORT8 m_d3dOldViewport;
LPDIRECT3DTEXTURE8 m_lpd3dShadowTexture;
LPDIRECT3DSURFACE8 m_lpd3dShadowSurface;
LPDIRECT3DSURFACE8 m_lpd3dDepthSurface;
LPDIRECT3DSURFACE8 m_lpd3dOldBackBufferSurface;
LPDIRECT3DSURFACE8 m_lpd3dOldDepthBufferSurface;
};

156
src/EterLib/GrpSubImage.cpp Normal file
View File

@ -0,0 +1,156 @@
#include "StdAfx.h"
#include "../eterBase/Stl.h"
#include "../eterBase/FileLoader.h"
#include "GrpSubImage.h"
#include "ResourceManager.h"
char CGraphicSubImage::m_SearchPath[256] = "D:/Ymir Work/UI/";
CGraphicSubImage::TType CGraphicSubImage::Type()
{
static TType s_type = StringToType("CGraphicSubImage");
return s_type;
}
CGraphicSubImage::CGraphicSubImage(const char* c_szFileName) : CGraphicImage(c_szFileName)
{
}
CGraphicSubImage::~CGraphicSubImage()
{
m_roImage = NULL;
}
bool CGraphicSubImage::CreateDeviceObjects()
{
m_imageTexture.CreateFromTexturePointer(m_roImage->GetTexturePointer());
return true;
}
void CGraphicSubImage::SetImagePointer(CGraphicImage* pImage)
{
m_roImage = pImage;
CreateDeviceObjects();
}
bool CGraphicSubImage::SetImageFileName(const char* c_szFileName)
{
CResource* pResource = CResourceManager::Instance().GetResourcePointer(c_szFileName);
if (!pResource->IsType(CGraphicImage::Type()))
return false;
SetImagePointer(static_cast<CGraphicImage*>(pResource));
return true;
}
void CGraphicSubImage::SetRectPosition(int left, int top, int right, int bottom)
{
m_rect.left = left;
m_rect.top = top;
m_rect.right = right;
m_rect.bottom = bottom;
}
void CGraphicSubImage::SetRectReference(const RECT& c_rRect)
{
m_rect = c_rRect;
}
void CGraphicSubImage::SetSearchPath(const char * c_szFileName)
{
strncpy(m_SearchPath, c_szFileName, sizeof(m_SearchPath)-1);
}
bool CGraphicSubImage::OnLoad(int iSize, const void* c_pvBuf)
{
if (!c_pvBuf)
return false;
CTokenVector stTokenVector;
std::map<std::string, std::string> stTokenMap;
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(iSize, c_pvBuf);
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
{
if (!textFileLoader.SplitLine(i, &stTokenVector))
continue;
if (stTokenVector.size() != 2)
return false;
stl_lowers(stTokenVector[0]);
stl_lowers(stTokenVector[1]);
stTokenMap[stTokenVector[0]] = stTokenVector[1];
}
const std::string& c_rstTitle = stTokenMap["title"];
const std::string& c_rstVersion = stTokenMap["version"];
const std::string& c_rstImage = stTokenMap["image"];
const std::string& c_rstLeft = stTokenMap["left"];
const std::string& c_rstTop = stTokenMap["top"];
const std::string& c_rstRight = stTokenMap["right"];
const std::string& c_rstBottom = stTokenMap["bottom"];
if (c_rstTitle != "subimage")
return false;
char szFileName[256];
if ("2.0"==c_rstVersion)
{
const std::string& c_rstSubFileName=GetFileNameString();
int nPos=c_rstSubFileName.find_last_of('\\', -1);
if (nPos>=0)
{
nPos++;
memcpy(szFileName, c_rstSubFileName.c_str(), nPos);
szFileName[nPos]='\0';
memcpy(szFileName+nPos, c_rstImage.c_str(), c_rstImage.length());
szFileName[nPos+c_rstImage.length()]='\0';
}
else
{
memcpy(szFileName, c_rstImage.c_str(), c_rstImage.length());
}
}
else
{
_snprintf(szFileName, sizeof(szFileName), "%s%s", m_SearchPath, c_rstImage.c_str());
}
SetImageFileName(szFileName);
SetRectPosition(atoi(c_rstLeft.c_str()),
atoi(c_rstTop.c_str()),
atoi(c_rstRight.c_str()),
atoi(c_rstBottom.c_str()));
return true;
}
void CGraphicSubImage::OnClear()
{
m_roImage = NULL;
memset(&m_rect, 0, sizeof(m_rect));
}
bool CGraphicSubImage::OnIsEmpty() const
{
if (!m_roImage.IsNull())
if (!m_roImage->IsEmpty())
return false;
return true;
}
bool CGraphicSubImage::OnIsType(TType type)
{
if (CGraphicSubImage::Type() == type)
return true;
return CGraphicImage::OnIsType(type);
}

38
src/EterLib/GrpSubImage.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include "GrpImage.h"
class CGraphicSubImage : public CGraphicImage
{
public:
typedef CRef<CGraphicImage> TRef;
public:
static TType Type();
static char m_SearchPath[256];
public:
CGraphicSubImage(const char* c_szFileName);
virtual ~CGraphicSubImage();
bool CreateDeviceObjects();
bool SetImageFileName(const char* c_szFileName);
void SetRectPosition(int left, int top, int right, int bottom);
void SetRectReference(const RECT& c_rRect);
static void SetSearchPath(const char * c_szFileName);
protected:
void SetImagePointer(CGraphicImage* pImage);
bool OnLoad(int iSize, const void* c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
protected:
CGraphicImage::TRef m_roImage;
};

101
src/EterLib/GrpText.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "StdAfx.h"
#include "../eterBase/Utils.h"
#include "GrpText.h"
CGraphicText::CGraphicText(const char* c_szFileName) : CResource(c_szFileName)
{
}
CGraphicText::~CGraphicText()
{
}
bool CGraphicText::CreateDeviceObjects()
{
return m_fontTexture.CreateDeviceObjects();
}
void CGraphicText::DestroyDeviceObjects()
{
m_fontTexture.DestroyDeviceObjects();
}
CGraphicFontTexture* CGraphicText::GetFontTexturePointer()
{
return &m_fontTexture;
}
CGraphicText::TType CGraphicText::Type()
{
static TType s_type = StringToType("CGraphicText");
return s_type;
}
bool CGraphicText::OnLoad(int /*iSize*/, const void* /*c_pvBuf*/)
{
static char strName[32];
int size;
bool bItalic = false;
// format
// <20><><EFBFBD><EFBFBD>.fnt "<22><><EFBFBD><EFBFBD>" <20><>Ʈ <20><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 12 <20><> <20>ε<EFBFBD>
// <20><><EFBFBD><EFBFBD>:18.fnt "<22><><EFBFBD><EFBFBD>" <20><>Ʈ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 18 <20><> <20>ε<EFBFBD>
// <20><><EFBFBD><EFBFBD>:14i.fnt "<22><><EFBFBD><EFBFBD>" <20><>Ʈ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 14 & <20><><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD><EFBFBD><EFBFBD> <20>ε<EFBFBD>
const char * p = strrchr(GetFileName(), ':');
if (p)
{
strncpy(strName, GetFileName(), MIN(31, p - GetFileName()));
++p;
static char num[8];
int i = 0;
while (*p && isdigit(*p))
{
num[i++] = *(p++);
}
num[i] = '\0';
if(*p == 'i')
bItalic = true;
size = atoi(num);
}
else
{
p = strrchr(GetFileName(), '.');
if (!p)
{
assert(!"CGraphicText::OnLoadFromFile there is no extension (ie: .fnt)");
strName[0] = '\0';
}
else
strncpy(strName, GetFileName(), MIN(31, p - GetFileName()));
size = 12;
}
if (!m_fontTexture.Create(strName, size, bItalic))
return false;
return true;
}
void CGraphicText::OnClear()
{
m_fontTexture.Destroy();
}
bool CGraphicText::OnIsEmpty() const
{
return m_fontTexture.IsEmpty();
}
bool CGraphicText::OnIsType(TType type)
{
if (CGraphicText::Type() == type)
return true;
return CResource::OnIsType(type);
}

32
src/EterLib/GrpText.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "Resource.h"
#include "Ref.h"
#include "GrpFontTexture.h"
class CGraphicText : public CResource
{
public:
typedef CRef<CGraphicText> TRef;
public:
static TType Type();
public:
CGraphicText(const char* c_szFileName);
virtual ~CGraphicText();
virtual bool CreateDeviceObjects();
virtual void DestroyDeviceObjects();
CGraphicFontTexture * GetFontTexturePointer();
protected:
bool OnLoad(int iSize, const void * c_pvBuf);
void OnClear();
bool OnIsEmpty() const;
bool OnIsType(TType type);
protected:
CGraphicFontTexture m_fontTexture;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,134 @@
#ifndef __INC_ETERLIB_GRPTEXTINSTANCE_H__
#define __INC_ETERLIB_GRPTEXTINSTANCE_H__
#include "Pool.h"
#include "GrpText.h"
class CGraphicTextInstance
{
public:
typedef CDynamicPool<CGraphicTextInstance> TPool;
public:
enum EHorizontalAlign
{
HORIZONTAL_ALIGN_LEFT = 0x01,
HORIZONTAL_ALIGN_CENTER = 0x02,
HORIZONTAL_ALIGN_RIGHT = 0x03,
};
enum EVerticalAlign
{
VERTICAL_ALIGN_TOP = 0x10,
VERTICAL_ALIGN_CENTER = 0x20,
VERTICAL_ALIGN_BOTTOM = 0x30
};
public:
static void Hyperlink_UpdateMousePos(int x, int y);
static int Hyperlink_GetText(char* buf, int len);
public:
CGraphicTextInstance();
virtual ~CGraphicTextInstance();
void Destroy();
void Update();
void Render(RECT * pClipRect = NULL);
void ShowCursor();
void HideCursor();
void ShowOutLine();
void HideOutLine();
void SetColor(DWORD color);
void SetColor(float r, float g, float b, float a = 1.0f);
void SetOutLineColor(DWORD color);
void SetOutLineColor(float r, float g, float b, float a = 1.0f);
void SetHorizonalAlign(int hAlign);
void SetVerticalAlign(int vAlign);
void SetMax(int iMax);
void SetTextPointer(CGraphicText* pText);
void SetValueString(const std::string& c_stValue);
void SetValue(const char* c_szValue, size_t len = -1);
void SetPosition(float fx, float fy, float fz = 0.0f);
void SetSecret(bool Value);
void SetOutline(bool Value);
void SetFeather(bool Value);
void SetMultiLine(bool Value);
void SetLimitWidth(float fWidth);
void GetTextSize(int* pRetWidth, int* pRetHeight);
const std::string& GetValueStringReference();
WORD GetTextLineCount();
int PixelPositionToCharacterPosition(int iPixelPosition);
int GetHorizontalAlign();
protected:
void __Initialize();
int __DrawCharacter(CGraphicFontTexture * pFontTexture, WORD codePage, wchar_t text, DWORD dwColor);
void __GetTextPos(DWORD index, float* x, float* y);
int __GetTextTag(const wchar_t * src, int maxLen, int & tagLen, std::wstring & extraInfo);
protected:
struct SHyperlink
{
short sx;
short ex;
std::wstring text;
SHyperlink() : sx(0), ex(0) { }
};
protected:
DWORD m_dwTextColor;
DWORD m_dwOutLineColor;
WORD m_textWidth;
WORD m_textHeight;
BYTE m_hAlign;
BYTE m_vAlign;
WORD m_iMax;
float m_fLimitWidth;
bool m_isCursor;
bool m_isSecret;
bool m_isMultiLine;
bool m_isOutline;
float m_fFontFeather;
/////
std::string m_stText;
D3DXVECTOR3 m_v3Position;
private:
bool m_isUpdate;
bool m_isUpdateFontTexture;
CGraphicText::TRef m_roText;
CGraphicFontTexture::TPCharacterInfomationVector m_pCharInfoVector;
std::vector<DWORD> m_dwColorInfoVector;
std::vector<SHyperlink> m_hyperlinkVector;
public:
static void CreateSystem(UINT uCapacity);
static void DestroySystem();
static CGraphicTextInstance* New();
static void Delete(CGraphicTextInstance* pkInst);
static CDynamicPool<CGraphicTextInstance> ms_kPool;
};
extern const char* FindToken(const char* begin, const char* end);
extern int ReadToken(const char* token);
#endif

View File

@ -0,0 +1,59 @@
#include "StdAfx.h"
#include "../eterBase/Stl.h"
#include "GrpTexture.h"
#include "StateManager.h"
void CGraphicTexture::DestroyDeviceObjects()
{
safe_release(m_lpd3dTexture);
}
void CGraphicTexture::Destroy()
{
DestroyDeviceObjects();
Initialize();
}
void CGraphicTexture::Initialize()
{
m_lpd3dTexture = NULL;
m_width = 0;
m_height = 0;
m_bEmpty = true;
}
bool CGraphicTexture::IsEmpty() const
{
return m_bEmpty;
}
void CGraphicTexture::SetTextureStage(int stage) const
{
assert(ms_lpd3dDevice != NULL);
STATEMANAGER.SetTexture(stage, m_lpd3dTexture);
}
LPDIRECT3DTEXTURE8 CGraphicTexture::GetD3DTexture() const
{
return m_lpd3dTexture;
}
int CGraphicTexture::GetWidth() const
{
return m_width;
}
int CGraphicTexture::GetHeight() const
{
return m_height;
}
CGraphicTexture::CGraphicTexture()
{
Initialize();
}
CGraphicTexture::~CGraphicTexture()
{
}

32
src/EterLib/GrpTexture.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "GrpBase.h"
class CGraphicTexture : public CGraphicBase
{
public:
virtual bool IsEmpty() const;
int GetWidth() const;
int GetHeight() const;
void SetTextureStage(int stage) const;
LPDIRECT3DTEXTURE8 GetD3DTexture() const;
void DestroyDeviceObjects();
protected:
CGraphicTexture();
virtual ~CGraphicTexture();
void Destroy();
void Initialize();
protected:
bool m_bEmpty;
int m_width;
int m_height;
LPDIRECT3DTEXTURE8 m_lpd3dTexture;
};

View File

@ -0,0 +1,179 @@
#include "StdAfx.h"
#include "../eterBase/Stl.h"
#include "GrpVertexBuffer.h"
#include "StateManager.h"
int CGraphicVertexBuffer::GetVertexStride() const
{
int retSize = D3DXGetFVFVertexSize(m_dwFVF);
return retSize;
}
DWORD CGraphicVertexBuffer::GetFlexibleVertexFormat() const
{
return m_dwFVF;
}
int CGraphicVertexBuffer::GetVertexCount() const
{
return m_vtxCount;
}
void CGraphicVertexBuffer::SetStream(int stride, int layer) const
{
assert(ms_lpd3dDevice != NULL);
STATEMANAGER.SetStreamSource(layer, m_lpd3dVB, stride);
}
bool CGraphicVertexBuffer::LockRange(unsigned count, void** pretVertices) const
{
if (!m_lpd3dVB)
return false;
DWORD dwLockSize=GetVertexStride() * count;
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag)))
return false;
return true;
}
bool CGraphicVertexBuffer::Lock(void ** pretVertices) const
{
if (!m_lpd3dVB)
return false;
DWORD dwLockSize=GetVertexStride()*GetVertexCount();
if (FAILED(m_lpd3dVB->Lock(0, dwLockSize, (BYTE **) pretVertices, m_dwLockFlag)))
return false;
return true;
}
bool CGraphicVertexBuffer::Unlock() const
{
if (!m_lpd3dVB)
return false;
if ( FAILED(m_lpd3dVB->Unlock()) )
return false;
return true;
}
bool CGraphicVertexBuffer::IsEmpty() const
{
if (m_lpd3dVB)
return true;
else
return false;
}
bool CGraphicVertexBuffer::LockDynamic(void** pretVertices)
{
if (!m_lpd3dVB)
return false;
if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, 0)))
return false;
return true;
}
bool CGraphicVertexBuffer::Lock(void ** pretVertices)
{
if (!m_lpd3dVB)
return false;
if (FAILED(m_lpd3dVB->Lock(0, 0, (BYTE**)pretVertices, m_dwLockFlag)))
return false;
return true;
}
bool CGraphicVertexBuffer::Unlock()
{
if (!m_lpd3dVB)
return false;
if ( FAILED(m_lpd3dVB->Unlock()) )
return false;
return true;
}
bool CGraphicVertexBuffer::Copy(int bufSize, const void* srcVertices)
{
void * dstVertices;
if (!Lock(&dstVertices))
return false;
memcpy(dstVertices, srcVertices, bufSize);
Unlock();
return true;
}
bool CGraphicVertexBuffer::CreateDeviceObjects()
{
assert(ms_lpd3dDevice != NULL);
assert(m_lpd3dVB == NULL);
if (FAILED(
ms_lpd3dDevice->CreateVertexBuffer(
m_dwBufferSize,
m_dwUsage,
m_dwFVF,
m_d3dPool,
&m_lpd3dVB)
))
return false;
return true;
}
void CGraphicVertexBuffer::DestroyDeviceObjects()
{
safe_release(m_lpd3dVB);
}
bool CGraphicVertexBuffer::Create(int vtxCount, DWORD fvf, DWORD usage, D3DPOOL d3dPool)
{
assert(ms_lpd3dDevice != NULL);
assert(vtxCount > 0);
Destroy();
m_vtxCount = vtxCount;
m_dwBufferSize = D3DXGetFVFVertexSize(fvf) * m_vtxCount;
m_d3dPool = d3dPool;
m_dwUsage = usage;
m_dwFVF = fvf;
if (usage == D3DUSAGE_WRITEONLY || usage == D3DUSAGE_DYNAMIC)
m_dwLockFlag = 0;
else
m_dwLockFlag = D3DLOCK_READONLY;
return CreateDeviceObjects();
}
void CGraphicVertexBuffer::Destroy()
{
DestroyDeviceObjects();
}
void CGraphicVertexBuffer::Initialize()
{
m_lpd3dVB = NULL;
m_vtxCount = 0;
m_dwBufferSize = 0;
}
CGraphicVertexBuffer::CGraphicVertexBuffer()
{
Initialize();
}
CGraphicVertexBuffer::~CGraphicVertexBuffer()
{
Destroy();
}

View File

@ -0,0 +1,50 @@
#pragma once
#include "GrpBase.h"
class CGraphicVertexBuffer : public CGraphicBase
{
public:
CGraphicVertexBuffer();
virtual ~CGraphicVertexBuffer();
void Destroy();
virtual bool Create(int vtxCount, DWORD fvf, DWORD usage, D3DPOOL d3dPool);
bool CreateDeviceObjects();
void DestroyDeviceObjects();
bool Copy(int bufSize, const void* srcVertices);
bool LockRange(unsigned count, void** pretVertices) const;
bool Lock(void** pretVertices) const;
bool Unlock() const;
bool LockDynamic(void** pretVertices);
virtual bool Lock(void** pretVertices);
bool Unlock();
void SetStream(int stride, int layer=0) const;
int GetVertexCount() const;
int GetVertexStride() const;
DWORD GetFlexibleVertexFormat() const;
inline LPDIRECT3DVERTEXBUFFER8 GetD3DVertexBuffer() const { return m_lpd3dVB; }
inline DWORD GetBufferSize() const { return m_dwBufferSize; }
bool IsEmpty() const;
protected:
void Initialize();
protected:
LPDIRECT3DVERTEXBUFFER8 m_lpd3dVB;
DWORD m_dwBufferSize;
DWORD m_dwFVF;
DWORD m_dwUsage;
D3DPOOL m_d3dPool;
int m_vtxCount;
DWORD m_dwLockFlag;
};

View File

@ -0,0 +1,29 @@
#include "StdAfx.h"
#include "GrpVertexBufferDynamic.h"
bool CDynamicVertexBuffer::Create(int vtxCount, int fvf)
{
if (m_lpd3dVB)
{
if (m_fvf == fvf)
{
if (m_vtxCount >= vtxCount)
return true;
}
}
m_vtxCount = vtxCount;
m_fvf = fvf;
return CGraphicVertexBuffer::Create(m_vtxCount, m_fvf, D3DUSAGE_DYNAMIC, D3DPOOL_SYSTEMMEM);
}
CDynamicVertexBuffer::CDynamicVertexBuffer()
{
m_vtxCount = 0;
m_fvf = 0;
}
CDynamicVertexBuffer::~CDynamicVertexBuffer()
{
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "GrpVertexBuffer.h"
class CDynamicVertexBuffer : public CGraphicVertexBuffer
{
public:
CDynamicVertexBuffer();
virtual ~CDynamicVertexBuffer();
bool Create(int vtxCount, int fvf);
protected:
int m_vtxCount;
int m_fvf;
};

View File

@ -0,0 +1,16 @@
#include "StdAfx.h"
#include "GrpVertexBufferStatic.h"
bool CStaticVertexBuffer::Create(int vtxCount, DWORD fvf, bool /*isManaged*/)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MANAGED <20><><EFBFBD><EFBFBD>
return CGraphicVertexBuffer::Create(vtxCount, fvf, D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED);
}
CStaticVertexBuffer::CStaticVertexBuffer()
{
}
CStaticVertexBuffer::~CStaticVertexBuffer()
{
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "GrpVertexBuffer.h"
class CStaticVertexBuffer : public CGraphicVertexBuffer
{
public:
CStaticVertexBuffer();
virtual ~CStaticVertexBuffer();
bool Create(int vtxCount, DWORD fvf, bool isManaged=true);
};

View File

@ -0,0 +1,57 @@
#include "StdAfx.h"
#include "GrpVertexShader.h"
#include "GrpD3DXBuffer.h"
#include "StateManager.h"
CVertexShader::CVertexShader()
{
Initialize();
}
CVertexShader::~CVertexShader()
{
Destroy();
}
void CVertexShader::Initialize()
{
m_handle=0;
}
void CVertexShader::Destroy()
{
if (m_handle)
{
if (ms_lpd3dDevice)
ms_lpd3dDevice->DeleteVertexShader(m_handle);
m_handle = 0;
}
}
bool CVertexShader::CreateFromDiskFile(const char* c_szFileName, const DWORD* c_pdwVertexDecl)
{
Destroy();
LPD3DXBUFFER lpd3dxShaderBuffer;
LPD3DXBUFFER lpd3dxErrorBuffer;
if (FAILED(
D3DXAssembleShaderFromFile(c_szFileName, 0, NULL, &lpd3dxShaderBuffer, &lpd3dxErrorBuffer)
)) return false;
CDirect3DXBuffer shaderBuffer(lpd3dxShaderBuffer);
CDirect3DXBuffer errorBuffer(lpd3dxErrorBuffer);
if (FAILED(
ms_lpd3dDevice->CreateVertexShader(c_pdwVertexDecl, (DWORD*)shaderBuffer.GetPointer(), &m_handle, 0 )
))
return false;
return true;
}
void CVertexShader::Set()
{
STATEMANAGER.SetVertexShader(m_handle);
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "GrpBase.h"
class CVertexShader : public CGraphicBase
{
public:
CVertexShader();
virtual ~CVertexShader();
void Destroy();
bool CreateFromDiskFile(const char* c_szFileName, const DWORD* c_pdwVertexDecl);
void Set();
protected:
void Initialize();
protected:
DWORD m_handle;
};

2302
src/EterLib/IME.cpp Normal file

File diff suppressed because it is too large Load Diff

208
src/EterLib/IME.h Normal file
View File

@ -0,0 +1,208 @@
#pragma once
#include <imm.h>
#pragma comment(lib, "imm32.lib")
#include "DIMM.h"
class IIMEEventSink
{
public:
virtual bool OnWM_CHAR( WPARAM wParam, LPARAM lParam ) = 0;
virtual void OnUpdate() = 0;
virtual void OnChangeCodePage() = 0;
virtual void OnOpenCandidateList() = 0;
virtual void OnCloseCandidateList() = 0;
virtual void OnOpenReadingWnd() = 0;
virtual void OnCloseReadingWnd() = 0;
};
class CIME
{
public:
enum
{
IMEREADING_MAXLEN = 128,
IMESTR_MAXLEN = 1024,
IMECANDIDATE_MAXLEN = 32768,
MAX_CANDLIST = 10,
MAX_CANDIDATE_LENGTH = 256
};
public:
CIME();
virtual ~CIME();
bool Initialize(HWND hWnd);
void Uninitialize(void);
static void Clear();
void SetMax(int iMax);
void SetUserMax(int iMax);
void SetText(const char* c_szText, int len);
int GetText(std::string & rstrText, bool addCodePage=false);
const char* GetCodePageText();
int GetCodePage();
// Candidate List
int GetCandidateCount();
int GetCandidatePageCount();
int GetCandidate(DWORD index, std::string & rstrText);
int GetCandidateSelection();
// Reading Information
int GetReading(std::string & rstrText);
int GetReadingError();
void SetInputMode(DWORD dwMode);
DWORD GetInputMode();
bool IsIMEEnabled();
void EnableIME(bool bEnable=true);
void DisableIME();
void EnableCaptureInput();
void DisableCaptureInput();
bool IsCaptureEnabled();
void SetNumberMode();
void SetStringMode();
bool __IsWritable(wchar_t key);
void AddExceptKey(wchar_t key);
void ClearExceptKey();
void PasteTextFromClipBoard();
void EnablePaste(bool bFlag);
void PasteString(const char * str);
static void FinalizeString(bool bSend = false);
void UseDefaultIME();
static int GetCurPos();
static int GetCompLen();
static int GetULBegin();
static int GetULEnd();
static void CloseCandidateList();
static void CloseReadingInformation();
static void ChangeInputLanguage();
static void ChangeInputLanguageWorker();
LRESULT WMInputLanguage(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMStartComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMEndComposition(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMNotify(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
LRESULT WMChar(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
protected:
void IncCurPos();
void DecCurPos();
void SetCurPos(int offset);
void DelCurPos();
protected:
static void CheckInputLocale();
static void CheckToggleState();
static void SetSupportLevel( DWORD dwImeLevel );
void InsertString(wchar_t* szString, int iSize);
void OnChar(wchar_t c);
UINT GetCodePageFromLang( LANGID langid );
void ResultProcess(HIMC hImc);
void CompositionProcessBuilding(HIMC hImc);
void CompositionProcess(HIMC hImc);
void AttributeProcess(HIMC hImc);
void CandidateProcess(HIMC hImc);
void ReadingProcess(HIMC hImc);
bool IsMax(const wchar_t* wInput, int len);
DWORD GetImeId(UINT uIndex = 0);
bool GetReadingWindowOrientation();
static void SetupImeApi();
static INPUTCONTEXT* (WINAPI * _ImmLockIMC)( HIMC );
static BOOL (WINAPI * _ImmUnlockIMC)( HIMC );
static LPVOID (WINAPI * _ImmLockIMCC)( HIMCC );
static BOOL (WINAPI * _ImmUnlockIMCC)( HIMCC );
static UINT (WINAPI * _GetReadingString)( HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT );
static BOOL (WINAPI * _ShowReadingWindow)( HIMC, BOOL );
protected:
HIMC m_hOrgIMC;
int m_max;
int m_userMax;
BOOL m_bOnlyNumberMode;
std::vector<wchar_t> m_exceptKey;
bool m_bEnablePaste;
bool m_bUseDefaultIME;
public:
static bool ms_bInitialized;
static bool ms_bDisableIMECompletely;
static bool ms_bUILessMode;
static bool ms_bImeEnabled;
static bool ms_bCaptureInput;
static bool ms_bChineseIME;
static bool ms_bUseIMMCandidate;
static HWND ms_hWnd;
static HKL ms_hklCurrent;
static char ms_szKeyboardLayout[KL_NAMELENGTH+1];
static OSVERSIONINFOA ms_stOSVI;
static HINSTANCE ms_hImm32Dll;
static HINSTANCE ms_hCurrentImeDll;
static DWORD ms_dwImeState;
static DWORD ms_adwId[2];
// IME Level
static DWORD ms_dwIMELevel;
static DWORD ms_dwIMELevelSaved;
// Candidate List
static bool ms_bCandidateList;
static DWORD ms_dwCandidateCount;
static bool ms_bVerticalCandidate;
static int ms_iCandListIndexBase;
static WCHAR ms_wszCandidate[CIME::MAX_CANDLIST][MAX_CANDIDATE_LENGTH];
static DWORD ms_dwCandidateSelection;
static DWORD ms_dwCandidatePageSize;
// Reading Information
static bool ms_bReadingInformation;
static int ms_iReadingError;
static bool ms_bHorizontalReading;
static std::vector<wchar_t> ms_wstrReading;
// Indicator
static wchar_t* ms_wszCurrentIndicator;
static IIMEEventSink* ms_pEvent;
wchar_t m_wszComposition[IMESTR_MAXLEN];
static wchar_t m_wText[IMESTR_MAXLEN];
static int ms_compLen;
static int ms_curpos;
static int ms_lastpos;
static int ms_ulbegin;
static int ms_ulend;
static UINT ms_uOutputCodePage;
static UINT ms_uInputCodePage;
};

134
src/EterLib/Input.cpp Normal file
View File

@ -0,0 +1,134 @@
#include "StdAfx.h"
#include "Input.h"
LPDIRECTINPUT8 CInputDevice::ms_lpDI = NULL;
LPDIRECTINPUTDEVICE8 CInputKeyboard::ms_lpKeyboard = NULL;
bool CInputKeyboard::ms_bPressedKey[256];
char CInputKeyboard::ms_diks[256];
CInputDevice::CInputDevice()
{
}
CInputDevice::~CInputDevice()
{
SAFE_RELEASE(ms_lpDI);
}
HRESULT CInputDevice::CreateDevice(HWND /*hWnd*/)
{
if (ms_lpDI)
{
ms_lpDI->AddRef();
return S_OK;
}
HRESULT hr;
// Create a DInput object
if (FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**) &ms_lpDI, NULL)))
return hr;
return S_OK;
}
CInputKeyboard::CInputKeyboard()
{
ResetKeyboard();
}
CInputKeyboard::~CInputKeyboard()
{
if (ms_lpKeyboard)
ms_lpKeyboard->Unacquire();
SAFE_RELEASE(ms_lpKeyboard);
}
void CInputKeyboard::ResetKeyboard()
{
memset(ms_diks, 0, sizeof(ms_diks));
memset(ms_bPressedKey, 0, sizeof(ms_bPressedKey));
}
bool CInputKeyboard::InitializeKeyboard(HWND hWnd)
{
NANOBEGIN
if (ms_lpKeyboard)
return true;
if (FAILED(CreateDevice(hWnd)))
return false;
HRESULT hr;
// Obtain an interface to the system keyboard device.
if (FAILED(hr = ms_lpDI->CreateDevice(GUID_SysKeyboard, &ms_lpKeyboard, NULL)))
return false;
if (FAILED(hr = ms_lpKeyboard->SetDataFormat(&c_dfDIKeyboard)))
return false;
// Alt + F4<46><34> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - [levites]
// DWORD dwCoopFlags = DISCL_FOREGROUND | DISCL_EXCLUSIVE;
// DWORD dwCoopFlags = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
DWORD dwCoopFlags = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE;
if (FAILED(hr = ms_lpKeyboard->SetCooperativeLevel(hWnd, dwCoopFlags)))
return false;
ms_lpKeyboard->Acquire();
NANOEND
return true;
}
void CInputKeyboard::UpdateKeyboard()
{
if (!ms_lpKeyboard)
return;
HRESULT hr;
hr = ms_lpKeyboard->GetDeviceState(sizeof(ms_diks), &ms_diks);
if (FAILED(hr))
{
hr = ms_lpKeyboard->Acquire();
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>̼<EFBFBD><CCBC><EFBFBD> <20><>Ȱ<EFBFBD><C8B0>ȭ <20>Ǿ<EFBFBD> <20>־<EFBFBD> <20>Է<EFBFBD><D4B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>.
//if (hr == DIERR_OTHERAPPHASPRIO || hr == DIERR_NOTACQUIRED);
return;
}
for (int i = 0; i < 256; ++i)
{
if (ms_diks[i] & 0x80)
{
if (!IsPressed(i))
KeyDown(i);
}
else if (IsPressed(i))
KeyUp(i);
}
}
void CInputKeyboard::KeyDown(int iIndex)
{
ms_bPressedKey[iIndex] = true;
OnKeyDown(iIndex);
}
void CInputKeyboard::KeyUp(int iIndex)
{
ms_bPressedKey[iIndex] = false;
OnKeyUp(iIndex);
}
bool CInputKeyboard::IsPressed(int iIndex)
{
return ms_bPressedKey[iIndex];
}

41
src/EterLib/Input.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
#endif
class CInputDevice
{
public:
CInputDevice();
virtual ~CInputDevice();
HRESULT CreateDevice(HWND hWnd);
protected:
static LPDIRECTINPUT8 ms_lpDI;
};
class CInputKeyboard : public CInputDevice
{
public:
CInputKeyboard();
virtual ~CInputKeyboard();
bool InitializeKeyboard(HWND hWnd);
void UpdateKeyboard();
void ResetKeyboard();
bool IsPressed(int iIndex);
void KeyDown(int iIndex);
void KeyUp(int iIndex);
protected:
virtual void OnKeyDown(int iIndex) = 0;
virtual void OnKeyUp(int iIndex) = 0;
protected:
static LPDIRECTINPUTDEVICE8 ms_lpKeyboard;
static bool ms_bPressedKey[256];
static char ms_diks[256];
};

368
src/EterLib/JpegFile.cpp Normal file
View File

@ -0,0 +1,368 @@
#include "StdAfx.h"
#include "JpegFile.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <jpeglib.h>
#define OUTBUFFER_SIZE 0x8000
static FILE*fi;
static JOCTET * buffer;
static unsigned char* dest;
static int len;
static int destlen;
static unsigned char* jpeg_data;
static int pos;
static int jpeg_size;
static void file_init_destination(j_compress_ptr cinfo)
{
struct jpeg_destination_mgr*dmgr =
(struct jpeg_destination_mgr*)(cinfo->dest);
buffer = (JOCTET*)malloc(OUTBUFFER_SIZE);
if(!buffer) {
perror("malloc");
printf("Out of memory!\n");
exit(1);
}
dmgr->next_output_byte = buffer;
dmgr->free_in_buffer = OUTBUFFER_SIZE;
}
static boolean file_empty_output_buffer(j_compress_ptr cinfo)
{
struct jpeg_destination_mgr*dmgr =
(struct jpeg_destination_mgr*)(cinfo->dest);
if(fi)
fwrite(buffer, OUTBUFFER_SIZE, 1, fi);
dmgr->next_output_byte = buffer;
dmgr->free_in_buffer = OUTBUFFER_SIZE;
return 1;
}
static void file_term_destination(j_compress_ptr cinfo)
{ struct jpeg_destination_mgr*dmgr =
(struct jpeg_destination_mgr*)(cinfo->dest);
if(fi)
fwrite(buffer, OUTBUFFER_SIZE-dmgr->free_in_buffer, 1, fi);
free(buffer);
buffer = 0;
dmgr->free_in_buffer = 0;
}
static void mem_init_destination(j_compress_ptr cinfo)
{
struct jpeg_destination_mgr*dmgr =
(struct jpeg_destination_mgr*)(cinfo->dest);
dmgr->next_output_byte = dest;
dmgr->free_in_buffer = destlen;
}
static boolean mem_empty_output_buffer(j_compress_ptr cinfo)
{
printf("jpeg mem overflow!\n");
exit(1);
}
static void mem_term_destination(j_compress_ptr cinfo)
{
struct jpeg_destination_mgr*dmgr =
(struct jpeg_destination_mgr*)(cinfo->dest);
len = destlen - dmgr->free_in_buffer;
dmgr->free_in_buffer = 0;
}
int jpeg_save(unsigned char*data, int width, int height, int quality, const char*filename)
{
struct jpeg_destination_mgr mgr;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
int t;
if(filename) {
fi = fopen(filename, "wb");
if(fi == NULL)
return 0;
} else
fi = NULL;
memset(&cinfo, 0, sizeof(cinfo));
memset(&jerr, 0, sizeof(jerr));
memset(&mgr, 0, sizeof(mgr));
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
mgr.init_destination = file_init_destination;
mgr.empty_output_buffer = file_empty_output_buffer;
mgr.term_destination = file_term_destination;
cinfo.dest = &mgr;
// init compression
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo,quality,TRUE);
//jpeg_write_tables(&cinfo);
//jpeg_suppress_tables(&cinfo, TRUE);
jpeg_start_compress(&cinfo, FALSE);
for(t=0;t<height;t++) {
unsigned char*data2 = &data[width*3*t];
jpeg_write_scanlines(&cinfo, &data2, 1);
}
jpeg_finish_compress(&cinfo);
if(fi)
fclose(fi);
jpeg_destroy_compress(&cinfo);
return 1;
}
int jpeg_save_to_file(unsigned char*data, int width, int height, int quality, FILE*_fi)
{
struct jpeg_destination_mgr mgr;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
int t;
fi = _fi;
memset(&cinfo, 0, sizeof(cinfo));
memset(&jerr, 0, sizeof(jerr));
memset(&mgr, 0, sizeof(mgr));
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
mgr.init_destination = file_init_destination;
mgr.empty_output_buffer = file_empty_output_buffer;
mgr.term_destination = file_term_destination;
cinfo.dest = &mgr;
// init compression
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
cinfo.dct_method = JDCT_IFAST;
jpeg_set_quality(&cinfo,quality,TRUE);
//jpeg_write_tables(&cinfo);
//jpeg_suppress_tables(&cinfo, TRUE);
jpeg_start_compress(&cinfo, FALSE);
for(t=0;t<height;t++) {
unsigned char*data2 = &data[width*3*t];
jpeg_write_scanlines(&cinfo, &data2, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
return 1;
}
int jpeg_save_to_mem(unsigned char*data, int width, int height, int quality, unsigned char*_dest, int _destlen)
{
struct jpeg_destination_mgr mgr;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
int t;
memset(&cinfo, 0, sizeof(cinfo));
memset(&jerr, 0, sizeof(jerr));
memset(&mgr, 0, sizeof(mgr));
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
dest = _dest;
len = 0;
destlen = _destlen;
mgr.init_destination = mem_init_destination;
mgr.empty_output_buffer = mem_empty_output_buffer;
mgr.term_destination = mem_term_destination;
cinfo.dest = &mgr;
// init compression
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
cinfo.dct_method = JDCT_IFAST;
jpeg_set_quality(&cinfo,quality,TRUE);
jpeg_start_compress(&cinfo, FALSE);
for(t=0;t<height;t++) {
unsigned char*data2 = &data[width*3*t];
jpeg_write_scanlines(&cinfo, &data2, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
return len;
}
void mem_init_source (j_decompress_ptr cinfo)
{
struct jpeg_source_mgr* mgr = cinfo->src;
mgr->next_input_byte = jpeg_data;
mgr->bytes_in_buffer = jpeg_size;
//printf("init %d\n", size - mgr->bytes_in_buffer);
}
boolean mem_fill_input_buffer (j_decompress_ptr cinfo)
{
struct jpeg_source_mgr* mgr = cinfo->src;
printf("fill %d\n", jpeg_size - mgr->bytes_in_buffer);
return 0;
}
void mem_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
struct jpeg_source_mgr* mgr = cinfo->src;
printf("skip %d +%d\n", jpeg_size - mgr->bytes_in_buffer, num_bytes);
if(num_bytes<=0)
return;
mgr->next_input_byte += num_bytes;
mgr->bytes_in_buffer -= num_bytes;
}
boolean mem_resync_to_restart (j_decompress_ptr cinfo, int desired)
{
struct jpeg_source_mgr* mgr = cinfo->src;
printf("resync %d\n", jpeg_size - mgr->bytes_in_buffer);
mgr->next_input_byte = jpeg_data;
mgr->bytes_in_buffer = jpeg_size;
return 1;
}
void mem_term_source (j_decompress_ptr cinfo)
{
struct jpeg_source_mgr* mgr = cinfo->src;
//printf("term %d\n", size - mgr->bytes_in_buffer);
}
int jpeg_load_from_mem(unsigned char*_data, int _size, unsigned char*dest, int width, int height)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
struct jpeg_source_mgr mgr;
int y;
//int x;
jpeg_data = _data;
jpeg_size = _size;
jpeg_create_decompress(&cinfo);
mgr.next_input_byte = jpeg_data;
mgr.bytes_in_buffer = jpeg_size;
mgr.init_source =mem_init_source ;
mgr.fill_input_buffer =mem_fill_input_buffer ;
mgr.skip_input_data =mem_skip_input_data ;
mgr.resync_to_restart =mem_resync_to_restart ;
mgr.term_source =mem_term_source ;
cinfo.err = jpeg_std_error(&jerr);
cinfo.src = &mgr;
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
for(y=0;y<height;y++) {
unsigned char*j = &dest[width*y*3];
jpeg_read_scanlines(&cinfo,&j,1);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return 1;
}
typedef struct _RGBA {
unsigned char a,r,g,b;
} RGBA;
typedef unsigned char U8;
int jpeg_load(const char*filename, unsigned char**dest, int*_width, int*_height)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
//struct jpeg_source_mgr mgr;
FILE*fi = fopen(filename, "rb");
if(!fi) {
fprintf(stderr, "Couldn't open file %s\n", filename);
return 0;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, fi);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
U8*scanline = (U8 *)malloc(4 * cinfo.output_width);
int width = *_width = cinfo.output_width;
int height = *_height = cinfo.output_height;
*dest = (unsigned char*)malloc(width*height*4);
int y;
for (y=0;y<height;y++) {
int x;
U8 *js = scanline;
RGBA*line = &((RGBA*)(*dest))[y*width];
jpeg_read_scanlines(&cinfo, &js, 1);
if (cinfo.out_color_space == JCS_GRAYSCALE) {
for (x = 0; x < width; x++) {
line[x].a = 255;
line[x].r = line[x].g = line[x].b = js[x];
}
} else if (cinfo.out_color_space == JCS_RGB) {
for (x = width - 1; x >= 0; x--) {
line[x].a = 255;
line[x].r = js[x*3+0];
line[x].g = js[x*3+1];
line[x].b = js[x*3+2];
}
} else if (cinfo.out_color_space == JCS_YCCK) {
fprintf(stderr, "Error: Can't convert YCCK to RGB.\n");
return 0;
} else if (cinfo.out_color_space == JCS_YCbCr) {
for (x = 0; x < width; x++) {
int y = js[x * 3 + 0];
int u = js[x * 3 + 1];
int v = js[x * 3 + 1];
line[x].a = 255;
line[x].r = y + ((360 * (v - 128)) >> 8);
line[x].g = y - ((88 * (u - 128) + 183 * (v - 128)) >> 8);
line[x].b = y + ((455 * (u - 128)) >> 8);
}
} else if (cinfo.out_color_space == JCS_CMYK) {
for (x = 0; x < width; x++) {
int white = 255 - js[x * 4 + 3];
line[x].a = 255;
line[x].r = white - ((js[x * 4] * white) >> 8);
line[x].g = white - ((js[x * 4 + 1] * white) >> 8);
line[x].b = white - ((js[x * 4 + 2] * white) >> 8);
}
}
}
free(scanline);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(fi);
return 1;
}

12
src/EterLib/JpegFile.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _JPEGFILE_H_
#define _JPEGFILE_H_
#include <stdio.h>
int jpeg_save(unsigned char*data, int width, int height, int quality, const char*filename);
int jpeg_save_to_file(unsigned char*data, int width, int height, int quality, FILE*fi);
int jpeg_save_to_mem(unsigned char*data, int width, int height, int quality, unsigned char*dest, int destsize);
int jpeg_load(const char*filename, unsigned char**dest, int*width, int*height);
int jpeg_load_from_mem(unsigned char*_data, int size, unsigned char*dest, int width, int height);
#endif

599
src/EterLib/LensFlare.cpp Normal file
View File

@ -0,0 +1,599 @@
///////////////////////////////////////////////////////////////////////
// CLensFlare Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
///////////////////////////////////////////////////////////////////////
// Preprocessor
#include "StdAfx.h"
#include "LensFlare.h"
#include "Camera.h"
#include "StateManager.h"
#include "ResourceManager.h"
#include <math.h>
using namespace std;
///////////////////////////////////////////////////////////////////////
// Variables
static string g_strFiles[] =
{
"flare2.dds",
"flare1.dds",
"flare2.dds",
"flare1.dds",
"flare6.dds",
"flare4.dds",
"flare2.dds",
"flare3.dds",
""
};
static float g_fPosition[] =
{
-0.55f,
-0.5f,
-0.45f,
0.2f,
0.3f,
0.95f,
0.9f,
1.0f
};
static float g_fWidth[] =
{
20.0f,
32.0f,
20.0f,
32.0f,
100.0f,
32.0f,
20.0f,
250.0f
};
static float g_afColors[ ][4] =
{
{ 1.0f, 1.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 0.8f },
{ 0.3f, 0.5f, 1.0f, 0.9f },
{ 0.3f, 0.5f, 1.0f, 0.6f },
{ 1.0f, 0.6f, 0.9f, 0.4f },
{ 1.0f, 0.0f, 0.0f, 0.5f },
{ 1.0f, 0.6f, 0.3f, 0.4f }
};
///////////////////////////////////////////////////////////////////////
// CLensFlare::CLensFlare
CLensFlare::CLensFlare() :
m_fSunSize(0),
m_fBeforeBright(0.0f),
m_fAfterBright(0.0f),
m_bFlareVisible(false),
m_bDrawFlare(true),
m_bDrawBrightScreen(true),
m_bEnabled(true),
m_bShowMainFlare(true),
m_fMaxBrightness(1.0f)
{
m_pControlPixels = new float[c_nDepthTestDimension * c_nDepthTestDimension];
m_pTestPixels = new float[c_nDepthTestDimension * c_nDepthTestDimension];
m_afColor[0] = m_afColor[1] = m_afColor[2] = 1.0f;
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::~CLensFlare
CLensFlare::~CLensFlare()
{
delete[] m_pControlPixels;
delete[] m_pTestPixels;
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::Interpolate
float CLensFlare::Interpolate(float fStart, float fEnd, float fPercent)
{
return fStart + (fEnd - fStart) * fPercent;
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::DrawBeforeFlare
void CLensFlare::Compute(const D3DXVECTOR3 & c_rv3LightDirection)
{
float afSunPos[3];
D3DXVECTOR3 v3Target = CCameraManager::Instance().GetCurrentCamera()->GetTarget();
afSunPos[0] = v3Target.x - c_rv3LightDirection.x * 99999999.0f;
afSunPos[1] = v3Target.y - c_rv3LightDirection.y * 99999999.0f;
afSunPos[2] = v3Target.z - c_rv3LightDirection.z * 99999999.0f;
float fX, fY;
ProjectPosition(afSunPos[0], afSunPos[1], afSunPos[2], &fX, &fY);
// set flare location
SetFlareLocation(fX, fY);
// determine visibility
float fSunVectorMagnitude = sqrtf(afSunPos[0] * afSunPos[0] +
afSunPos[1] * afSunPos[1] +
afSunPos[2] * afSunPos[2]);
float afSunVector[3];
afSunVector[0] = -afSunPos[0] / fSunVectorMagnitude;
afSunVector[1] = -afSunPos[1] / fSunVectorMagnitude;
afSunVector[2] = -afSunPos[2] / fSunVectorMagnitude;
float afCameraDirection[3];
afCameraDirection[0] = ms_matView._13;
afCameraDirection[1] = ms_matView._23;
afCameraDirection[2] = ms_matView._33;
float fDotProduct =
(afSunVector[0] * afCameraDirection[0]) +
(afSunVector[1] * afCameraDirection[1]) +
(afSunVector[2] * afCameraDirection[2]);
if (acosf(fDotProduct) < 0.5f * D3DX_PI)
SetVisible(true);
else
SetVisible(false);
// set flare brightness
fX /= ms_Viewport.Width;
fY /= ms_Viewport.Height;
float fDistance = sqrtf(((0.5f - fX) * (0.5f - fX)) + ((0.5f - fY) * (0.5f - fY)));
float fBeforeBright = Interpolate(0.0f, c_fHalfMaxBright, 1.0f - (fDistance * c_fDistanceScale));
float fAfterBright = Interpolate(0.0f, 1.0f, 1.0f - (fDistance * c_fDistanceScale));
SetBrightnesses(fBeforeBright, fAfterBright);
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::DrawBeforeFlare
void CLensFlare::DrawBeforeFlare()
{
if (!m_bFlareVisible || !m_bEnabled || !m_bShowMainFlare)
return;
if (m_SunFlareImageInstance.IsEmpty())
return;
D3DXMATRIX matProj;
D3DXMatrixOrthoOffCenterRH(&matProj, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f);
STATEMANAGER.SaveTransform(D3DTS_PROJECTION, &matProj);
STATEMANAGER.SaveTransform(D3DTS_VIEW, &ms_matIdentity);
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matWorld, m_afFlarePos[0], m_afFlarePos[1], 0.0f);
STATEMANAGER.SetTransform(D3DTS_WORLD, &matWorld);
STATEMANAGER.SaveRenderState(D3DRS_LIGHTING, FALSE);
STATEMANAGER.SaveRenderState(D3DRS_ZENABLE, FALSE); // glDisable(GL_DEPTH_TEST);
STATEMANAGER.SaveRenderState(D3DRS_ZWRITEENABLE, FALSE);
STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // glDisable(GL_CULL_FACE);
STATEMANAGER.SaveRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); // glShadeModel(GL_FLAT);
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, FALSE); // glDisable(GL_ALPHA_TEST);
STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // glEnable(GL_BLEND);
STATEMANAGER.SaveRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
/*
if (m_fBeforeBright != 0.0f && m_bDrawFlare && m_bDrawBrightScreen && false) // <20><> false?
{
glColor4f(1.0f, 1.0f, 1.0f, m_fBeforeBright);
glDisable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
}
*/
float fAspectRatio = ms_Viewport.Width / float(ms_Viewport.Height);
float fHeight = m_fSunSize * fAspectRatio;
D3DXCOLOR color(1.0f, 1.0f, 1.0f, 1.0f);
SVertex vertices[4];
vertices[0].x = -m_fSunSize;
vertices[0].y = -fHeight;
vertices[0].z = 0.0f;
vertices[0].color = color;
vertices[0].u = 0.0f;
vertices[0].v = 0.0f;
vertices[1].x = -m_fSunSize;
vertices[1].y = fHeight;
vertices[1].z = 0.0f;
vertices[1].color = color;
vertices[1].u = 0.0f;
vertices[1].v = 1.0f;
vertices[2].x = m_fSunSize;
vertices[2].y = -fHeight;
vertices[2].z = 0.0f;
vertices[2].color = color;
vertices[2].u = 1.0f;
vertices[2].v = 0.0f;
vertices[3].x = m_fSunSize;
vertices[3].y = fHeight;
vertices[3].z = 0.0f;
vertices[3].color = color;
vertices[3].u = 1.0f;
vertices[3].v = 1.0f;
STATEMANAGER.SetTexture(0, m_SunFlareImageInstance.GetTexturePointer()->GetD3DTexture());
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(SVertex));
STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING);
STATEMANAGER.RestoreRenderState(D3DRS_ZENABLE); // glDisable(GL_DEPTH_TEST);
STATEMANAGER.RestoreRenderState(D3DRS_ZWRITEENABLE);
STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); // glDisable(GL_CULL_FACE);
STATEMANAGER.RestoreRenderState(D3DRS_SHADEMODE); // glShadeModel(GL_FLAT);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); // glDisable(GL_ALPHA_TEST);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); // glEnable(GL_BLEND);
STATEMANAGER.RestoreRenderState(D3DRS_SRCBLEND);
STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND);
STATEMANAGER.RestoreTransform(D3DTS_VIEW);
STATEMANAGER.RestoreTransform(D3DTS_PROJECTION);
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::DrawAfterFlare
void CLensFlare::DrawAfterFlare()
{
if (m_bEnabled && m_fAfterBright != 0.0f && m_bDrawBrightScreen)
{
SetDiffuseColor(m_afColor[0], m_afColor[1], m_afColor[2], m_fAfterBright);
RenderBar2d(0.0f, 0.0f, 1024.0f, 1024.0f);
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::SetMainFlare
void CLensFlare::SetMainFlare(string strSunFile, float fSunSize)
{
if (m_bEnabled && m_bShowMainFlare)
{
m_fSunSize = fSunSize;
CResource * pResource = CResourceManager::Instance().GetResourcePointer(strSunFile.c_str());
if (!pResource->IsType(CGraphicImage::Type()))
assert(false);
m_SunFlareImageInstance.SetImagePointer(static_cast<CGraphicImage *> (pResource));
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::DrawFlare
void CLensFlare::DrawFlare()
{
if (m_bEnabled && m_bFlareVisible && m_bDrawFlare && m_fAfterBright != 0.0f)
{
//glPushAttrib(GL_ENABLE_BIT);
STATEMANAGER.SaveRenderState(D3DRS_LIGHTING, FALSE); // glDisable(GL_LIGHTING);
STATEMANAGER.SaveRenderState(D3DRS_ZENABLE, FALSE); // glDisable(GL_DEPTH_TEST);
STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // glDisable(GL_CULL_FACE);
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, FALSE); // glDisable(GL_ALPHA_TEST);
STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // glEnable(GL_BLEND);
D3DXMATRIX matProj;
D3DXMatrixOrthoOffCenterRH(&matProj, 0.0f, ms_Viewport.Width, ms_Viewport.Height, 0.0f, -1.0f, 1.0f);
STATEMANAGER.SaveTransform(D3DTS_PROJECTION, &matProj);
STATEMANAGER.SaveTransform(D3DTS_VIEW, &ms_matIdentity);
STATEMANAGER.SetTransform(D3DTS_WORLD, &ms_matIdentity);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
//glDisable(GL_TEXTURE_2D);
DrawAfterFlare();
//glEnable(GL_TEXTURE_2D);
m_cFlare.Draw(m_fAfterBright,
ms_Viewport.Width,
ms_Viewport.Height,
static_cast<int>(m_afFlareWinPos[0]),
static_cast<int>(m_afFlareWinPos[1]));
STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING); // glDisable(GL_LIGHTING);
STATEMANAGER.RestoreRenderState(D3DRS_ZENABLE); // glDisable(GL_DEPTH_TEST);
STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE); // glDisable(GL_CULL_FACE);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE); // glEnable(GL_BLEND);
STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE); // glDisable(GL_ALPHA_TEST);
STATEMANAGER.RestoreTransform(D3DTS_PROJECTION);
STATEMANAGER.RestoreTransform(D3DTS_VIEW);
//glDisable(GL_TEXTURE_2D);
//glPopAttrib();
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::CharacterizeFlare
void CLensFlare::CharacterizeFlare(bool bEnabled, bool bShowMainFlare, float fMaxBrightness, const D3DXCOLOR & c_rColor)
{
m_bEnabled = bEnabled;
m_bShowMainFlare = bShowMainFlare;
m_fMaxBrightness = fMaxBrightness;
m_afColor[0] = c_rColor.r;
m_afColor[1] = c_rColor.g;
m_afColor[2] = c_rColor.b;
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::Initialize
void CLensFlare::Initialize(std::string strPath)
{
if (m_bEnabled)
m_cFlare.Init(strPath);
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::SetFlareLocation
void CLensFlare::SetFlareLocation(double dX, double dY)
{
if (m_bEnabled)
{
m_afFlareWinPos[0] = float(dX);
m_afFlareWinPos[1] = float(dY);
m_afFlarePos[0] = float(dX) / ms_Viewport.Width;
m_afFlarePos[1] = float(dY) / ms_Viewport.Height;
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::SetBrightnesses
void CLensFlare::SetBrightnesses(float fBeforeBright, float fAfterBright)
{
if (m_bEnabled)
{
m_fBeforeBright = fBeforeBright;
m_fAfterBright = fAfterBright;
ClampBrightness();
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::ReadControlPixels
void CLensFlare::ReadControlPixels()
{
if (m_bEnabled)
ReadDepthPixels(m_pControlPixels);
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::AdjustBrightness
void CLensFlare::AdjustBrightness()
{
if (m_bEnabled)
{
ReadDepthPixels(m_pTestPixels);
int nDifferent = 0;
for (int i = 0; i < c_nDepthTestDimension * c_nDepthTestDimension; ++i)
if (m_pTestPixels[i] != m_pControlPixels[i])
++nDifferent;
float fAdjust = (static_cast<float>(nDifferent) / (c_nDepthTestDimension * c_nDepthTestDimension));
fAdjust = sqrtf(fAdjust) * 0.85f;
m_fAfterBright *= 1.0f - fAdjust;
}
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::ReadDepthPixels
void CLensFlare::ReadDepthPixels(float * /*pPixels*/)
{
/*
LPDIRECT3DSURFACE8 lpSurface;
if (FAILED(ms_lpd3dDevice->GetDepthStencilSurface(&lpSurface)))
assert(false);
D3DLOCKED_RECT rect;
lpSurface->LockRect(&rect, NULL, D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);
lpSurface->UnlockRect();
*/
/*
glReadPixels(GLint(m_afFlareWinPos[0] - c_nDepthTestDimension / 2),
GLint(m_afFlareWinPos[1] - c_nDepthTestDimension / 2),
c_nDepthTestDimension, c_nDepthTestDimension,
GL_DEPTH_COMPONENT, GL_FLOAT, pPixels);
*/
}
///////////////////////////////////////////////////////////////////////
// CLensFlare::ClampBrightness
void CLensFlare::ClampBrightness()
{
// before
if (m_fBeforeBright < 0.0f)
m_fBeforeBright = 0.0f;
else if (m_fBeforeBright > 1.0f)
m_fBeforeBright = 1.0f;
m_fBeforeBright *= m_fMaxBrightness;
if (m_fAfterBright < 0.0f)
m_fAfterBright = 0.0f;
else if (m_fAfterBright > 1.0f)
m_fAfterBright = 1.0f;
m_fAfterBright *= m_fMaxBrightness;
}
///////////////////////////////////////////////////////////////////////
// CFlare implementation
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// CFlare::CFlare
CFlare::CFlare()
{
}
///////////////////////////////////////////////////////////////////////
// CFlare::~CFlare
CFlare::~CFlare()
{
}
///////////////////////////////////////////////////////////////////////
// CFlare::Init
void CFlare::Init(std::string strPath)
{
int i = 0;
while (g_strFiles[i] != "")
{
CResource * pResource = CResourceManager::Instance().GetResourcePointer((strPath + "/" + string(g_strFiles[i])).c_str());
if (!pResource->IsType(CGraphicImage::Type()))
assert(false);
SFlarePiece * pPiece = new SFlarePiece;
pPiece->m_imageInstance.SetImagePointer(static_cast<CGraphicImage *> (pResource));
pPiece->m_fPosition = g_fPosition[i];
pPiece->m_fWidth = g_fWidth[i];
pPiece->m_pColor = g_afColors[i];
m_vFlares.push_back(pPiece);
i++;
}
}
///////////////////////////////////////////////////////////////////////
// CFlare::Draw
void CFlare::Draw(float fBrightScale, int nWidth, int nHeight, int nX, int nY)
{
STATEMANAGER.SaveRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
float fDX = float(nX) - float(nWidth) / 2.0f;
float fDY = float(nY) - float(nHeight) / 2.0f;
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
for (unsigned int i = 0; i < m_vFlares.size(); i++)
{
float fCenterX = float(nX) - (m_vFlares[i]->m_fPosition + 1.0f) * fDX;
float fCenterY = float(nY) - (m_vFlares[i]->m_fPosition + 1.0f) * fDY;
float fW = m_vFlares[i]->m_fWidth;
D3DXCOLOR d3dColor(m_vFlares[i]->m_pColor[0] * fBrightScale,
m_vFlares[i]->m_pColor[1] * fBrightScale,
m_vFlares[i]->m_pColor[2] * fBrightScale,
m_vFlares[i]->m_pColor[3] * fBrightScale);
STATEMANAGER.SetTexture(0, m_vFlares[i]->m_imageInstance.GetTexturePointer()->GetD3DTexture());
TVertex vertices[4];
vertices[0].u = 0.0f;
vertices[0].v = 0.0f;
vertices[0].x = fCenterX - fW;
vertices[0].y = fCenterY - fW;
vertices[0].z = 0.0f;
vertices[0].color = d3dColor;
vertices[1].u = 0.0f;
vertices[1].v = 1.0f;
vertices[1].x = fCenterX - fW;
vertices[1].y = fCenterY + fW;
vertices[1].z = 0.0f;
vertices[1].color = d3dColor;
vertices[2].u = 1.0f;
vertices[2].v = 0.0f;
vertices[2].x = fCenterX + fW;
vertices[2].y = fCenterY - fW;
vertices[2].z = 0.0f;
vertices[2].color = d3dColor;
vertices[3].u = 1.0f;
vertices[3].v = 1.0f;
vertices[3].x = fCenterX + fW;
vertices[3].y = fCenterY + fW;
vertices[3].z = 0.0f;
vertices[3].color = d3dColor;
STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(TVertex));
}
STATEMANAGER.RestoreRenderState(D3DRS_DESTBLEND);
}

125
src/EterLib/LensFlare.h Normal file
View File

@ -0,0 +1,125 @@
///////////////////////////////////////////////////////////////////////
// CLensFlare Class
//
// (c) 2003 IDV, Inc.
//
// *** INTERACTIVE DATA VISUALIZATION (IDV) PROPRIETARY INFORMATION ***
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Interactive Data Visualization and may
// not be copied or disclosed except in accordance with the terms of
// that agreement.
//
// Copyright (c) 2001-2003 IDV, Inc.
// All Rights Reserved.
//
// IDV, Inc.
// 1233 Washington St. Suite 610
// Columbia, SC 29201
// Voice: (803) 799-1699
// Fax: (803) 931-0320
// Web: http://www.idvinc.com
//
///////////////////////////////////////////////////////////////////////
// Preprocessor
#pragma once
#include "GrpImageInstance.h"
#include "GrpScreen.h"
#include <float.h>
#include <string>
#include <vector>
///////////////////////////////////////////////////////////////////////
// Constants
const float c_fHalfMaxBright = 0.45f;
const float c_fDistanceScale = 1.0f;
const int c_nDepthTestDimension = 15;
///////////////////////////////////////////////////////////////////////
// CFlare
class CFlare
{
public:
void Draw(float fBrightScale, int nWidth, int nHeight, int nX, int nY);
void Init(std::string strPath);
CFlare();
virtual ~CFlare();
private:
struct SFlarePiece
{
SFlarePiece() :
m_fPosition(0.0f),
m_fWidth(0.0f),
m_pColor(NULL)
{
}
CGraphicImageInstance m_imageInstance;
float m_fPosition; // -1.0 = light location, 0.0 = center, 1.0 = far end of flare
float m_fWidth; // height = width
float * m_pColor;
};
std::vector<SFlarePiece *> m_vFlares;
};
///////////////////////////////////////////////////////////////////////
// CLensFlare
class CLensFlare : public CScreen
{
public:
CLensFlare();
virtual ~CLensFlare();
void Compute(const D3DXVECTOR3 & c_rv3LightDirection); // D3DTS_VIEW<45><57> <20><><EFBFBD><EFBFBD> ī<>޶<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>, ī<>޶<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ڿ<EFBFBD> <20>ؾ<EFBFBD> <20><>.
void DrawBeforeFlare();
void DrawAfterFlare();
void DrawFlare();
void SetMainFlare(std::string strSunFile, float fSunSize);
void Initialize(std::string strPath);
void SetFlareLocation(double dX, double dY);
void SetVisible(bool bState) { m_bFlareVisible = bState; }
bool IsVisible() { return m_bFlareVisible; }
void SetBrightnesses(float fBeforeBright, float fAfterBright);
void ReadControlPixels();
void AdjustBrightness();
void CharacterizeFlare(bool bEnabled, bool bShowMainFlare, float fMaxBrightness, const D3DXCOLOR & c_rColor);
protected:
float Interpolate(float fStart, float fEnd, float fPercent);
private:
float m_afFlarePos[2], m_afFlareWinPos[2];
float m_fBeforeBright, m_fAfterBright;
bool m_bFlareVisible, m_bDrawFlare, m_bDrawBrightScreen;
float m_fSunSize;
CFlare m_cFlare;
float * m_pControlPixels;
float * m_pTestPixels;
bool m_bEnabled;
bool m_bShowMainFlare;
float m_fMaxBrightness;
float m_afColor[4];
CGraphicImageInstance m_SunFlareImageInstance;
void ReadDepthPixels(float * pPixels);
void ClampBrightness();
};

View File

@ -0,0 +1,56 @@
#include "StdAfx.h"
#include "MsApplication.h"
CMSApplication::CMSApplication()
{
}
CMSApplication::~CMSApplication()
{
// for (TWindowClassSet::iterator i=ms_stWCSet.begin(); i!=ms_stWCSet.end(); ++i)
// UnregisterClass(*i, ms_hInstance);
}
void CMSApplication::Initialize(HINSTANCE hInstance)
{
ms_hInstance = hInstance;
}
void CMSApplication::MessageLoop()
{
while (MessageProcess());
}
bool CMSApplication::IsMessage()
{
MSG msg;
if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
return false;
return true;
}
bool CMSApplication::MessageProcess()
{
MSG msg;
if (!GetMessage(&msg, NULL, 0, 0))
return false;
TranslateMessage(&msg);
DispatchMessage(&msg);
return true;
}
LRESULT CMSApplication::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return CMSWindow::WindowProcedure(hWnd, uiMsg, wParam, lParam);
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "MSWindow.h"
class CMSApplication : public CMSWindow
{
public:
CMSApplication();
virtual ~CMSApplication();
void Initialize(HINSTANCE hInstance);
void MessageLoop();
bool IsMessage();
bool MessageProcess();
protected:
void ClearWindowClass();
LRESULT WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
};

249
src/EterLib/MSWindow.cpp Normal file
View File

@ -0,0 +1,249 @@
#include "StdAfx.h"
#include "MsWindow.h"
#include <windowsx.h>
CMSWindow::TWindowClassSet CMSWindow::ms_stWCSet;
HINSTANCE CMSWindow::ms_hInstance = NULL;
LRESULT CALLBACK MSWindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
CMSWindow * pWnd = (CMSWindow *) GetWindowLong(hWnd, GWL_USERDATA);
if (pWnd)
return pWnd->WindowProcedure(hWnd, uiMsg, wParam, lParam);
return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}
LRESULT CMSWindow::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
{
case WM_SIZE:
OnSize(wParam, lParam);
break;
case WM_ACTIVATEAPP:
m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
break;
}
return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}
void CMSWindow::OnSize(WPARAM wParam, LPARAM /*lParam*/)
{
if (wParam == SIZE_MINIMIZED)
{
InvalidateRect(m_hWnd, NULL, true);
m_isActive = false;
m_isVisible = false;
}
else
{
m_isActive = true;
m_isVisible = true;
}
}
void CMSWindow::Destroy()
{
if (!m_hWnd)
return;
if (IsWindow(m_hWnd))
DestroyWindow(m_hWnd);
m_hWnd = NULL;
m_isVisible = false;
}
bool CMSWindow::Create(const char* c_szName, int brush, DWORD cs, DWORD ws, HICON hIcon, int iCursorResource)
{
//assert(ms_hInstance != NULL);
Destroy();
const char* c_szClassName = RegisterWindowClass(cs, brush, MSWindowProcedure, hIcon, iCursorResource);
m_hWnd = CreateWindow(
c_szClassName,
c_szName,
ws,
0, 0, 0, 0,
NULL,
NULL,
ms_hInstance,
NULL);
if (!m_hWnd)
return false;
SetWindowLong(m_hWnd, GWL_USERDATA, (DWORD) this);
//DestroyWindow(ImmGetDefaultIMEWnd(m_hWnd));
return true;
}
void CMSWindow::SetVisibleMode(bool isVisible)
{
m_isVisible = isVisible;
if (m_isVisible)
{
ShowWindow(m_hWnd, SW_SHOW);
}
else
{
ShowWindow(m_hWnd, SW_HIDE);
}
}
void CMSWindow::Show()
{
m_isVisible = true;
ShowWindow(m_hWnd, SW_SHOW);
}
void CMSWindow::Hide()
{
m_isVisible = false;
ShowWindow(m_hWnd, SW_HIDE);
}
bool CMSWindow::IsVisible()
{
return m_isVisible;
}
bool CMSWindow::IsActive()
{
return m_isActive;
}
HINSTANCE CMSWindow::GetInstance()
{
return ms_hInstance;
}
HWND CMSWindow::GetWindowHandle()
{
return m_hWnd;
}
int CMSWindow::GetScreenWidth()
{
return GetSystemMetrics(SM_CXSCREEN);
}
int CMSWindow::GetScreenHeight()
{
return GetSystemMetrics(SM_CYSCREEN);
}
void CMSWindow::GetWindowRect(RECT* prc)
{
::GetWindowRect(m_hWnd, prc);
}
void CMSWindow::GetClientRect(RECT* prc)
{
::GetClientRect(m_hWnd, prc);
}
void CMSWindow::GetMousePosition(POINT* ppt)
{
GetCursorPos(ppt);
ScreenToClient(m_hWnd, ppt);
}
void CMSWindow::SetPosition(int x, int y)
{
SetWindowPos(m_hWnd, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
}
void CMSWindow::SetCenterPosition()
{
RECT rc;
GetClientRect(&rc);
int windowWidth = rc.right - rc.left;
int windowHeight = rc.bottom - rc.top;
SetPosition((GetScreenWidth()-windowWidth)/2, (GetScreenHeight()-windowHeight)/2);
}
void CMSWindow::AdjustSize(int width, int height)
{
SetRect(&m_rect, 0, 0, width, height);
AdjustWindowRectEx(&m_rect,
GetWindowStyle(m_hWnd),
GetMenu(m_hWnd ) != NULL,
GetWindowExStyle(m_hWnd ) );
MoveWindow
(
m_hWnd,
0,
0,
m_rect.right - m_rect.left,
m_rect.bottom - m_rect.top,
FALSE
);
}
void CMSWindow::SetText(const char* c_szText)
{
SetWindowText(m_hWnd, c_szText);
}
void CMSWindow::SetSize(int width, int height)
{
SetWindowPos(m_hWnd, NULL, 0, 0, width, height, SWP_NOZORDER|SWP_NOMOVE);
}
const char * CMSWindow::RegisterWindowClass(DWORD style, int brush, WNDPROC pfnWndProc, HICON hIcon, int iCursorResource)
{
char szClassName[1024];
sprintf(szClassName, "eter - s%x:b%x:p:%x", style, brush, (DWORD) pfnWndProc);
TWindowClassSet::iterator f = ms_stWCSet.find((char*) szClassName);
if (f != ms_stWCSet.end())
return *f;
const char* c_szStaticClassName = stl_static_string(szClassName).c_str();
ms_stWCSet.insert((char * const) c_szStaticClassName);
WNDCLASS wc;
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = pfnWndProc;
wc.hCursor = LoadCursor(ms_hInstance, MAKEINTRESOURCE(iCursorResource));
wc.hIcon = hIcon ? hIcon : LoadIcon(ms_hInstance, IDI_APPLICATION);
wc.hbrBackground = (HBRUSH) GetStockObject(brush);
wc.hInstance = ms_hInstance;
wc.lpszClassName = c_szStaticClassName;
wc.lpszMenuName = "";
if (!RegisterClass(&wc))
return "";
return c_szStaticClassName;
}
CMSWindow::CMSWindow()
{
m_hWnd=NULL;
m_isVisible=false;
}
CMSWindow::~CMSWindow()
{
}

59
src/EterLib/MSWindow.h Normal file
View File

@ -0,0 +1,59 @@
#pragma once
#include "../eterBase/Stl.h"
class CMSWindow
{
public:
CMSWindow();
virtual ~CMSWindow();
void Destroy();
bool Create(const char* c_szName, int brush=BLACK_BRUSH, DWORD cs=0, DWORD ws=WS_OVERLAPPEDWINDOW, HICON hIcon=NULL, int iCursorResource=32512);
void Show();
void Hide();
void SetVisibleMode(bool isVisible);
void SetPosition(int x, int y);
void SetCenterPosition();
void SetText(const char* c_szText);
void AdjustSize(int width, int height);
void SetSize(int width, int height);
bool IsVisible();
bool IsActive();
void GetMousePosition(POINT* ppt);
void GetClientRect(RECT* prc);
void GetWindowRect(RECT* prc);
int GetScreenWidth();
int GetScreenHeight();
HWND GetWindowHandle();
HINSTANCE GetInstance();
virtual LRESULT WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
virtual void OnSize(WPARAM wParam, LPARAM lParam);
protected:
const char* RegisterWindowClass(DWORD style, int brush, WNDPROC pfnWndProc, HICON hIcon=NULL, int iCursorResource=32512);
protected:
typedef std::set<char*, stl_sz_less> TWindowClassSet;
protected:
HWND m_hWnd;
RECT m_rect;
bool m_isActive;
bool m_isVisible;
protected:
static TWindowClassSet ms_stWCSet;
static HINSTANCE ms_hInstance;
};

Some files were not shown because too many files have changed in this diff Show More