port 2V2-d.2: Granny runtime on libgr2, main character model animates

Implement the Granny SDK 2.11 API the client uses on top of libgr2
(platform/EterGrnLib/GrannyRuntime.cpp, shim granny.h declared from the
SDK header): file sections, type-definition vertex conversion, material
textures by Usage, mesh/bone bindings, deformer, control clock/loop/ease
and weighted SRT sampling. Port EterGrnLib (LODController, Material, Mesh,
Model, ModelInstance*, Motion, Thing, ThingInstance, Util) plus EterLib
GrpObjectInstance/GrpCollisionObject/CollisionData verbatim and drop their
platform skeletons and pending stand-ins; register the gr2 resource
factory; vertex/index buffers are CPU-side until the 2V2-e render adapter.

app.UpdateGame/RenderGame now run 40250's bodies, reaching the
CPythonApplication members through their singletons (the platform has no
app object); CPythonGraphic joins GameSingletons in member order, and
GetMousePosition reads the host cursor.

port.login_flow asserts the main instance's PART_MAIN model has meshes,
its diffuse image loaded and the WAIT motion moves the bones between
frames; offline and live pass, port_gate macos PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-23 19:43:27 +09:00
co-authored by Claude Opus 5.5
parent 5266b00c6e
commit 668f48d6ec
74 changed files with 11404 additions and 2356 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ if(NOT TARGET mtpython)
list(FILTER MT_PLATFORM_SOURCES EXCLUDE REGEX "/ScriptLib/")
endif()
add_library(port_platform STATIC ${MT_PLATFORM_SOURCES})
target_link_libraries(port_platform PUBLIC port_logic PRIVATE mt3p::freetype)
target_link_libraries(port_platform PUBLIC port_logic PRIVATE mt3p::freetype xrender::libgr2)
foreach(src IN LISTS MT_PLATFORM_SOURCES)
mt_port_apply_defines(${src})
endforeach()
File diff suppressed because it is too large Load Diff
@@ -1,209 +0,0 @@
// Platform skeleton for EterGrnLib/LODController.h (40250 EterGrnLib/LODController.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/LODController.h"
#include "../PlatformStub.h"
auto CGrannyLODController::SetMinLODMode(bool) -> void
{
MT_PLATFORM_STUB();
}
CGrannyLODController::CGrannyLODController()
{
MT_PLATFORM_STUB();
}
CGrannyLODController::~CGrannyLODController()
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::Clear() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::CreateDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::AddModel(CGraphicThing *, int, CGrannyLODController *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::AttachModelInstance(CGrannyLODController *, const char *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::DetachModelInstance(CGrannyLODController *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetLODLimits(float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetLODLevel(BYTE) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetMaterialImagePointer(const char *, CGraphicImage *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetMaterialData(const char *, const SMaterialData &) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetSpecularInfo(const char *, BOOL, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::RenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::RenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::BlendRenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::BlendRenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::Update(float, float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::UpdateLODLevel(float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::UpdateTime(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::UpdateSkeleton(const D3DXMATRIX *, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::Deform(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::DeformNoSkin(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::DeformAll(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::RenderToShadowMap() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::RenderShadow() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::ReloadTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::GetBoundBox(D3DXVECTOR3 *, D3DXVECTOR3 *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::Intersect(const D3DXMATRIX *, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyLODController::SetLocalTime(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::ResetLocalTime() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetMotionPointer(const CGrannyMotion *, float, int, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::ChangeMotionPointer(const CGrannyMotion *, int, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::SetMotionAtEnd() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::isModelInstance() -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGrannyLODController::GetModelInstance() -> CGrannyModelInstance *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyModelInstance *>();
}
auto CGrannyLODController::SetCurrentModelInstance(CGrannyModelInstance *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::RefreshAttachedModelInstance() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyLODController::__ReserveSharedDeformableVertexBuffer(DWORD) -> void
{
MT_PLATFORM_STUB();
}
@@ -1,211 +0,0 @@
// Platform skeleton for EterGrnLib/Material.h (40250 EterGrnLib/Material.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Material.h"
#include "../PlatformStub.h"
auto CGrannyMaterial::CreateSphereMap(UINT, const char *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::DestroySphereMap() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::TranslateSpecularMatrix(float, float, float) -> void
{
MT_PLATFORM_STUB();
}
decltype(CGrannyMaterial::ms_matSpecular) CGrannyMaterial::ms_matSpecular{};
decltype(CGrannyMaterial::ms_v3SpecularTrans) CGrannyMaterial::ms_v3SpecularTrans{};
CGrannyMaterial::CGrannyMaterial()
{
MT_PLATFORM_STUB();
}
CGrannyMaterial::~CGrannyMaterial()
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::Copy(CGrannyMaterial &) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::IsEqual(granny_material *) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMaterial::IsIn(const char *, int *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMaterial::SetSpecularInfo(BOOL, float, BYTE) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::ApplyRenderState() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::RestoreRenderState() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::CreateFromGrannyMaterialPointer(granny_material *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMaterial::SetImagePointer(int, CGraphicImage *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::GetType() const -> CGrannyMaterial::EType
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyMaterial::EType>();
}
auto CGrannyMaterial::GetImagePointer(int) const -> CGraphicImage *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicImage *>();
}
auto CGrannyMaterial::GetDiffuseTexture() const -> const CGraphicTexture *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGraphicTexture *>();
}
auto CGrannyMaterial::GetOpacityTexture() const -> const CGraphicTexture *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGraphicTexture *>();
}
auto CGrannyMaterial::GetD3DTexture(int) const -> LPDIRECT3DTEXTURE8
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<LPDIRECT3DTEXTURE8>();
}
auto CGrannyMaterial::__GetImagePointer(const char *) -> CGraphicImage *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicImage *>();
}
auto CGrannyMaterial::__IsSpecularEnable() const -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGrannyMaterial::__GetSpecularPower() const -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGrannyMaterial::__ApplyDiffuseRenderState() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::__RestoreDiffuseRenderState() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::__ApplySpecularRenderState() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterial::__RestoreSpecularRenderState() -> void
{
MT_PLATFORM_STUB();
}
decltype(CGrannyMaterial::ms_akSphereMapInstance) CGrannyMaterial::ms_akSphereMapInstance{};
CGrannyMaterialPalette::CGrannyMaterialPalette()
{
MT_PLATFORM_STUB();
}
CGrannyMaterialPalette::~CGrannyMaterialPalette()
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::Clear() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::Copy(const CGrannyMaterialPalette &) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::RegisterMaterial(granny_material *) -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGrannyMaterialPalette::SetMaterialImagePointer(const char *, CGraphicImage *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::SetMaterialData(const char *, const SMaterialData &) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::SetSpecularInfo(const char *, BOOL, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMaterialPalette::GetMaterialRef(DWORD) -> CGrannyMaterial &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyMaterial &>();
}
auto CGrannyMaterialPalette::GetMaterialCount() const -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
-133
View File
@@ -1,133 +0,0 @@
// Platform skeleton for EterGrnLib/Mesh.h (40250 EterGrnLib/Mesh.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Mesh.h"
#include "../PlatformStub.h"
CGrannyMesh::CGrannyMesh()
{
MT_PLATFORM_STUB();
}
CGrannyMesh::~CGrannyMesh()
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::IsEmpty() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMesh::CreateFromGrannyMeshPointer(granny_skeleton *, granny_mesh *, int, int, CGrannyMaterialPalette &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMesh::LoadIndices(void *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::LoadPNTVertices(void *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::NEW_LoadVertices(void *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::SetPNT2Mesh() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::DeformPNTVertices(void *, D3DXMATRIX *, granny_mesh_binding *) const -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::CanDeformPNTVertices() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMesh::IsTwoSide() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMesh::GetVertexCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyMesh::GetDefaultBoneIndices() const -> int *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int *>();
}
auto CGrannyMesh::GetVertexBasePosition() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyMesh::GetIndexBasePosition() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyMesh::GetGrannyMeshPointer() const -> const granny_mesh *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const granny_mesh *>();
}
auto CGrannyMesh::GetTriGroupNodeList(CGrannyMaterial::EType) const -> const CGrannyMesh::TTriGroupNode *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGrannyMesh::TTriGroupNode *>();
}
auto CGrannyMesh::RebuildTriGroupNodeList() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::ReloadMaterials() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMesh::LoadMaterials(CGrannyMaterialPalette &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMesh::LoadTriGroupNodeList(CGrannyMaterialPalette &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
-178
View File
@@ -1,178 +0,0 @@
// Platform skeleton for EterGrnLib/Model.h (40250 EterGrnLib/Model.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Model.h"
#include "../PlatformStub.h"
CGrannyModel::CGrannyModel()
{
MT_PLATFORM_STUB();
}
CGrannyModel::~CGrannyModel()
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::IsEmpty() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::CreateFromGrannyModelPointer(granny_model *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::GetRigidVertexCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModel::GetDeformVertexCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModel::GetVertexCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModel::CanDeformPNTVertices() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::DeformPNTVertices(void *, D3DXMATRIX *, const std::vector<granny_mesh_binding *> &) const -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::GetIdxCount() -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModel::GetMeshCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModel::GetMeshPointer(int) -> CGrannyMesh *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyMesh *>();
}
auto CGrannyModel::GetGrannyModelPointer() -> granny_model *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<granny_model *>();
}
auto CGrannyModel::GetMeshPointer(int) const -> const CGrannyMesh *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGrannyMesh *>();
}
auto CGrannyModel::GetPNTD3DVertexBuffer() const -> LPDIRECT3DVERTEXBUFFER8
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<LPDIRECT3DVERTEXBUFFER8>();
}
auto CGrannyModel::GetD3DIndexBuffer() const -> LPDIRECT3DINDEXBUFFER8
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<LPDIRECT3DINDEXBUFFER8>();
}
auto CGrannyModel::GetMeshNodeList(CGrannyMesh::EType, CGrannyMaterial::EType) const -> const CGrannyModel::TMeshNode *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGrannyModel::TMeshNode *>();
}
auto CGrannyModel::LockVertices(void **, void **) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::UnlockVertices() const -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::GetMaterialPalette() const -> const CGrannyMaterialPalette &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const CGrannyMaterialPalette &>();
}
auto CGrannyModel::LoadMeshs() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::LoadPNTVertices() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::LoadIndices() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModel::Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::CheckMeshIndex(int) const -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGrannyModel::AppendMeshNode(CGrannyMesh::EType, CGrannyMaterial::EType, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModel::__LoadVertices() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
@@ -1,379 +0,0 @@
// Platform skeleton for EterGrnLib/ModelInstance.h (40250 EterGrnLib/ModelInstance.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/ModelInstance.h"
#include "../PlatformStub.h"
auto CGrannyModelInstance::DestroySystem() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::New() -> CGrannyModelInstance *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyModelInstance *>();
}
auto CGrannyModelInstance::Delete(CGrannyModelInstance *) -> void
{
MT_PLATFORM_STUB();
}
decltype(CGrannyModelInstance::ms_kPool) CGrannyModelInstance::ms_kPool{};
CGrannyModelInstance::CGrannyModelInstance()
{
MT_PLATFORM_STUB();
}
CGrannyModelInstance::~CGrannyModelInstance()
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::IsEmpty() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::Clear() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::Update(DWORD) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::UpdateLocalTime(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::UpdateTransform(D3DXMATRIX *, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::UpdateSkeleton(const D3DXMATRIX *, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::DeformNoSkin(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::Deform(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::BlendRenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::BlendRenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderWithoutTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::GetModel() -> CGrannyModel *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyModel *>();
}
auto CGrannyModelInstance::SetMaterialImagePointer(const char *, CGraphicImage *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetMaterialData(const char *, const SMaterialData &) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetSpecularInfo(const char *, BOOL, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetMainModelPointer(CGrannyModel *, CGraphicVertexBuffer *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetLinkedModelPointer(CGrannyModel *, CGraphicVertexBuffer *, CGrannyModelInstance **) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetMotionPointer(const CGrannyMotion *, float, int, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::ChangeMotionPointer(const CGrannyMotion *, int, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetMotionAtEnd() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::IsMotionPlaying() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::CopyMotion(CGrannyModelInstance *, bool) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetLocalTime(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::ResetLocalTime() -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGrannyModelInstance::GetLocalTime() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGrannyModelInstance::GetNextTime() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGrannyModelInstance::GetDeformableVertexCount() -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGrannyModelInstance::GetVertexCount() -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGrannyModelInstance::GetBoneMatrixPointer(int) const -> const float *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const float *>();
}
auto CGrannyModelInstance::GetCompositeBoneMatrixPointer(int) const -> const float *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const float *>();
}
auto CGrannyModelInstance::GetMeshMatrixPointer(int, const D3DXMATRIX **) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::GetBoneIndexByName(const char *, int *) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::SetParentModelInstance(const CGrannyModelInstance *, const char *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::SetParentModelInstance(const CGrannyModelInstance *, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::Intersect(const D3DXMATRIX *, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::MakeBoundBox(TBoundBox *, const float *, const float *, const float *, D3DXVECTOR3 *, D3DXVECTOR3 *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::GetBoundBox(D3DXVECTOR3 *, D3DXVECTOR3 *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::ReloadTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__DestroyModelInstance() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__DestroyMeshMatrices() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__DestroyDynamicVertexBuffer() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__CreateModelInstance() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__CreateMeshMatrices() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__CreateDynamicVertexBuffer() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__DestroyWorldPose() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__CreateWorldPose(CGrannyModelInstance *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__CreateMeshBindingVector(CGrannyModelInstance *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::__DestroyMeshBindingVector() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__GetMeshBoneIndices(unsigned int) const -> int *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int *>();
}
auto CGrannyModelInstance::__IsDeformableVertexBuffer() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyModelInstance::__SetSharedDeformableVertexBuffer(CGraphicVertexBuffer *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::__GetDeformableD3DVertexBufferPtr() -> IDirect3DVertexBuffer8 *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<IDirect3DVertexBuffer8 *>();
}
auto CGrannyModelInstance::__GetDeformableVertexBufferRef() -> CGraphicVertexBuffer &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicVertexBuffer &>();
}
auto CGrannyModelInstance::__GetWorldPosePtr() const -> granny_world_pose *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<granny_world_pose *>();
}
auto CGrannyModelInstance::UpdateWorldPose() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::UpdateWorldMatrices(const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::DeformPNTVertices(void *) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderMeshNodeListWithOneTexture(CGrannyMesh::EType, CGrannyMaterial::EType) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderMeshNodeListWithTwoTexture(CGrannyMesh::EType, CGrannyMaterial::EType) -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyModelInstance::RenderMeshNodeListWithoutTexture(CGrannyMesh::EType, CGrannyMaterial::EType) -> void
{
MT_PLATFORM_STUB();
}
@@ -1,61 +0,0 @@
// Platform skeleton for EterGrnLib/Motion.h (40250 EterGrnLib/Motion.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Motion.h"
#include "../PlatformStub.h"
CGrannyMotion::CGrannyMotion()
{
MT_PLATFORM_STUB();
}
CGrannyMotion::~CGrannyMotion()
{
MT_PLATFORM_STUB();
}
auto CGrannyMotion::IsEmpty() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMotion::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMotion::BindGrannyAnimation(granny_animation *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGrannyMotion::GetGrannyAnimationPointer() const -> granny_animation *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<granny_animation *>();
}
auto CGrannyMotion::GetName() const -> const char *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const char *>();
}
auto CGrannyMotion::GetDuration() const -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGrannyMotion::GetTextTrack(const char *, int *, float *) const -> void
{
MT_PLATFORM_STUB();
}
auto CGrannyMotion::Initialize() -> void
{
MT_PLATFORM_STUB();
}
-109
View File
@@ -1,109 +0,0 @@
// Platform skeleton for EterGrnLib/Thing.h (40250 EterGrnLib/Thing.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Thing.h"
#include "../PlatformStub.h"
auto CGraphicThing::Type() -> CGraphicThing::TType
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicThing::TType>();
}
CGraphicThing::CGraphicThing(const char * c_szFileName) : CResource(c_szFileName) // initializers as in 40250
{
MT_PLATFORM_STUB();
}
CGraphicThing::~CGraphicThing()
{
MT_PLATFORM_STUB();
}
auto CGraphicThing::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThing::CheckModelIndex(int) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::GetModelPointer(int) -> CGrannyModel *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyModel *>();
}
auto CGraphicThing::GetModelCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGraphicThing::CheckMotionIndex(int) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::GetMotionPointer(int) -> CGrannyMotion *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyMotion *>();
}
auto CGraphicThing::GetMotionCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGraphicThing::Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThing::LoadModels() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::LoadMotions() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::OnLoad(int, const void *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::OnClear() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThing::OnIsEmpty() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThing::OnIsType(TType) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
@@ -1,440 +0,0 @@
// Platform skeleton for EterGrnLib/ThingInstance.h (40250 EterGrnLib/ThingInstance.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/ThingInstance.h"
#include "../PlatformStub.h"
CGraphicThingInstance::CGraphicThingInstance()
{
MT_PLATFORM_STUB();
}
CGraphicThingInstance::~CGraphicThingInstance()
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::DeformNoSkin() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::UpdateLODLevel() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::UpdateTime() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::DeformAll() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::LessRenderOrder(CGraphicThingInstance *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::Picking(const D3DXVECTOR3 &, const D3DXVECTOR3 &, float &, float &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::OnInitialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::ReserveModelInstance(int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::ReserveModelThing(int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::CheckModelInstanceIndex(int) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::CheckModelThingIndex(int) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::CheckMotionThingIndex(DWORD) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::GetMotionThingPointer(DWORD, CGraphicThing **) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::IsMotionThing() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::RegisterModelThing(int, CGraphicThing *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::RegisterLODThing(int, CGraphicThing *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::RegisterMotionThing(DWORD, CGraphicThing *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::SetModelInstance(int, int, int, int) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::SetEndStopMotion() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::SetMotionAtEnd() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::AttachModelInstance(int, const char *, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::AttachModelInstance(int, const char *, CGraphicThingInstance &, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::DetachModelInstance(int, CGraphicThingInstance &, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::FindBoneIndex(int, const char *, int *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::GetBonePosition(int, int, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::ResetLocalTime() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::InsertDelay(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::SetMaterialImagePointer(UINT, const char *, CGraphicImage *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::SetMaterialData(UINT, const char *, SMaterialData) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::SetSpecularInfo(UINT, const char *, BOOL, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::__SetLocalTime(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::GetLastLocalTime() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicThingInstance::GetLocalTime() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicThingInstance::GetSecondElapsed() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicThingInstance::GetAverageSecondElapsed() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicThingInstance::GetLODLevel(DWORD) -> BYTE
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BYTE>();
}
auto CGraphicThingInstance::GetHeight() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicThingInstance::RenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::RenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::BlendRenderWithOneTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::BlendRenderWithTwoTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::GetLODControllerCount() const -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGraphicThingInstance::GetLODControllerPointer(DWORD) const -> CGrannyLODController *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyLODController *>();
}
auto CGraphicThingInstance::GetLODControllerPointer(DWORD) -> CGrannyLODController *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGrannyLODController *>();
}
auto CGraphicThingInstance::ReloadTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::GetBaseThingPtr() -> CGraphicThing *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicThing *>();
}
auto CGraphicThingInstance::SetMotion(DWORD, float, int, float) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::ChangeMotion(DWORD, int, float) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::Intersect(float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::GetBoundBox(D3DXVECTOR3 *, D3DXVECTOR3 *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::GetBoundBox(DWORD, D3DXVECTOR3 *, D3DXVECTOR3 *) -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGraphicThingInstance::GetBoneMatrix(DWORD, DWORD, D3DXMATRIX **) -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGraphicThingInstance::GetCompositeBoneMatrix(DWORD, DWORD, D3DXMATRIX **) -> BOOL
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<BOOL>();
}
auto CGraphicThingInstance::UpdateTransform(D3DXMATRIX *, float, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::ProjectShadow(const CGraphicShadowTexture &) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::BuildBoundingSphere() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::BuildBoundingAABB() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::CalculateBBox() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::GetBoundingSphere(D3DXVECTOR3 &, float &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::GetBoundingAABB(D3DXVECTOR3 &, D3DXVECTOR3 &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::OnClear() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnDeform() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnUpdate() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnRender() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnBlendRender() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnRenderToShadowMap() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnRenderShadow() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnRenderPCBlocker() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnUpdateCollisionData(const CStaticCollisionDataVector *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnUpdateHeighInstance(CAttributeInstance *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::OnGetObjectHeight(float, float, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicThingInstance::CreateSystem(UINT) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::DestroySystem() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicThingInstance::New() -> CGraphicThingInstance *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CGraphicThingInstance *>();
}
auto CGraphicThingInstance::Delete(CGraphicThingInstance *) -> void
{
MT_PLATFORM_STUB();
}
decltype(CGraphicThingInstance::ms_kPool) CGraphicThingInstance::ms_kPool{};
auto CGraphicThingInstance::HaveBlendThing() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
@@ -1,12 +0,0 @@
// Platform skeleton for EterGrnLib/Util.h (40250 EterGrnLib/Util.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterGrnLib/StdAfx.h"
#include "EterGrnLib/Util.h"
#include "../PlatformStub.h"
auto GrannyMeshIsDeform(granny_mesh *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
@@ -0,0 +1,47 @@
#pragma once
// CPU-memory vertex/index buffers behind the D3D8 buffer handles. 40250 fills its buffers through
// Lock/Unlock (CGrannyModel::__LoadVertices, CGrannyModelInstance deform) and the renderer later reads
// them back, so the platform keeps the bytes in memory instead of creating device objects.
#include "EterLib/StdAfx.h"
#include <cstdint>
#include <vector>
struct MtCpuVertexBuffer : IDirect3DVertexBuffer8
{
std::vector<uint8_t> bytes;
DWORD fvf = 0;
};
struct MtCpuIndexBuffer : IDirect3DIndexBuffer8
{
std::vector<uint8_t> bytes;
D3DFORMAT format = D3DFMT_INDEX16;
};
// D3DXGetFVFVertexSize.
inline unsigned mt_fvf_vertex_size(DWORD fvf)
{
unsigned size = 0;
switch (fvf & D3DFVF_POSITION_MASK)
{
case D3DFVF_XYZ: size += 12; break;
case D3DFVF_XYZRHW: size += 16; break;
case D3DFVF_XYZB1: size += 16; break;
case D3DFVF_XYZB2: size += 20; break;
case D3DFVF_XYZB3: size += 24; break;
case D3DFVF_XYZB4: size += 28; break;
case D3DFVF_XYZB5: size += 32; break;
}
if (fvf & D3DFVF_NORMAL) size += 12;
if (fvf & D3DFVF_PSIZE) size += 4;
if (fvf & D3DFVF_DIFFUSE) size += 4;
if (fvf & D3DFVF_SPECULAR) size += 4;
const unsigned texCount = (fvf & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
for (unsigned i = 0; i < texCount; ++i)
{
static const unsigned coordSize[4] = { 8, 12, 16, 4 };
size += coordSize[(fvf >> (16 + i * 2)) & 3];
}
return size;
}
@@ -1,70 +0,0 @@
// Platform skeleton for EterLib/GrpCollisionObject.h (40250 EterLib/GrpCollisionObject.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterLib/StdAfx.h"
#include "EterLib/GrpCollisionObject.h"
#include "../PlatformStub.h"
CGraphicCollisionObject::CGraphicCollisionObject()
{
MT_PLATFORM_STUB();
}
CGraphicCollisionObject::~CGraphicCollisionObject()
{
MT_PLATFORM_STUB();
}
auto CGraphicCollisionObject::IntersectTriangle(const D3DXVECTOR3 &, const D3DXVECTOR3 &, const D3DXVECTOR3 &, const D3DXVECTOR3 &, const D3DXVECTOR3 &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectBoundBox(const D3DXMATRIX *, const TBoundBox &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectCube(const D3DXMATRIX *, float, float, float, float, float, float, D3DXVECTOR3 &, D3DXVECTOR3 &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectIndexedMesh(const D3DXMATRIX *, const void *, int, int, const void *, int, D3DXVECTOR3 &, D3DXVECTOR3 &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectMesh(const D3DXMATRIX *, const void *, DWORD, DWORD, D3DXVECTOR3 &, D3DXVECTOR3 &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectSphere(const D3DXVECTOR3 &, float, const D3DXVECTOR3 &, const D3DXVECTOR3 &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectCylinder(const D3DXVECTOR3 &, float, float, const D3DXVECTOR3 &, const D3DXVECTOR3 &) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectSphere(const D3DXVECTOR3 &, float) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicCollisionObject::IntersectCylinder(const D3DXVECTOR3 &, float, float) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
+115 -77
View File
@@ -1,88 +1,126 @@
// Platform skeleton for EterLib/GrpIndexBuffer.h (40250 EterLib/GrpIndexBuffer.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
// 40250 EterLib/GrpIndexBuffer.cpp over CPU memory (CpuBuffer.h).
#include "EterLib/StdAfx.h"
#include "EterLib/GrpIndexBuffer.h"
#include "EterLib/StateManager.h"
#include "../PlatformStub.h"
#include "CpuBuffer.h"
namespace {
BYTE* index_bytes(LPDIRECT3DINDEXBUFFER8 buffer)
{
return static_cast<MtCpuIndexBuffer*>(buffer)->bytes.data();
}
}
LPDIRECT3DINDEXBUFFER8 CGraphicIndexBuffer::GetD3DIndexBuffer() const
{
assert(m_lpd3dIdxBuf!=NULL);
return m_lpd3dIdxBuf;
}
void CGraphicIndexBuffer::SetIndices(int startIndex) const
{
STATEMANAGER.SetIndices(m_lpd3dIdxBuf, startIndex);
}
bool CGraphicIndexBuffer::Lock(void** pretIndices) const
{
assert(m_lpd3dIdxBuf!=NULL);
*pretIndices = index_bytes(m_lpd3dIdxBuf);
return true;
}
void CGraphicIndexBuffer::Unlock() const
{
assert(m_lpd3dIdxBuf!=NULL);
}
bool CGraphicIndexBuffer::Lock(void** pretIndices)
{
assert(m_lpd3dIdxBuf!=NULL);
*pretIndices = index_bytes(m_lpd3dIdxBuf);
return true;
}
void CGraphicIndexBuffer::Unlock()
{
assert(m_lpd3dIdxBuf!=NULL);
}
bool CGraphicIndexBuffer::Copy(int bufSize, const void* srcIndices)
{
assert(m_lpd3dIdxBuf!=NULL);
memcpy(index_bytes(m_lpd3dIdxBuf), srcIndices, bufSize);
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 = reinterpret_cast<WORD*>(index_bytes(m_lpd3dIdxBuf));
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];
}
return true;
}
bool CGraphicIndexBuffer::CreateDeviceObjects()
{
MtCpuIndexBuffer* buffer = new MtCpuIndexBuffer;
buffer->bytes.assign(m_dwBufferSize, 0);
buffer->format = m_d3dFmt;
m_lpd3dIdxBuf = buffer;
return true;
}
void CGraphicIndexBuffer::DestroyDeviceObjects()
{
delete static_cast<MtCpuIndexBuffer*>(m_lpd3dIdxBuf);
m_lpd3dIdxBuf = NULL;
}
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;
m_iidxCount=0;
m_dwBufferSize=0;
}
CGraphicIndexBuffer::CGraphicIndexBuffer()
{
MT_PLATFORM_STUB();
Initialize();
}
CGraphicIndexBuffer::~CGraphicIndexBuffer()
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::Create(int, D3DFORMAT) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::Create(int, TFace *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::Copy(int, const void *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::Lock(void **) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::Unlock() const -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::Lock(void **) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicIndexBuffer::Unlock() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::SetIndices(int) const -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicIndexBuffer::GetD3DIndexBuffer() const -> LPDIRECT3DINDEXBUFFER8
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<LPDIRECT3DINDEXBUFFER8>();
}
auto CGraphicIndexBuffer::Initialize() -> void
{
MT_PLATFORM_STUB();
Destroy();
}
@@ -1,270 +0,0 @@
// Platform skeleton for EterLib/GrpObjectInstance.h (40250 EterLib/GrpObjectInstance.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
#include "EterLib/StdAfx.h"
#include "EterLib/GrpObjectInstance.h"
#include "../PlatformStub.h"
CGraphicObjectInstance::CGraphicObjectInstance()
{
MT_PLATFORM_STUB();
}
CGraphicObjectInstance::~CGraphicObjectInstance()
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::GetPosition() const -> const D3DXVECTOR3 &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const D3DXVECTOR3 &>();
}
auto CGraphicObjectInstance::GetScale() const -> const D3DXVECTOR3 &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<const D3DXVECTOR3 &>();
}
auto CGraphicObjectInstance::GetRotation() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicObjectInstance::GetYaw() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicObjectInstance::GetPitch() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicObjectInstance::GetRoll() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CGraphicObjectInstance::SetPosition(float, float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetPosition(const D3DXVECTOR3 &) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetScale(float, float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetRotation(float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetRotation(float, float, float) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetRotationQuaternion(const D3DXQUATERNION &) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::SetRotationMatrix(const D3DXMATRIX &) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Clear() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Update() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Render() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::BlendRender() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::RenderToShadowMap() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::RenderShadow() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::RenderPCBlocker() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Deform() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Transform() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Show() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::Hide() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::isShow() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::isIntersect(const CRay &, float *, float *, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::GetWTBBoxVertex(const unsigned char &) -> D3DXVECTOR4 &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<D3DXVECTOR4 &>();
}
auto CGraphicObjectInstance::GetTransform() -> D3DXMATRIX &
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<D3DXMATRIX &>();
}
auto CGraphicObjectInstance::SetPortal(DWORD, int) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::GetPortal(DWORD) -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGraphicObjectInstance::Initialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::OnInitialize() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::UpdateBoundingSphere() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::RegisterBoundingSphere() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::AddCollision(const CStaticCollisionData *, const D3DXMATRIX *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::ClearCollision() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::CollisionDynamicSphere(const CDynamicSphereInstance &) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::MovementCollisionDynamicSphere(const CDynamicSphereInstance &) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::GetCollisionMovementAdjust(const CDynamicSphereInstance &) const -> D3DXVECTOR3
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<D3DXVECTOR3>();
}
auto CGraphicObjectInstance::UpdateCollisionData(const CStaticCollisionDataVector *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::GetCollisionInstanceCount() -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGraphicObjectInstance::GetCollisionInstanceData(DWORD) -> CBaseCollisionInstance *
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<CBaseCollisionInstance *>();
}
auto CGraphicObjectInstance::SetHeightInstance(CAttributeInstance *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::ClearHeightInstance() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::UpdateHeightInstance(CAttributeInstance *) -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicObjectInstance::IsObjectHeight() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicObjectInstance::GetObjectHeight(float, float, float *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
+149 -103
View File
@@ -1,114 +1,160 @@
// Platform skeleton for EterLib/GrpVertexBuffer.h (40250 EterLib/GrpVertexBuffer.cpp), generated by platform_stub.py.
// Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation.
// 40250 EterLib/GrpVertexBuffer.cpp over CPU memory (CpuBuffer.h): the device buffer is a byte vector
// that Lock hands out directly, so Granny vertex loading and deform write real data.
#include "EterLib/StdAfx.h"
#include "EterLib/GrpVertexBuffer.h"
#include "EterLib/StateManager.h"
#include "../PlatformStub.h"
#include "CpuBuffer.h"
int CGraphicVertexBuffer::GetVertexStride() const
{
int retSize = mt_fvf_vertex_size(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
{
STATEMANAGER.SetStreamSource(layer, m_lpd3dVB, stride);
}
bool CGraphicVertexBuffer::LockRange(unsigned count, void** pretVertices) const
{
if (!m_lpd3dVB)
return false;
*pretVertices = static_cast<MtCpuVertexBuffer*>(m_lpd3dVB)->bytes.data();
return true;
}
bool CGraphicVertexBuffer::Lock(void ** pretVertices) const
{
if (!m_lpd3dVB)
return false;
*pretVertices = static_cast<MtCpuVertexBuffer*>(m_lpd3dVB)->bytes.data();
return true;
}
bool CGraphicVertexBuffer::Unlock() const
{
if (!m_lpd3dVB)
return false;
return true;
}
// Returns true when a buffer exists, as 40250 does.
bool CGraphicVertexBuffer::IsEmpty() const
{
if (m_lpd3dVB)
return true;
else
return false;
}
bool CGraphicVertexBuffer::LockDynamic(void** pretVertices)
{
if (!m_lpd3dVB)
return false;
*pretVertices = static_cast<MtCpuVertexBuffer*>(m_lpd3dVB)->bytes.data();
return true;
}
bool CGraphicVertexBuffer::Lock(void ** pretVertices)
{
if (!m_lpd3dVB)
return false;
*pretVertices = static_cast<MtCpuVertexBuffer*>(m_lpd3dVB)->bytes.data();
return true;
}
bool CGraphicVertexBuffer::Unlock()
{
if (!m_lpd3dVB)
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(m_lpd3dVB == NULL);
MtCpuVertexBuffer* buffer = new MtCpuVertexBuffer;
buffer->bytes.assign(m_dwBufferSize, 0);
buffer->fvf = m_dwFVF;
m_lpd3dVB = buffer;
return true;
}
void CGraphicVertexBuffer::DestroyDeviceObjects()
{
delete static_cast<MtCpuVertexBuffer*>(m_lpd3dVB);
m_lpd3dVB = NULL;
}
bool CGraphicVertexBuffer::Create(int vtxCount, DWORD fvf, DWORD usage, D3DPOOL d3dPool)
{
assert(vtxCount > 0);
Destroy();
m_vtxCount = vtxCount;
m_dwBufferSize = mt_fvf_vertex_size(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;
m_dwFVF = 0;
}
CGraphicVertexBuffer::CGraphicVertexBuffer()
{
MT_PLATFORM_STUB();
Initialize();
}
CGraphicVertexBuffer::~CGraphicVertexBuffer()
{
MT_PLATFORM_STUB();
}
auto CGraphicVertexBuffer::Destroy() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicVertexBuffer::Create(int, DWORD, DWORD, D3DPOOL) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::CreateDeviceObjects() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::DestroyDeviceObjects() -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicVertexBuffer::Copy(int, const void *) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::LockRange(unsigned int, void **) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::Lock(void **) const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::Unlock() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::LockDynamic(void **) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::Lock(void **) -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::Unlock() -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::SetStream(int, int) const -> void
{
MT_PLATFORM_STUB();
}
auto CGraphicVertexBuffer::GetVertexCount() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGraphicVertexBuffer::GetVertexStride() const -> int
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<int>();
}
auto CGraphicVertexBuffer::GetFlexibleVertexFormat() const -> DWORD
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<DWORD>();
}
auto CGraphicVertexBuffer::IsEmpty() const -> bool
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CGraphicVertexBuffer::Initialize() -> void
{
MT_PLATFORM_STUB();
Destroy();
}
@@ -0,0 +1,4 @@
#pragma once
// The cursor in client coordinates, as the host (Godot) last pushed it. 40250 CMSWindow::GetMousePosition
// asks Win32 (GetCursorPos + ScreenToClient); here the host is the only source of mouse input.
void MtHostSetCursor(int x, int y);
+13 -2
View File
@@ -4,6 +4,7 @@
#include "EterLib/MSWindow.h"
#include "../PlatformStub.h"
#include "HostCursor.h"
CMSWindow::CMSWindow()
{
@@ -78,9 +79,19 @@ auto CMSWindow::IsActive() -> bool
return mt_platform_stub_return<bool>();
}
auto CMSWindow::GetMousePosition(POINT *) -> void
namespace {
POINT g_host_cursor = {0, 0};
}
void MtHostSetCursor(int x, int y)
{
MT_PLATFORM_STUB();
g_host_cursor.x = x;
g_host_cursor.y = y;
}
auto CMSWindow::GetMousePosition(POINT * ppt) -> void
{
*ppt = g_host_cursor;
}
auto CMSWindow::GetClientRect(RECT *) -> void
@@ -12,6 +12,22 @@
#include "../PlatformStub.h"
#include "../EterLib/UIRenderCommands.h"
// 40250 PythonGraphic.cpp:611
CPythonGraphic::CPythonGraphic()
{
m_lightColor = GetColor(1.0f, 1.0f, 1.0f);
m_darkColor = GetColor(0.0f, 0.0f, 0.0f);
memset(&m_backupViewport, 0, sizeof(D3DVIEWPORT8));
m_fOrthoDepth = 1000.0f;
}
CPythonGraphic::~CPythonGraphic()
{
Tracef("Python Graphic Clear\n");
}
void CPythonGraphic::SetViewport(float x, float y, float width, float height) { UIRenderSetClip(x, y, width, height); }
void CPythonGraphic::RestoreViewport() { UIRenderRestoreClip(); }
void CPythonGraphic::SetOmniLight() { MT_PLATFORM_STUB(); }
@@ -7,6 +7,7 @@
#include "EterPythonLib/StdAfx.h"
#include "EterBase/Timer.h"
#include "EterLib/Util.h"
#include "../EterLib/HostCursor.h"
#include "UserInterface/PythonNetworkStream.h"
#include "UserInterface/AccountConnector.h"
#include "UserInterface/PythonPlayer.h"
@@ -103,6 +104,7 @@ struct GameSingletons
CItemManager kItemMgr;
CPythonCharacterManager kChrMgr;
CPythonGraphic pyGraphic; // owns CCullingManager (m_CullingManager)
CPythonItem pyItem;
CPythonShop pyShop;
CPythonExchange pyExchange;
@@ -220,11 +222,13 @@ void SetUISize(int width, int height)
void UIMouseMove(int x, int y)
{
MtHostSetCursor(x, y);
if (g_window_manager) g_window_manager->RunMouseMove(x, y);
}
void UIMouseButton(int button, bool pressed, int x, int y)
{
MtHostSetCursor(x, y);
if (!g_window_manager) return;
g_window_manager->RunMouseMove(x, y);
switch (button)
@@ -3,12 +3,14 @@
#include "EterLib/GrpImage.h"
#include "EterLib/GrpSubImage.h"
#include "EterLib/GrpText.h"
#include "EterGrnLib/Thing.h"
namespace {
CResource* NewUIImage(const char* name) { return new CGraphicImage(name); }
CResource* NewUISubImage(const char* name) { return new CGraphicSubImage(name); }
// 40250 UserInterface/PythonApplication.cpp NewText: a "<face>:<size>[i].fnt" name is a CGraphicText.
CResource* NewText(const char* name) { return new CGraphicText(name); }
CResource* NewThing(const char* name) { return new CGraphicThing(name); }
}
CPythonResource::CPythonResource() {
@@ -16,6 +18,7 @@ CPythonResource::CPythonResource() {
m_resManager.RegisterResourceNewFunctionPointer(ext, NewUIImage);
m_resManager.RegisterResourceNewFunctionPointer("sub", NewUISubImage);
m_resManager.RegisterResourceNewFunctionPointer("fnt", NewText);
m_resManager.RegisterResourceNewFunctionPointer("gr2", NewThing);
}
CPythonResource::~CPythonResource() { m_resManager.DestroyDeletingList(); }
void CPythonResource::Destroy() { m_resManager.DestroyDeletingList(); m_resManager.Destroy(); }
@@ -86,8 +86,107 @@ bool CPythonApplication::Create(PyObject*, const char*, int, int, int)
}
return true;
}
void CPythonApplication::UpdateGame() { MT_PLATFORM_STUB(); }
void CPythonApplication::RenderGame() { MT_PLATFORM_STUB(); }
// 40250 PythonApplication.cpp:105
void CPythonApplication::GetMousePosition(POINT* ppt)
{
CMSApplication::GetMousePosition(ppt);
}
// 40250 PythonApplication.cpp:168, the !PERF_CHECKER_RENDER_GAME branch (the profiling copy below it
// only adds timers). game.GameWindow.OnRender calls it every frame.
// PORT: the members are reached through their singletons (see the note at the top of the file).
void CPythonApplication::RenderGame()
{
float fAspect=UI::CWindowManager::Instance().GetAspect();
float fFarClip=CPythonBackground::Instance().GetFarClip();
CPythonGraphic::Instance().SetPerspective(30.0f, fAspect, 100.0, fFarClip);
CCullingManager::Instance().Process();
CPythonCharacterManager::Instance().Deform();
CEffectManager::Instance().Update();
CPythonBackground::Instance().RenderCharacterShadowToTexture();
CPythonGraphic::Instance().SetGameRenderState();
CPythonGraphic::Instance().PushState();
{
long lx, ly;
UI::CWindowManager::Instance().GetMousePosition(lx, ly);
CPythonGraphic::Instance().SetCursorPosition(lx, ly);
}
CPythonBackground::Instance().RenderSky();
CPythonBackground::Instance().RenderBeforeLensFlare();
CPythonBackground::Instance().RenderCloud();
CPythonBackground::Instance().BeginEnvironment();
CPythonBackground::Instance().Render();
CPythonBackground::Instance().SetCharacterDirLight();
CPythonCharacterManager::Instance().Render();
CPythonBackground::Instance().SetBackgroundDirLight();
CPythonBackground::Instance().RenderWater();
CPythonBackground::Instance().RenderSnow();
CPythonBackground::Instance().RenderEffect();
CPythonBackground::Instance().EndEnvironment();
CEffectManager::Instance().Render();
CPythonItem::Instance().Render();
CFlyingManager::Instance().Render();
CPythonBackground::Instance().BeginEnvironment();
CPythonBackground::Instance().RenderPCBlocker();
CPythonBackground::Instance().EndEnvironment();
CPythonBackground::Instance().RenderAfterLensFlare();
}
// 40250 PythonApplication.cpp:321 without the PERF_CHECKER_RENDER_GAME timers. game.GameWindow.OnUpdate
// calls it every frame. PORT: members through their singletons, as in RenderGame.
void CPythonApplication::UpdateGame()
{
POINT ptMouse;
GetMousePosition(&ptMouse);
CGraphicTextInstance::Hyperlink_UpdateMousePos(ptMouse.x, ptMouse.y);
//!@# Alt+Tab 중 SetTransfor 에서 튕김 현상 해결을 위해 - [levites]
//if (m_isActivateWnd)
{
CScreen s;
float fAspect = UI::CWindowManager::Instance().GetAspect();
float fFarClip = CPythonBackground::Instance().GetFarClip();
s.SetPerspective(30.0f,fAspect, 100.0f, fFarClip);
s.BuildViewFrustum();
}
TPixelPosition kPPosMainActor;
CPythonPlayer::Instance().NEW_GetMainActorPosition(&kPPosMainActor);
CPythonBackground::Instance().Update(kPPosMainActor.x, kPPosMainActor.y, kPPosMainActor.z);
CGameEventManager::Instance().SetCenterPosition(kPPosMainActor.x, kPPosMainActor.y, kPPosMainActor.z);
CGameEventManager::Instance().Update();
CPythonCharacterManager::Instance().Update();
CEffectManager::Instance().UpdateSound();
CFlyingManager::Instance().Update();
CPythonItem::Instance().Update(ptMouse);
CPythonPlayer::Instance().Update();
// NOTE : Update 에서 위치 값이 바뀌므로 다시 얻어 옵니다 - [levites]
// 이 부분 때문에 메인 케릭터의 Sound가 이전 위치에서 플레이 되는 현상이 있었음.
CPythonPlayer::Instance().NEW_GetMainActorPosition(&kPPosMainActor);
SetCenterPosition(kPPosMainActor.x, kPPosMainActor.y, kPPosMainActor.z);
}
// 40250 PythonApplication.cpp:399. Kept in order: timer, network (2V1), input polling (Godot pushes
// input instead), camera (2V3), resource GC, mouse/UI update, then the render block's interface pass.
@@ -166,7 +265,6 @@ void CMovieMan::PlayLogo(const char*) { MT_PLATFORM_STUB(); }
BOOL PERF_CHECKER_RENDER_GAME = FALSE;
BOOL SKILL_EFFECT_UPGRADE_ENABLE = FALSE;
D3DXCOLOR g_fSpecularColor;
double g_specularSpd = 0;
bool LoadLocaleData(const char*) { MT_PLATFORM_STUB(); return false; }
@@ -1,23 +0,0 @@
// Stand-in for the 40250 logic unit EterLib/CollisionData.cpp, not ported yet: the members the ported units
// reference, as platform_stub.py stubs. Delete this file in the commit that ports the unit into port/
// (docs/PORT-PLAN.md).
#include "EterLib/StdAfx.h"
#include "EterLib/CollisionData.h"
#include "../../PlatformStub.h"
auto CSphereCollisionInstance::GetAttribute() -> TSphereData &
{
MT_PLATFORM_STUB();
return m_attribute;
}
auto CSphereCollisionInstance::GetAttribute() const -> const TSphereData & { return m_attribute; }
auto CSphereCollisionInstance::Render(D3DFILLMODE) -> void { MT_PLATFORM_STUB(); }
auto CSphereCollisionInstance::OnDestroy() -> void { MT_PLATFORM_STUB(); }
auto CSphereCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance&) const -> bool
{ MT_PLATFORM_STUB(); return false; }
auto CSphereCollisionInstance::OnCollisionDynamicSphere(const CDynamicSphereInstance&) const -> bool
{ MT_PLATFORM_STUB(); return false; }
auto CSphereCollisionInstance::OnGetCollisionMovementAdjust(const CDynamicSphereInstance&) const -> D3DXVECTOR3
{ MT_PLATFORM_STUB(); return D3DXVECTOR3(0, 0, 0); }
@@ -68,3 +68,13 @@ auto CMapManager::isAttrOn(int, int, BYTE) -> bool
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CMapManager::BeginEnvironment() -> void
{
MT_PLATFORM_STUB();
}
auto CMapManager::EndEnvironment() -> void
{
MT_PLATFORM_STUB();
}
@@ -94,3 +94,69 @@ auto CPythonBackground::GetPickingPointWithRayOnlyTerrain(const CRay &, D3DXVECT
MT_PLATFORM_STUB();
return mt_platform_stub_return<bool>();
}
auto CPythonBackground::GetFarClip() -> float
{
MT_PLATFORM_STUB();
return mt_platform_stub_return<float>();
}
auto CPythonBackground::Render() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderAfterLensFlare() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderBeforeLensFlare() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderCharacterShadowToTexture() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderCloud() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderEffect() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderPCBlocker() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderSky() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderSnow() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::RenderWater() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::SetBackgroundDirLight() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonBackground::SetCharacterDirLight() -> void
{
MT_PLATFORM_STUB();
}
@@ -55,3 +55,13 @@ auto CPythonItem::SetOwnership(DWORD, const char *) -> void
{
MT_PLATFORM_STUB();
}
auto CPythonItem::Render() -> void
{
MT_PLATFORM_STUB();
}
auto CPythonItem::Update(const POINT &) -> void
{
MT_PLATFORM_STUB();
}
@@ -0,0 +1,695 @@
#include "StdAfx.h"
#include "LODController.h"
static float LODHEIGHT_ACTOR = 500.0f;
static float LODDISTANCE_ACTOR = 5000.0f;
static float LODDISTANCE_BUILDING = 25000.0f;
static const float c_fNearLodScale = 3.0f;
static const float c_fFarLodScale = 25.0f;
static const float LOD_APPLY_MAX = 2000.0f;
static const float LOD_APPLY_MIN = 500.0f;
bool ms_isMinLODModeEnable=false;
enum
{
SHARED_VB_500 = 0,
SHARED_VB_1000 = 1,
SHARED_VB_1500 = 2,
SHARED_VB_2000 = 3,
SHARED_VB_2500 = 4,
SHARED_VB_3000 = 5,
SHARED_VB_3500 = 6,
SHARED_VB_4000 = 7,
SHARED_VB_NUM = 9,
};
static std::vector<CGraphicVertexBuffer*> gs_vbs[SHARED_VB_NUM];
static CGraphicVertexBuffer gs_emptyVB;
#include <time.h>
static CGraphicVertexBuffer* __AllocDeformVertexBuffer(unsigned deformableVertexCount)
{
if (deformableVertexCount == 0)
return &gs_emptyVB;
unsigned capacity = (((deformableVertexCount-1) / 500) + 1) * 500;
unsigned index = (deformableVertexCount-1) / 500;
if (index < SHARED_VB_NUM)
{
std::vector<CGraphicVertexBuffer*>& vbs = gs_vbs[index];
if (!vbs.empty())
{
//TraceError("REUSE %d(%d)", capacity, deformableVertexCount);
CGraphicVertexBuffer* pkRetVB = vbs.back();
vbs.pop_back();
return pkRetVB;
}
}
static time_t base = time(NULL);
//TraceError("NEW %8d: %d(%d)", time(NULL) - base, capacity, deformableVertexCount);
CGraphicVertexBuffer* pkNewVB = new CGraphicVertexBuffer;
if (!pkNewVB->Create(
capacity,
D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1,
D3DUSAGE_WRITEONLY,
D3DPOOL_MANAGED))
{
TraceError("NEW_ERROR %8d: %d(%d)", time(NULL) - base, capacity, deformableVertexCount);
}
return pkNewVB;
}
void __FreeDeformVertexBuffer(CGraphicVertexBuffer* pkDelVB)
{
if (pkDelVB)
{
if (pkDelVB == &gs_emptyVB)
return;
unsigned index = (pkDelVB->GetVertexCount() - 1) / 500;
if (index < SHARED_VB_NUM)
{
gs_vbs[index].push_back(pkDelVB);
}
else
{
pkDelVB->Destroy();
delete pkDelVB;
}
}
}
void __ReserveSharedVertexBuffers(unsigned index, unsigned count)
{
NANOBEGIN
if (index >= SHARED_VB_NUM)
return;
unsigned capacity = (index + 1) * 500;
for (unsigned i = 0; i != count; ++i)
{
CGraphicVertexBuffer* pkNewVB = new CGraphicVertexBuffer;
pkNewVB->Create(
capacity,
D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1,
D3DUSAGE_WRITEONLY,
D3DPOOL_MANAGED);
gs_vbs[index].push_back(pkNewVB);
}
NANOEND
}
void GrannyCreateSharedDeformBuffer()
{
__ReserveSharedVertexBuffers(SHARED_VB_500, 40);
__ReserveSharedVertexBuffers(SHARED_VB_1000, 20);
__ReserveSharedVertexBuffers(SHARED_VB_1500, 20);
__ReserveSharedVertexBuffers(SHARED_VB_2000, 40);
__ReserveSharedVertexBuffers(SHARED_VB_3000, 20);
}
void GrannyDestroySharedDeformBuffer()
{
#ifdef _DEBUG
TraceError("granny_shared_vbs:");
#endif
for (int i = 0; i != SHARED_VB_NUM; ++i)
{
std::vector<CGraphicVertexBuffer*>& vbs = gs_vbs[i];
#ifdef _DEBUG
TraceError("\t%d: %d", i, vbs.size());
#endif
std::vector<CGraphicVertexBuffer*>::iterator v;
for (v = vbs.begin(); v != vbs.end(); ++v)
{
CGraphicVertexBuffer* pkEachVB = (*v);
pkEachVB->Destroy();
delete pkEachVB;
}
vbs.clear();
}
}
void CGrannyLODController::SetMinLODMode(bool isEnable)
{
ms_isMinLODModeEnable=isEnable;
}
void CGrannyLODController::SetMaterialImagePointer(const char* c_szImageName, CGraphicImage* pImage)
{
std::deque<CGrannyModelInstance *>::iterator i;
for (i=m_que_pkModelInst.begin(); i!=m_que_pkModelInst.end(); ++i)
{
CGrannyModelInstance* pkModelInst=(*i);
pkModelInst->SetMaterialImagePointer(c_szImageName, pImage);
}
}
void CGrannyLODController::SetMaterialData(const char* c_szImageName, const SMaterialData& c_rkMaterialData)
{
std::deque<CGrannyModelInstance *>::iterator i;
for (i=m_que_pkModelInst.begin(); i!=m_que_pkModelInst.end(); ++i)
{
CGrannyModelInstance* pkModelInst=(*i);
pkModelInst->SetMaterialData(c_szImageName, c_rkMaterialData);
}
}
void CGrannyLODController::SetSpecularInfo(const char* c_szMtrlName, BOOL bEnable, float fPower)
{
std::deque<CGrannyModelInstance *>::iterator i;
for (i=m_que_pkModelInst.begin(); i!=m_que_pkModelInst.end(); ++i)
{
CGrannyModelInstance* pkModelInst=(*i);
pkModelInst->SetSpecularInfo(c_szMtrlName, bEnable, fPower);
}
}
CGrannyLODController::CGrannyLODController() :
m_pCurrentModelInstance(NULL),
m_bLODLevel(0),
m_pAttachedParentModel(NULL),
m_fLODDistance(0.0f),
m_dwLODAniFPS(CGrannyModelInstance::ANIFPS_MAX),
m_pkSharedDeformableVertexBuffer(NULL)
/////////////////////////////////////////////////////
{
}
CGrannyLODController::~CGrannyLODController()
{
__FreeDeformVertexBuffer(m_pkSharedDeformableVertexBuffer);
Clear();
}
void CGrannyLODController::Clear()
{
if (m_pAttachedParentModel)
{
m_pAttachedParentModel->DetachModelInstance(this);
}
m_pCurrentModelInstance = NULL;
m_pAttachedParentModel = NULL;
std::for_each(m_que_pkModelInst.begin(), m_que_pkModelInst.end(), CGrannyModelInstance::Delete);
m_que_pkModelInst.clear();
std::vector<TAttachingModelData>::iterator itor = m_AttachedModelDataVector.begin();
for (; m_AttachedModelDataVector.end() != itor; ++itor)
{
TAttachingModelData & rData = *itor;
rData.pkLODController->m_pAttachedParentModel = NULL;
}
m_AttachedModelDataVector.clear();
}
void CGrannyLODController::AddModel(CGraphicThing * pThing, int iSrcModel, CGrannyLODController * pSkelLODController)
{
if (!pThing)
return;
if (pSkelLODController && pSkelLODController->m_que_pkModelInst.empty())
{
assert(!"EMPTY SKELETON(CANNON LINK)");
return;
}
assert(pThing->GetReferenceCount()>=1);
pThing->AddReference();
if (pThing->GetModelCount() <= iSrcModel)
{
pThing->Release();
return;
}
CGrannyModel * pModel = pThing->GetModelPointer(iSrcModel);
if (!pModel)
{
pThing->Release();
return;
}
CGrannyModelInstance * pModelInstance = CGrannyModelInstance::New();
__ReserveSharedDeformableVertexBuffer(pModel->GetDeformVertexCount());
if (pSkelLODController)
{
pModelInstance->SetLinkedModelPointer(pModel, m_pkSharedDeformableVertexBuffer, &pSkelLODController->m_pCurrentModelInstance);
}
else
{
pModelInstance->SetLinkedModelPointer(pModel, m_pkSharedDeformableVertexBuffer, NULL);
}
// END_OF_WORK
if (!m_pCurrentModelInstance)
{
m_pCurrentModelInstance = pModelInstance;
pModelInstance->DeformNoSkin(&ms_matIdentity);
D3DXVECTOR3 vtMin, vtMax;
pModelInstance->GetBoundBox(&vtMin, &vtMax);
float fSize = 0.0f;
fSize = fMAX(fSize, fabs(vtMin.x - vtMax.x));
fSize = fMAX(fSize, fabs(vtMin.y - vtMax.y));
fSize = fMAX(fSize, fabs(vtMin.z - vtMax.z));
if (fSize<LODHEIGHT_ACTOR)
SetLODLimits(0.0f, LODDISTANCE_ACTOR);
else
//
SetLODLimits(0.0f, LODDISTANCE_BUILDING);
}
else
{
// FIXME : CModelInstance::m_pgrnWorldPose를 Update에서 사용하는데,
// Deform을 하지 않으면 NULL 입니다. 구조가 조금 바뀌어야 할지도.. - [levites]
pModelInstance->DeformNoSkin(&ms_matIdentity);
}
pThing->Release();
m_que_pkModelInst.push_front(pModelInstance);
}
void CGrannyLODController::__ReserveSharedDeformableVertexBuffer(DWORD deformableVertexCount)
{
if (m_pkSharedDeformableVertexBuffer &&
m_pkSharedDeformableVertexBuffer->GetVertexCount() >= deformableVertexCount)
return;
__FreeDeformVertexBuffer(m_pkSharedDeformableVertexBuffer);
m_pkSharedDeformableVertexBuffer = __AllocDeformVertexBuffer(deformableVertexCount);
}
void CGrannyLODController::AttachModelInstance(CGrannyLODController * pSrcLODController, const char * c_szBoneName)
{
CGrannyModelInstance * pSrcInstance = pSrcLODController->GetModelInstance();
if (!pSrcInstance)
return;
CGrannyModelInstance * pDestInstance = GetModelInstance();
if (pDestInstance)
{
pSrcInstance->SetParentModelInstance(pDestInstance, c_szBoneName);
}
if (!pSrcLODController->GetModelInstance())
return;
// Link Parent Data
pSrcLODController->m_pAttachedParentModel = this;
// Link Child Data
std::vector<TAttachingModelData>::iterator itor = m_AttachedModelDataVector.begin();
for (; m_AttachedModelDataVector.end() != itor;)
{
TAttachingModelData & rData = *itor;
if (pSrcLODController == rData.pkLODController)
{
itor = m_AttachedModelDataVector.erase(itor);
}
else
{
++itor;
}
}
TAttachingModelData AttachingModelData;
AttachingModelData.pkLODController = pSrcLODController;
AttachingModelData.strBoneName = c_szBoneName;
m_AttachedModelDataVector.push_back(AttachingModelData);
}
void CGrannyLODController::DetachModelInstance(CGrannyLODController * pSrcLODController)
{
CGrannyModelInstance * pSrcInstance = pSrcLODController->GetModelInstance();
if (!pSrcInstance)
return;
CGrannyModelInstance * pDestInstance = GetModelInstance();
if (pDestInstance)
{
pSrcInstance->SetParentModelInstance(NULL, 0);
}
// if (!pSrcLODController->GetModelInstance())
// return;
// Unlink Child Data
std::vector<TAttachingModelData>::iterator itor = m_AttachedModelDataVector.begin();
for (; m_AttachedModelDataVector.end() != itor;)
{
TAttachingModelData & rData = *itor;
if (pSrcLODController == rData.pkLODController)
{
itor = m_AttachedModelDataVector.erase(itor);
}
else
{
++itor;
}
}
// Unlink Parent Data
pSrcLODController->m_pAttachedParentModel = NULL;
}
void CGrannyLODController::SetLODLimits(float /*fNearLOD*/, float fFarLOD)
{
m_fLODDistance = fFarLOD;
}
void CGrannyLODController::SetLODLevel(BYTE bLodLevel)
{
assert(m_que_pkModelInst.size() > 0);
if (m_que_pkModelInst.size() > 0)
m_bLODLevel = (BYTE) MIN(m_que_pkModelInst.size() - 1, bLodLevel);
}
void CGrannyLODController::CreateDeviceObjects()
{
std::for_each(m_que_pkModelInst.begin(),
m_que_pkModelInst.end(),
CGrannyModelInstance::FCreateDeviceObjects());
}
void CGrannyLODController::DestroyDeviceObjects()
{
std::for_each(m_que_pkModelInst.begin(),
m_que_pkModelInst.end(),
CGrannyModelInstance::FDestroyDeviceObjects());
}
void CGrannyLODController::RenderWithOneTexture()
{
assert(m_pCurrentModelInstance != NULL);
//#define CHECK_LOD
#ifdef CHECK_LOD
if (m_que_pkModelInst.size() > 0 && m_pCurrentModelInstance == m_que_pkModelInst[0])
m_pCurrentModelInstance->RenderWithoutTexture();
if (m_que_pkModelInst.size() > 1 && m_pCurrentModelInstance == m_que_pkModelInst[1])
m_pCurrentModelInstance->RenderWithOneTexture();
if (m_que_pkModelInst.size() > 2 && m_pCurrentModelInstance == m_que_pkModelInst[2])
m_pCurrentModelInstance->RenderWithOneTexture();
if (m_que_pkModelInst.size() > 3 && m_pCurrentModelInstance == m_que_pkModelInst[3])
m_pCurrentModelInstance->RenderWithOneTexture();
#else
m_pCurrentModelInstance->RenderWithOneTexture();
#endif
}
void CGrannyLODController::BlendRenderWithOneTexture()
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->BlendRenderWithOneTexture();
}
void CGrannyLODController::RenderWithTwoTexture()
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->RenderWithTwoTexture();
}
void CGrannyLODController::BlendRenderWithTwoTexture()
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->BlendRenderWithTwoTexture();
}
void CGrannyLODController::Update(float fElapsedTime, float fDistanceFromCenter, float fDistanceFromCamera)
{
UpdateLODLevel(fDistanceFromCenter, fDistanceFromCamera);
UpdateTime(fElapsedTime);
}
void CGrannyLODController::UpdateLODLevel(float fDistanceFromCenter, float fDistanceFromCamera)
{
if (m_que_pkModelInst.size()<=1)
return;
assert(m_pCurrentModelInstance != NULL);
if (fDistanceFromCenter > LOD_APPLY_MIN) // 중심 LOD 예외 취소
{
// 카메라부터 멀어질 수록 fLODRate가 작아진다
// 3개 LOD가 있을때.. 가장 먼게 0, 가까울 수록 숫자가 커진다
// 100fps 50fps 33fps 25fps 20fps
// 10ms 20ms 30ms 40ms 50ms
float fLODFactor = fMINMAX(0.0f, (m_fLODDistance-fDistanceFromCamera), m_fLODDistance);
if (m_fLODDistance>0.0f)
m_dwLODAniFPS = (DWORD) ((CGrannyModelInstance::ANIFPS_MAX - CGrannyModelInstance::ANIFPS_MIN) * fLODFactor / m_fLODDistance + static_cast<float>(CGrannyModelInstance::ANIFPS_MIN));
else
m_dwLODAniFPS = CGrannyModelInstance::ANIFPS_MIN;
assert(m_dwLODAniFPS > 0);
m_dwLODAniFPS /= 10;
m_dwLODAniFPS *= 10;
float fLODStep = m_fLODDistance / m_que_pkModelInst.size();
BYTE bLODLevel = BYTE(fLODFactor / fLODStep);
if (m_fLODDistance <= 5000.0f)
{
if (fDistanceFromCamera < 500.0f)
{
bLODLevel = 0;
}
else if (fDistanceFromCamera < 1500.0f)
{
bLODLevel = 1;
}
else if (fDistanceFromCamera < 2500.0f)
{
bLODLevel = 2;
}
else
{
bLODLevel = 3;
}
bLODLevel = (BYTE) (m_que_pkModelInst.size() - min(bLODLevel, m_que_pkModelInst.size()) - 1);
}
if (ms_isMinLODModeEnable)
bLODLevel=0;
SetLODLevel(bLODLevel);
if (m_pCurrentModelInstance != m_que_pkModelInst[m_bLODLevel])
{
SetCurrentModelInstance(m_que_pkModelInst[m_bLODLevel]);
}
}
else
{
m_dwLODAniFPS=CGrannyModelInstance::ANIFPS_MAX;
if (!m_que_pkModelInst.empty())
{
if (m_pCurrentModelInstance != m_que_pkModelInst.back())
{
SetCurrentModelInstance(m_que_pkModelInst.back());
}
}
}
}
void CGrannyLODController::UpdateTime(float fElapsedTime)
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->Update(m_dwLODAniFPS);
//DWORD t3=timeGetTime();
m_pCurrentModelInstance->UpdateLocalTime(fElapsedTime);
//DWORD t4=timeGetTime();
#ifdef __PERFORMANCE_CHECKER__
{
static FILE* fp=fopen("perf_lod_update.txt", "w");
if (t4-t1>3)
{
fprintf(fp, "LOD.Total %d (Time %f)\n", t4-t1, timeGetTime()/1000.0f);
fprintf(fp, "LOD.SMI %d\n", t2-t1);
fprintf(fp, "LOD.UP %d\n", t3-t2);
fprintf(fp, "LOD.UL %d\n", t4-t3);
fprintf(fp, "-------------------------------- \n");
fflush(fp);
}
fflush(fp);
}
#endif
}
void CGrannyLODController::SetCurrentModelInstance(CGrannyModelInstance * pgrnModelInstance)
{
// Copy Motion
pgrnModelInstance->CopyMotion(m_pCurrentModelInstance, true);
m_pCurrentModelInstance = pgrnModelInstance;
// Change children attaching link
RefreshAttachedModelInstance();
// Change parent attaching link
if (m_pAttachedParentModel)
{
m_pAttachedParentModel->RefreshAttachedModelInstance();
}
}
void CGrannyLODController::RefreshAttachedModelInstance()
{
if (!m_pCurrentModelInstance)
return;
for (DWORD i = 0; i < m_AttachedModelDataVector.size(); ++i)
{
TAttachingModelData & rModelData = m_AttachedModelDataVector[i];
CGrannyModelInstance * pSrcInstance = rModelData.pkLODController->GetModelInstance();
if (!pSrcInstance)
{
Tracenf("CGrannyLODController::RefreshAttachedModelInstance : m_AttachedModelDataVector[%d]->pkLODController->GetModelIntance()==NULL", i);
continue;
}
pSrcInstance->SetParentModelInstance(m_pCurrentModelInstance, rModelData.strBoneName.c_str());
}
}
void CGrannyLODController::UpdateSkeleton(const D3DXMATRIX * c_pWorldMatrix, float fElapsedTime)
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->UpdateSkeleton(c_pWorldMatrix, fElapsedTime);
}
void CGrannyLODController::DeformAll(const D3DXMATRIX * c_pWorldMatrix)
{
std::deque<CGrannyModelInstance *>::iterator i;
for (i=m_que_pkModelInst.begin(); i!=m_que_pkModelInst.end(); ++i)
{
CGrannyModelInstance* pkModelInst=(*i);
pkModelInst->Deform(c_pWorldMatrix);
}
}
void CGrannyLODController::DeformNoSkin(const D3DXMATRIX * c_pWorldMatrix)
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->DeformNoSkin(c_pWorldMatrix);
}
void CGrannyLODController::Deform(const D3DXMATRIX * c_pWorldMatrix)
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->Deform(c_pWorldMatrix);
}
void CGrannyLODController::RenderToShadowMap()
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->RenderWithoutTexture();
}
void CGrannyLODController::RenderShadow()
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->RenderWithOneTexture();
}
void CGrannyLODController::ReloadTexture()
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->ReloadTexture();
}
void CGrannyLODController::GetBoundBox(D3DXVECTOR3 * vtMin, D3DXVECTOR3 * vtMax)
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->GetBoundBox(vtMin, vtMax);
}
bool CGrannyLODController::Intersect(const D3DXMATRIX * c_pMatrix, float * u, float * v, float * t)
{
if (!m_pCurrentModelInstance)
return false;
return m_pCurrentModelInstance->Intersect(c_pMatrix, u, v, t);
}
void CGrannyLODController::SetLocalTime(float fLocalTime)
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->SetLocalTime(fLocalTime);
}
void CGrannyLODController::ResetLocalTime()
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->ResetLocalTime();
}
void CGrannyLODController::SetMotionPointer(const CGrannyMotion * c_pMotion, float fBlendTime, int iLoopCount, float speedRatio)
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->SetMotionPointer(c_pMotion, fBlendTime, iLoopCount, speedRatio);
}
void CGrannyLODController::ChangeMotionPointer(const CGrannyMotion * c_pMotion, int iLoopCount, float speedRatio)
{
assert(m_pCurrentModelInstance != NULL);
m_pCurrentModelInstance->ChangeMotionPointer(c_pMotion, iLoopCount, speedRatio);
}
void CGrannyLODController::SetMotionAtEnd()
{
if (m_pCurrentModelInstance)
m_pCurrentModelInstance->SetMotionAtEnd();
}
BOOL CGrannyLODController::isModelInstance()
{
if (!m_pCurrentModelInstance)
return FALSE;
return TRUE;
}
CGrannyModelInstance * CGrannyLODController::GetModelInstance()
{
return m_pCurrentModelInstance;
}
+560
View File
@@ -0,0 +1,560 @@
#include "StdAfx.h"
#include "Material.h"
#include "Mesh.h"
#include "../EterBase/Filename.h"
#include "../EterLib/ResourceManager.h"
#include "../EterLib/StateManager.h"
#include "../EterLib/GrpScreen.h"
CGraphicImageInstance CGrannyMaterial::ms_akSphereMapInstance[SPHEREMAP_NUM];
D3DXVECTOR3 CGrannyMaterial::ms_v3SpecularTrans(0.0f, 0.0f, 0.0f);
D3DXMATRIX CGrannyMaterial::ms_matSpecular;
D3DXCOLOR g_fSpecularColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f);
void CGrannyMaterial::TranslateSpecularMatrix(float fAddX, float fAddY, float fAddZ)
{
static float SPECULAR_TRANSLATE_MAX = 1000000.0f;
ms_v3SpecularTrans.x+=fAddX;
ms_v3SpecularTrans.y+=fAddY;
ms_v3SpecularTrans.z+=fAddZ;
if (ms_v3SpecularTrans.x>=SPECULAR_TRANSLATE_MAX)
ms_v3SpecularTrans.x=0.0f;
if (ms_v3SpecularTrans.y>=SPECULAR_TRANSLATE_MAX)
ms_v3SpecularTrans.y=0.0f;
if (ms_v3SpecularTrans.z>=SPECULAR_TRANSLATE_MAX)
ms_v3SpecularTrans.z=0.0f;
D3DXMatrixTranslation(&ms_matSpecular,
ms_v3SpecularTrans.x,
ms_v3SpecularTrans.y,
ms_v3SpecularTrans.z
);
}
void CGrannyMaterial::ApplyRenderState()
{
assert(m_pfnApplyRenderState!=NULL && "CGrannyMaterial::SaveRenderState");
(this->*m_pfnApplyRenderState)();
}
void CGrannyMaterial::RestoreRenderState()
{
assert(m_pfnRestoreRenderState!=NULL && "CGrannyMaterial::RestoreRenderState");
(this->*m_pfnRestoreRenderState)();
}
void CGrannyMaterial::Copy(CGrannyMaterial& rkMtrl)
{
m_pgrnMaterial = rkMtrl.m_pgrnMaterial;
m_roImage[0] = rkMtrl.m_roImage[0];
m_roImage[1] = rkMtrl.m_roImage[1];
m_eType = rkMtrl.m_eType;
}
CGrannyMaterial::CGrannyMaterial()
{
m_bTwoSideRender = false;
m_dwLastCullRenderStateForTwoSideRendering = D3DCULL_CW;
Initialize();
}
CGrannyMaterial::~CGrannyMaterial()
{
}
CGrannyMaterial::EType CGrannyMaterial::GetType() const
{
return m_eType;
}
void CGrannyMaterial::SetImagePointer(int iStage, CGraphicImage* pImage)
{
assert(iStage<2 && "CGrannyMaterial::SetImagePointer");
m_roImage[iStage]=pImage;
}
bool CGrannyMaterial::IsIn(const char* c_szImageName, int* piStage)
{
std::string strImageName = c_szImageName;
CFileNameHelper::StringPath(strImageName);
granny_texture * pgrnDiffuseTexture = GrannyGetMaterialTextureByType(m_pgrnMaterial, GrannyDiffuseColorTexture);
if (pgrnDiffuseTexture)
{
std::string strDiffuseFileName = pgrnDiffuseTexture->FromFileName;
CFileNameHelper::StringPath(strDiffuseFileName);
if (strDiffuseFileName == strImageName)
{
*piStage=0;
return true;
}
}
granny_texture * pgrnOpacityTexture = GrannyGetMaterialTextureByType(m_pgrnMaterial, GrannyOpacityTexture);
if (pgrnOpacityTexture)
{
std::string strOpacityFileName = pgrnOpacityTexture->FromFileName;
CFileNameHelper::StringPath(strOpacityFileName);
if (strOpacityFileName == strImageName)
{
*piStage=1;
return true;
}
}
return false;
}
void CGrannyMaterial::SetSpecularInfo(BOOL bFlag, float fPower, BYTE uSphereMapIndex)
{
m_fSpecularPower = fPower;
m_bSphereMapIndex = uSphereMapIndex;
m_bSpecularEnable = bFlag;
if (bFlag)
{
m_pfnApplyRenderState = &CGrannyMaterial::__ApplySpecularRenderState;
m_pfnRestoreRenderState = &CGrannyMaterial::__RestoreSpecularRenderState;
}
else
{
m_pfnApplyRenderState = &CGrannyMaterial::__ApplyDiffuseRenderState;
m_pfnRestoreRenderState = &CGrannyMaterial::__RestoreDiffuseRenderState;
}
}
bool CGrannyMaterial::IsEqual(granny_material* pgrnMaterial) const
{
if (m_pgrnMaterial==pgrnMaterial)
return true;
return false;
}
LPDIRECT3DTEXTURE8 CGrannyMaterial::GetD3DTexture(int iStage) const
{
const CGraphicImage::TRef & ratImage = m_roImage[iStage];
if (ratImage.IsNull())
return NULL;
CGraphicImage * pImage = ratImage.GetPointer();
const CGraphicTexture * pTexture = pImage->GetTexturePointer();
return pTexture->GetD3DTexture();
}
CGraphicImage * CGrannyMaterial::GetImagePointer(int iStage) const
{
const CGraphicImage::TRef & ratImage = m_roImage[iStage];
if (ratImage.IsNull())
return NULL;
CGraphicImage * pImage = ratImage.GetPointer();
return pImage;
}
const CGraphicTexture* CGrannyMaterial::GetDiffuseTexture() const
{
if (m_roImage[0].IsNull())
return NULL;
return m_roImage[0].GetPointer()->GetTexturePointer();
}
const CGraphicTexture* CGrannyMaterial::GetOpacityTexture() const
{
if (m_roImage[1].IsNull())
return NULL;
return m_roImage[1].GetPointer()->GetTexturePointer();
}
BOOL CGrannyMaterial::__IsSpecularEnable() const
{
return m_bSpecularEnable;
}
float CGrannyMaterial::__GetSpecularPower() const
{
return m_fSpecularPower;
}
extern const std::string& GetModelLocalPath();
CGraphicImage* CGrannyMaterial::__GetImagePointer(const char* fileName)
{
assert(*fileName != '\0');
CResourceManager& rkResMgr = CResourceManager::Instance();
// SUPPORT_LOCAL_TEXTURE
int fileName_len = strlen(fileName);
if (fileName_len > 2 && fileName[1] != ':')
{
char localFileName[256];
const std::string& modelLocalPath = GetModelLocalPath();
int localFileName_len = modelLocalPath.length() + 1 + fileName_len;
if (localFileName_len < sizeof(localFileName) - 1)
{
_snprintf(localFileName, sizeof(localFileName), "%s%s", GetModelLocalPath().c_str(), fileName);
CResource* pResource = rkResMgr.GetResourcePointer(localFileName);
return static_cast<CGraphicImage*>(pResource);
}
}
// END_OF_SUPPORT_LOCAL_TEXTURE
CResource* pResource = rkResMgr.GetResourcePointer(fileName);
return static_cast<CGraphicImage*>(pResource);
}
bool CGrannyMaterial::CreateFromGrannyMaterialPointer(granny_material * pgrnMaterial)
{
m_pgrnMaterial = pgrnMaterial;
granny_texture * pgrnDiffuseTexture = NULL;
granny_texture * pgrnOpacityTexture = NULL;
if (pgrnMaterial)
{
if (pgrnMaterial->MapCount > 1 && !_strnicmp(pgrnMaterial->Name, "Blend", 5))
{
pgrnDiffuseTexture = GrannyGetMaterialTextureByType(pgrnMaterial->Maps[0].Material, GrannyDiffuseColorTexture);
pgrnOpacityTexture = GrannyGetMaterialTextureByType(pgrnMaterial->Maps[1].Material, GrannyDiffuseColorTexture);
}
else
{
pgrnDiffuseTexture = GrannyGetMaterialTextureByType(m_pgrnMaterial, GrannyDiffuseColorTexture);
pgrnOpacityTexture = GrannyGetMaterialTextureByType(m_pgrnMaterial, GrannyOpacityTexture);
}
// Two-Side 렌더링이 필요한 지 검사
{
granny_int32 twoSided = 0;
granny_data_type_definition TwoSidedFieldType[] =
{
{GrannyInt32Member, "Two-sided"},
{GrannyEndMember},
};
granny_variant twoSideResult;
if (GrannyFindMatchingMember(pgrnMaterial->ExtendedData.Type, pgrnMaterial->ExtendedData.Object, "Two-sided", &twoSideResult) && NULL != twoSideResult.Type)
GrannyConvertSingleObject(twoSideResult.Type, twoSideResult.Object, TwoSidedFieldType, &twoSided, NULL);
m_bTwoSideRender = 1 == twoSided;
}
}
if (pgrnDiffuseTexture)
m_roImage[0].SetPointer(__GetImagePointer(pgrnDiffuseTexture->FromFileName));
if (pgrnOpacityTexture)
m_roImage[1].SetPointer(__GetImagePointer(pgrnOpacityTexture->FromFileName));
// 오퍼시티가 있으면 블렌딩 메쉬
if (!m_roImage[1].IsNull())
m_eType = TYPE_BLEND_PNT;
else
m_eType = TYPE_DIFFUSE_PNT;
return true;
}
void CGrannyMaterial::Initialize()
{
m_roImage[0] = NULL;
m_roImage[1] = NULL;
SetSpecularInfo(FALSE, 0.0f, 0);
}
void CGrannyMaterial::__ApplyDiffuseRenderState()
{
STATEMANAGER.SetTexture(0, GetD3DTexture(0));
if (m_bTwoSideRender)
{
// -_-렌더링 프로세스가 좀 구려서... Save & Restore 하면 순서때문에 좀 꼬인다. 귀찮으니 Save & Restore 대신 따로 저장해 둠.
m_dwLastCullRenderStateForTwoSideRendering = STATEMANAGER.GetRenderState(D3DRS_CULLMODE);
STATEMANAGER.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
}
}
void CGrannyMaterial::__RestoreDiffuseRenderState()
{
if (m_bTwoSideRender)
{
STATEMANAGER.SetRenderState(D3DRS_CULLMODE, m_dwLastCullRenderStateForTwoSideRendering);
}
}
void CGrannyMaterial::__ApplySpecularRenderState()
{
if (TRUE == STATEMANAGER.GetRenderState(D3DRS_ALPHABLENDENABLE))
{
__ApplyDiffuseRenderState();
return;
}
CGraphicTexture* pkTexture=ms_akSphereMapInstance[m_bSphereMapIndex].GetTexturePointer();
STATEMANAGER.SetTexture(0, GetD3DTexture(0));
if (pkTexture)
STATEMANAGER.SetTexture(1, pkTexture->GetD3DTexture());
else
STATEMANAGER.SetTexture(1, NULL);
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, D3DXCOLOR(g_fSpecularColor.r, g_fSpecularColor.g, g_fSpecularColor.b, __GetSpecularPower()));
STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &ms_matSpecular);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
STATEMANAGER.SaveTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
}
void CGrannyMaterial::__RestoreSpecularRenderState()
{
if (TRUE == STATEMANAGER.GetRenderState(D3DRS_ALPHABLENDENABLE))
{
__RestoreDiffuseRenderState();
return;
}
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSU);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_ADDRESSV);
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_TEXCOORDINDEX);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
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);
}
void CGrannyMaterial::CreateSphereMap(UINT uMapIndex, const char* c_szSphereMapImageFileName)
{
CResourceManager& rkResMgr = CResourceManager::Instance();
CGraphicImage * pImage = (CGraphicImage *)rkResMgr.GetResourcePointer(c_szSphereMapImageFileName);
ms_akSphereMapInstance[uMapIndex].SetImagePointer(pImage);
}
void CGrannyMaterial::DestroySphereMap()
{
for (UINT uMapIndex=0; uMapIndex<SPHEREMAP_NUM; ++uMapIndex)
ms_akSphereMapInstance[uMapIndex].Destroy();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CGrannyMaterialPalette::CGrannyMaterialPalette()
{
}
CGrannyMaterialPalette::~CGrannyMaterialPalette()
{
Clear();
}
void CGrannyMaterialPalette::Copy(const CGrannyMaterialPalette& rkMtrlPalSrc)
{
m_mtrlVector=rkMtrlPalSrc.m_mtrlVector;
}
void CGrannyMaterialPalette::Clear()
{
m_mtrlVector.clear();
}
CGrannyMaterial& CGrannyMaterialPalette::GetMaterialRef(DWORD mtrlIndex)
{
assert(mtrlIndex<m_mtrlVector.size());
return *m_mtrlVector[mtrlIndex].GetPointer();
}
void CGrannyMaterialPalette::SetMaterialImagePointer(const char* c_szImageName, CGraphicImage* pImage)
{
DWORD size=m_mtrlVector.size();
DWORD i;
for (i=0; i<size; ++i)
{
CGrannyMaterial::TRef& roMtrl=m_mtrlVector[i];
int iStage;
if (roMtrl->IsIn(c_szImageName, &iStage))
{
CGrannyMaterial* pkNewMtrl=new CGrannyMaterial;
pkNewMtrl->Copy(*roMtrl.GetPointer());
pkNewMtrl->SetImagePointer(iStage, pImage);
roMtrl=pkNewMtrl;
return;
}
}
}
void CGrannyMaterialPalette::SetMaterialData(const char* c_szMtrlName, const SMaterialData& c_rkMaterialData)
{
if (c_szMtrlName)
{
std::vector<CGrannyMaterial::TRef>::iterator i;
for (i=m_mtrlVector.begin(); i!=m_mtrlVector.end(); ++i)
{
CGrannyMaterial::TRef& roMtrl=*i;
int iStage;
if (roMtrl->IsIn(c_szMtrlName, &iStage))
{
CGrannyMaterial* pkNewMtrl=new CGrannyMaterial;
pkNewMtrl->Copy(*roMtrl.GetPointer());
pkNewMtrl->SetImagePointer(iStage, c_rkMaterialData.pImage);
pkNewMtrl->SetSpecularInfo(c_rkMaterialData.isSpecularEnable, c_rkMaterialData.fSpecularPower, c_rkMaterialData.bSphereMapIndex);
roMtrl=pkNewMtrl;
return;
}
}
}
else
{
std::vector<CGrannyMaterial::TRef>::iterator i;
for (i=m_mtrlVector.begin(); i!=m_mtrlVector.end(); ++i)
{
CGrannyMaterial::TRef& roMtrl=*i;
roMtrl->SetSpecularInfo(c_rkMaterialData.isSpecularEnable, c_rkMaterialData.fSpecularPower, c_rkMaterialData.bSphereMapIndex);
}
}
}
void CGrannyMaterialPalette::SetSpecularInfo(const char* c_szMtrlName, BOOL bEnable, float fPower)
{
DWORD size=m_mtrlVector.size();
DWORD i;
if (c_szMtrlName)
{
for (i=0; i<size; ++i)
{
CGrannyMaterial::TRef& roMtrl=m_mtrlVector[i];
int iStage;
if (roMtrl->IsIn(c_szMtrlName, &iStage))
{
roMtrl->SetSpecularInfo(bEnable, fPower, 0);
return;
}
}
}
else
{
for (i=0; i<size; ++i)
{
CGrannyMaterial::TRef& roMtrl=m_mtrlVector[i];
roMtrl->SetSpecularInfo(bEnable, fPower, 0);
}
}
}
DWORD CGrannyMaterialPalette::RegisterMaterial(granny_material* pgrnMaterial)
{
DWORD size=m_mtrlVector.size();
DWORD i;
for (i=0; i<size; ++i)
{
CGrannyMaterial::TRef& roMtrl=m_mtrlVector[i];
if (roMtrl->IsEqual(pgrnMaterial))
return i;
}
CGrannyMaterial* pkNewMtrl=new CGrannyMaterial;
pkNewMtrl->CreateFromGrannyMaterialPointer(pgrnMaterial);
m_mtrlVector.push_back(pkNewMtrl);
return size;
}
DWORD CGrannyMaterialPalette::GetMaterialCount() const
{
return m_mtrlVector.size();
}
/*
void CActorInstance::BeginSpecularRender()
{
// NOTE - Blending해서 찍는 부분은 Specular를 적용시키지 않는다 - [levites]
STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
STATEMANAGER.SetRenderState(D3DRS_TEXTUREFACTOR, D3DXCOLOR(1.0f, 1.0f, 1.0f, m_AddColor.r));
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_TFACTOR);
STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
// STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
// STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
// STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
// STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
//
// STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATEALPHA_ADDCOLOR);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
// D3DXMATRIX texMatrix;
// GetSphereMatrix(&texMatrix);
// STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &texMatrix);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
// Type 1
// STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
// // Type 2
// STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACENORMAL);
}
void CActorInstance::EndSpecularRender()
{
// STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
// STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
*/
+311
View File
@@ -0,0 +1,311 @@
#include "StdAfx.h"
#include "Mesh.h"
#include "Model.h"
#include "Material.h"
granny_data_type_definition GrannyPNT3322VertexType[5] =
{
{GrannyReal32Member, GrannyVertexPositionName, 0, 3},
{GrannyReal32Member, GrannyVertexNormalName, 0, 3},
{GrannyReal32Member, GrannyVertexTextureCoordinatesName"0", 0, 2},
{GrannyReal32Member, GrannyVertexTextureCoordinatesName"1", 0, 2},
{GrannyEndMember}
};
void CGrannyMesh::LoadIndices(void * dstBaseIndices)
{
const granny_mesh * pgrnMesh = GetGrannyMeshPointer();
TIndex * dstIndices = ((TIndex *)dstBaseIndices) + m_idxBasePos;
GrannyCopyMeshIndices(pgrnMesh, sizeof(TIndex), dstIndices);
}
void CGrannyMesh::LoadPNTVertices(void * dstBaseVertices)
{
const granny_mesh * pgrnMesh = GetGrannyMeshPointer();
if (!GrannyMeshIsRigid(pgrnMesh))
return;
TPNTVertex * dstVertices = ((TPNTVertex *)dstBaseVertices) + m_vtxBasePos;
GrannyCopyMeshVertices(pgrnMesh, m_pgrnMeshType, dstVertices);
}
void CGrannyMesh::NEW_LoadVertices(void * dstBaseVertices)
{
const granny_mesh * pgrnMesh = GetGrannyMeshPointer();
if (!GrannyMeshIsRigid(pgrnMesh))
return;
TPNTVertex * dstVertices = ((TPNTVertex *)dstBaseVertices) + m_vtxBasePos;
GrannyCopyMeshVertices(pgrnMesh, m_pgrnMeshType, dstVertices);
}
void CGrannyMesh::DeformPNTVertices(void * dstBaseVertices, D3DXMATRIX * boneMatrices, granny_mesh_binding* pgrnMeshBinding) const
{
assert(dstBaseVertices != NULL);
assert(boneMatrices != NULL);
assert(m_pgrnMeshDeformer != NULL);
const granny_mesh * pgrnMesh = GetGrannyMeshPointer();
TPNTVertex * srcVertices = (TPNTVertex *) GrannyGetMeshVertices(pgrnMesh);
TPNTVertex * dstVertices = ((TPNTVertex *) dstBaseVertices) + m_vtxBasePos;
int vtxCount = GrannyGetMeshVertexCount(pgrnMesh);
// WORK
int * boneIndices = (int*)GrannyGetMeshBindingToBoneIndices(pgrnMeshBinding);
// END_OF_WORK
GrannyDeformVertices(
m_pgrnMeshDeformer,
boneIndices,
(float *)boneMatrices,
vtxCount,
srcVertices,
dstVertices);
}
bool CGrannyMesh::CanDeformPNTVertices() const
{
return m_canDeformPNTVertex;
}
const granny_mesh * CGrannyMesh::GetGrannyMeshPointer() const
{
return m_pgrnMesh;
}
const CGrannyMesh::TTriGroupNode * CGrannyMesh::GetTriGroupNodeList(CGrannyMaterial::EType eMtrlType) const
{
return m_triGroupNodeLists[eMtrlType];
}
int CGrannyMesh::GetVertexCount() const
{
assert(m_pgrnMesh!=NULL);
return GrannyGetMeshVertexCount(m_pgrnMesh);
}
int CGrannyMesh::GetVertexBasePosition() const
{
return m_vtxBasePos;
}
int CGrannyMesh::GetIndexBasePosition() const
{
return m_idxBasePos;
}
// WORK
int * CGrannyMesh::GetDefaultBoneIndices() const
{
return (int*)GrannyGetMeshBindingToBoneIndices(m_pgrnMeshBindingTemp);
}
// END_OF_WORK
bool CGrannyMesh::IsEmpty() const
{
if (m_pgrnMesh)
return false;
return true;
}
bool CGrannyMesh::CreateFromGrannyMeshPointer(granny_skeleton * pgrnSkeleton, granny_mesh * pgrnMesh, int vtxBasePos, int idxBasePos, CGrannyMaterialPalette& rkMtrlPal)
{
assert(IsEmpty());
m_pgrnMesh = pgrnMesh;
m_vtxBasePos = vtxBasePos;
m_idxBasePos = idxBasePos;
if (m_pgrnMesh->BoneBindingCount < 0)
return true;
// WORK
m_pgrnMeshBindingTemp = GrannyNewMeshBinding(m_pgrnMesh, pgrnSkeleton, pgrnSkeleton);
// END_OF_WORK
if (!GrannyMeshIsRigid(m_pgrnMesh))
{
m_canDeformPNTVertex = true;
granny_data_type_definition * pgrnInputType = GrannyGetMeshVertexType(m_pgrnMesh);
granny_data_type_definition * pgrnOutputType = m_pgrnMeshType;
m_pgrnMeshDeformer = GrannyNewMeshDeformer(pgrnInputType, pgrnOutputType, GrannyDeformPositionNormal, GrannyAllowUncopiedTail);
assert(m_pgrnMeshDeformer != NULL && "Cannot create mesh deformer");
}
// Two Side Mesh
if (!strncmp(m_pgrnMesh->Name, "2x", 2))
m_isTwoSide = true;
if (!LoadMaterials(rkMtrlPal))
return false;
if (!LoadTriGroupNodeList(rkMtrlPal))
return false;
return true;
}
bool CGrannyMesh::LoadTriGroupNodeList(CGrannyMaterialPalette& rkMtrlPal)
{
assert(m_pgrnMesh != NULL);
assert(m_triGroupNodes == NULL);
int mtrlCount = m_pgrnMesh->MaterialBindingCount;
if (mtrlCount <= 0) // 천의 동굴 2층 크래쉬 발생
return true;
int GroupNodeCount = GrannyGetMeshTriangleGroupCount(m_pgrnMesh);
if (GroupNodeCount <= 0)
return true;
m_triGroupNodes = new TTriGroupNode[GroupNodeCount];
const granny_tri_material_group * c_pgrnTriGroups = GrannyGetMeshTriangleGroups(m_pgrnMesh);
for (int g = 0; g < GroupNodeCount; ++g)
{
const granny_tri_material_group & c_rgrnTriGroup = c_pgrnTriGroups[g];
TTriGroupNode * pTriGroupNode = m_triGroupNodes + g;
pTriGroupNode->idxPos = m_idxBasePos + c_rgrnTriGroup.TriFirst * 3;
pTriGroupNode->triCount = c_rgrnTriGroup.TriCount;
int iMtrl = c_rgrnTriGroup.MaterialIndex;
if (iMtrl < 0 || iMtrl >= mtrlCount)
{
pTriGroupNode->mtrlIndex=0;//m_mtrlIndexVector[iMtrl];
}
else
{
pTriGroupNode->mtrlIndex=m_mtrlIndexVector[iMtrl];
}
const CGrannyMaterial& rkMtrl=rkMtrlPal.GetMaterialRef(pTriGroupNode->mtrlIndex);
pTriGroupNode->pNextTriGroupNode = m_triGroupNodeLists[rkMtrl.GetType()];
m_triGroupNodeLists[rkMtrl.GetType()] = pTriGroupNode;
}
return true;
}
void CGrannyMesh::RebuildTriGroupNodeList()
{
assert(!"CGrannyMesh::RebuildTriGroupNodeList() - \277\326 \270\256\272\364\265\345\270\246 \307\317\264\302\260\241- -?");
/*
int mtrlCount = m_pgrnMesh->MaterialBindingCount;
int GroupNodeCount = GrannyGetMeshTriangleGroupCount(m_pgrnMesh);
if (GroupNodeCount <= 0)
return;
const granny_tri_material_group * c_pgrnTriGroups = GrannyGetMeshTriangleGroups(m_pgrnMesh);
for (int g = 0; g < GroupNodeCount; ++g)
{
const granny_tri_material_group& c_rgrnTriGroup = c_pgrnTriGroups[g];
TTriGroupNode * pTriGroupNode = m_triGroupNodes + g;
int iMtrl = c_rgrnTriGroup.MaterialIndex;
if (iMtrl >= 0 && iMtrl < mtrlCount)
{
CGrannyMaterial & rMtrl = m_mtrls[iMtrl];
pTriGroupNode->lpd3dTextures[0] = rMtrl.GetD3DTexture(0);
pTriGroupNode->lpd3dTextures[1] = rMtrl.GetD3DTexture(1);
}
}
*/
}
bool CGrannyMesh::LoadMaterials(CGrannyMaterialPalette& rkMtrlPal)
{
assert(m_pgrnMesh != NULL);
if (m_pgrnMesh->MaterialBindingCount <= 0)
return true;
int mtrlCount = m_pgrnMesh->MaterialBindingCount;
bool bHaveBlendThing = false;
for (int m = 0; m < mtrlCount; ++m)
{
granny_material* pgrnMaterial = m_pgrnMesh->MaterialBindings[m].Material;
DWORD mtrlIndex=rkMtrlPal.RegisterMaterial(pgrnMaterial);
m_mtrlIndexVector.push_back(mtrlIndex);
bHaveBlendThing |= rkMtrlPal.GetMaterialRef(mtrlIndex).GetType() == CGrannyMaterial::TYPE_BLEND_PNT;
}
m_bHaveBlendThing = bHaveBlendThing;
return true;
}
bool CGrannyMesh::IsTwoSide() const
{
return m_isTwoSide;
}
void CGrannyMesh::SetPNT2Mesh()
{
m_pgrnMeshType = GrannyPNT3322VertexType;
}
void CGrannyMesh::Destroy()
{
if (m_triGroupNodes)
delete [] m_triGroupNodes;
m_mtrlIndexVector.clear();
// WORK
if (m_pgrnMeshBindingTemp)
GrannyFreeMeshBinding(m_pgrnMeshBindingTemp);
// END_OF_WORK
if (m_pgrnMeshDeformer)
GrannyFreeMeshDeformer(m_pgrnMeshDeformer);
Initialize();
}
void CGrannyMesh::Initialize()
{
for (int r = 0; r < CGrannyMaterial::TYPE_MAX_NUM; ++r)
m_triGroupNodeLists[r] = NULL;
m_pgrnMeshType = GrannyPNT332VertexType;
m_pgrnMesh = NULL;
// WORK
m_pgrnMeshBindingTemp = NULL;
// END_OF_WORK
m_pgrnMeshDeformer = NULL;
m_triGroupNodes = NULL;
m_vtxBasePos = 0;
m_idxBasePos = 0;
m_canDeformPNTVertex = false;
m_isTwoSide = false;
m_bHaveBlendThing = false;
}
CGrannyMesh::CGrannyMesh()
{
Initialize();
}
CGrannyMesh::~CGrannyMesh()
{
Destroy();
}
+419
View File
@@ -0,0 +1,419 @@
#include "StdAfx.h"
#include "Model.h"
#include "Mesh.h"
const CGrannyMaterialPalette& CGrannyModel::GetMaterialPalette() const
{
return m_kMtrlPal;
}
const CGrannyModel::TMeshNode* CGrannyModel::GetMeshNodeList(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType) const
{
return m_meshNodeLists[eMeshType][eMtrlType];
}
CGrannyMesh * CGrannyModel::GetMeshPointer(int iMesh)
{
assert(CheckMeshIndex(iMesh));
assert(m_meshs != NULL);
return m_meshs + iMesh;
}
const CGrannyMesh* CGrannyModel::GetMeshPointer(int iMesh) const
{
assert(CheckMeshIndex(iMesh));
assert(m_meshs != NULL);
return m_meshs + iMesh;
}
bool CGrannyModel::CanDeformPNTVertices() const
{
return m_canDeformPNVertices;
}
void CGrannyModel::DeformPNTVertices(void * dstBaseVertices, D3DXMATRIX * boneMatrices, const std::vector<granny_mesh_binding*>& c_rvct_pgrnMeshBinding) const
{
int meshCount = GetMeshCount();
for (int iMesh = 0; iMesh < meshCount; ++iMesh)
{
assert(iMesh < c_rvct_pgrnMeshBinding.size());
CGrannyMesh & rMesh = m_meshs[iMesh];
if (rMesh.CanDeformPNTVertices())
rMesh.DeformPNTVertices(dstBaseVertices, boneMatrices, c_rvct_pgrnMeshBinding[iMesh]);
}
}
int CGrannyModel::GetRigidVertexCount() const
{
return m_rigidVtxCount;
}
int CGrannyModel::GetDeformVertexCount() const
{
return m_deformVtxCount;
}
int CGrannyModel::GetVertexCount() const
{
return m_vtxCount;
}
int CGrannyModel::GetMeshCount() const
{
return m_pgrnModel ? m_pgrnModel->MeshBindingCount : 0;
}
granny_model* CGrannyModel::GetGrannyModelPointer()
{
return m_pgrnModel;
}
LPDIRECT3DINDEXBUFFER8 CGrannyModel::GetD3DIndexBuffer() const
{
return m_idxBuf.GetD3DIndexBuffer();
}
LPDIRECT3DVERTEXBUFFER8 CGrannyModel::GetPNTD3DVertexBuffer() const
{
return m_pntVtxBuf.GetD3DVertexBuffer();
}
bool CGrannyModel::LockVertices(void** indicies, void** vertices) const
{
if (!m_idxBuf.Lock(indicies))
return false;
if (!m_pntVtxBuf.Lock(vertices))
{
m_idxBuf.Unlock();
return false;
}
return true;
}
void CGrannyModel::UnlockVertices() const
{
m_idxBuf.Unlock();
m_pntVtxBuf.Unlock();
}
bool CGrannyModel::LoadPNTVertices()
{
if (m_rigidVtxCount <= 0)
return true;
assert(m_meshs != NULL);
if (!m_pntVtxBuf.Create(m_rigidVtxCount, m_dwFvF, D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED))
return false;
void* vertices;
if (!m_pntVtxBuf.Lock(&vertices))
return false;
for (int m = 0; m < m_pgrnModel->MeshBindingCount; ++m)
{
CGrannyMesh& rMesh = m_meshs[m];
rMesh.LoadPNTVertices(vertices);
}
m_pntVtxBuf.Unlock();
return true;
}
bool CGrannyModel::LoadIndices()
{
//assert(m_idxCount > 0);
if (m_idxCount <= 0)
return true;
if (!m_idxBuf.Create(m_idxCount, D3DFMT_INDEX16))
return false;
void * indices;
if (!m_idxBuf.Lock((void**)&indices))
return false;
for (int m = 0; m < m_pgrnModel->MeshBindingCount; ++m)
{
CGrannyMesh& rMesh = m_meshs[m];
rMesh.LoadIndices(indices);
}
m_idxBuf.Unlock();
return true;
}
bool CGrannyModel::LoadMeshs()
{
assert(m_meshs == NULL);
assert(m_pgrnModel != NULL);
if (m_pgrnModel->MeshBindingCount <= 0) // 메쉬가 없는 모델
return true;
granny_skeleton * pgrnSkeleton = m_pgrnModel->Skeleton;
int vtxRigidPos = 0;
int vtxDeformPos = 0;
int vtxPos = 0;
int idxPos = 0;
int diffusePNTMeshNodeCount = 0;
int blendPNTMeshNodeCount = 0;
int blendPNT2MeshNodeCount = 0;
int meshCount = GetMeshCount();
m_meshs = new CGrannyMesh[meshCount];
m_dwFvF = 0;
for (int m = 0; m < meshCount; ++m)
{
CGrannyMesh& rMesh = m_meshs[m];
granny_mesh* pgrnMesh = m_pgrnModel->MeshBindings[m].Mesh;
if (GrannyMeshIsRigid(pgrnMesh))
{
if (!rMesh.CreateFromGrannyMeshPointer(pgrnSkeleton, pgrnMesh, vtxRigidPos, idxPos, m_kMtrlPal))
return false;
vtxRigidPos += GrannyGetMeshVertexCount(pgrnMesh);
}
else
{
if (!rMesh.CreateFromGrannyMeshPointer(pgrnSkeleton, pgrnMesh, vtxDeformPos, idxPos, m_kMtrlPal))
return false;
vtxDeformPos += GrannyGetMeshVertexCount(pgrnMesh);
m_canDeformPNVertices |= rMesh.CanDeformPNTVertices();
}
m_bHaveBlendThing |= rMesh.HaveBlendThing();
granny_int32x grni32xTypeCount = GrannyGetTotalTypeSize(pgrnMesh->PrimaryVertexData->VertexType) / 32;
int i = 0;
while (i < grni32xTypeCount)
{
if (NULL == pgrnMesh->PrimaryVertexData->VertexType[i].Name || 0 == strlen(pgrnMesh->PrimaryVertexData->VertexType[i].Name))
{
++i;
continue;
}
if ( 0 == strcmp(pgrnMesh->PrimaryVertexData->VertexType[i].Name, GrannyVertexPositionName) )
m_dwFvF |= D3DFVF_XYZ;
else if ( 0 == strcmp(pgrnMesh->PrimaryVertexData->VertexType[i].Name, GrannyVertexNormalName) )
m_dwFvF |= D3DFVF_NORMAL;
else if ( 0 == strcmp(pgrnMesh->PrimaryVertexData->VertexType[i].Name, GrannyVertexTextureCoordinatesName"0") )
m_dwFvF |= D3DFVF_TEX1;
else if ( 0 == strcmp(pgrnMesh->PrimaryVertexData->VertexType[i].Name, GrannyVertexTextureCoordinatesName"1") )
m_dwFvF |= D3DFVF_TEX2;
++i;
}
vtxPos += GrannyGetMeshVertexCount(pgrnMesh);
idxPos += GrannyGetMeshIndexCount(pgrnMesh);
if (rMesh.GetTriGroupNodeList(CGrannyMaterial::TYPE_DIFFUSE_PNT))
++diffusePNTMeshNodeCount;
if (rMesh.GetTriGroupNodeList(CGrannyMaterial::TYPE_BLEND_PNT))
++blendPNTMeshNodeCount;
}
m_meshNodeCapacity = diffusePNTMeshNodeCount + blendPNTMeshNodeCount + blendPNT2MeshNodeCount;
m_meshNodes = new TMeshNode[m_meshNodeCapacity];
for (int n = 0; n < meshCount; ++n)
{
CGrannyMesh& rMesh = m_meshs[n];
granny_mesh* pgrnMesh = m_pgrnModel->MeshBindings[n].Mesh;
CGrannyMesh::EType eMeshType = GrannyMeshIsRigid(pgrnMesh) ? CGrannyMesh::TYPE_RIGID : CGrannyMesh::TYPE_DEFORM;
if (rMesh.GetTriGroupNodeList(CGrannyMaterial::TYPE_DIFFUSE_PNT))
AppendMeshNode(eMeshType, CGrannyMaterial::TYPE_DIFFUSE_PNT, n);
if (rMesh.GetTriGroupNodeList(CGrannyMaterial::TYPE_BLEND_PNT))
AppendMeshNode(eMeshType, CGrannyMaterial::TYPE_BLEND_PNT, n);
}
// For Dungeon Block
if ((D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1|D3DFVF_TEX2) == m_dwFvF)
{
for (int n = 0; n < meshCount; ++n)
{
CGrannyMesh& rMesh = m_meshs[n];
rMesh.SetPNT2Mesh();
}
}
m_rigidVtxCount = vtxRigidPos;
m_deformVtxCount = vtxDeformPos;
m_vtxCount = vtxPos;
m_idxCount = idxPos;
return true;
}
BOOL CGrannyModel::CheckMeshIndex(int iIndex) const
{
if (iIndex < 0)
return FALSE;
if (iIndex >= m_meshNodeSize)
return FALSE;
return TRUE;
}
void CGrannyModel::AppendMeshNode(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType, int iMesh)
{
assert(m_meshNodeSize < m_meshNodeCapacity);
TMeshNode& rMeshNode = m_meshNodes[m_meshNodeSize++];
rMeshNode.iMesh = iMesh;
rMeshNode.pMesh = m_meshs + iMesh;
rMeshNode.pNextMeshNode = m_meshNodeLists[eMeshType][eMtrlType];
m_meshNodeLists[eMeshType][eMtrlType] = &rMeshNode;
}
bool CGrannyModel::CreateFromGrannyModelPointer(granny_model* pgrnModel)
{
assert(IsEmpty());
m_pgrnModel = pgrnModel;
if (!LoadMeshs())
return false;
if (!__LoadVertices())
return false;
if (!LoadIndices())
return false;
AddReference();
return true;
}
int CGrannyModel::GetIdxCount()
{
return m_idxCount;
}
bool CGrannyModel::CreateDeviceObjects()
{
if (m_rigidVtxCount > 0)
if (!m_pntVtxBuf.CreateDeviceObjects())
return false;
if (m_idxCount > 0)
if (!m_idxBuf.CreateDeviceObjects())
return false;
int meshCount = GetMeshCount();
for (int i = 0; i < meshCount; ++i)
{
CGrannyMesh& rMesh = m_meshs[i];
rMesh.RebuildTriGroupNodeList();
}
return true;
}
void CGrannyModel::DestroyDeviceObjects()
{
m_pntVtxBuf.DestroyDeviceObjects();
m_idxBuf.DestroyDeviceObjects();
}
bool CGrannyModel::IsEmpty() const
{
if (m_pgrnModel)
return false;
return true;
}
void CGrannyModel::Destroy()
{
m_kMtrlPal.Clear();
if (m_meshNodes)
delete [] m_meshNodes;
if (m_meshs)
delete [] m_meshs;
m_pntVtxBuf.Destroy();
m_idxBuf.Destroy();
Initialize();
}
bool CGrannyModel::__LoadVertices()
{
if (m_rigidVtxCount <= 0)
return true;
assert(m_meshs != NULL);
// assert((m_dwFvF & (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)) == m_dwFvF);
// if (!m_pntVtxBuf.Create(m_rigidVtxCount, D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1, D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED))
if (!m_pntVtxBuf.Create(m_rigidVtxCount, m_dwFvF, D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED))
return false;
void* vertices;
if (!m_pntVtxBuf.Lock(&vertices))
return false;
for (int m = 0; m < m_pgrnModel->MeshBindingCount; ++m)
{
CGrannyMesh& rMesh = m_meshs[m];
rMesh.NEW_LoadVertices(vertices);
}
m_pntVtxBuf.Unlock();
return true;
}
void CGrannyModel::Initialize()
{
memset(m_meshNodeLists, 0, sizeof(m_meshNodeLists));
m_pgrnModel = NULL;
m_meshs = NULL;
m_meshNodes = NULL;
m_meshNodeSize = 0;
m_meshNodeCapacity = 0;
m_rigidVtxCount = 0;
m_deformVtxCount = 0;
m_vtxCount = 0;
m_idxCount = 0;
m_canDeformPNVertices = false;
m_dwFvF = 0;
m_bHaveBlendThing = false;
}
CGrannyModel::CGrannyModel()
{
Initialize();
}
CGrannyModel::~CGrannyModel()
{
Destroy();
}
@@ -0,0 +1,140 @@
#include "StdAfx.h"
#include "ModelInstance.h"
#include "Model.h"
#include "../EterLib/ResourceManager.h"
CGrannyModel* CGrannyModelInstance::GetModel()
{
return m_pModel;
}
void CGrannyModelInstance::SetMaterialImagePointer(const char* c_szImageName, CGraphicImage* pImage)
{
m_kMtrlPal.SetMaterialImagePointer(c_szImageName, pImage);
}
void CGrannyModelInstance::SetMaterialData(const char* c_szImageName, const SMaterialData& c_rkMaterialData)
{
m_kMtrlPal.SetMaterialData(c_szImageName, c_rkMaterialData);
}
void CGrannyModelInstance::SetSpecularInfo(const char* c_szMtrlName, BOOL bEnable, float fPower)
{
m_kMtrlPal.SetSpecularInfo(c_szMtrlName, bEnable, fPower);
}
void CGrannyModelInstance::SetLocalTime(float fLocalTime)
{
m_fLocalTime = fLocalTime;
}
int CGrannyModelInstance::ResetLocalTime()
{
m_fLocalTime = 0.0f;
return 0;
}
float CGrannyModelInstance::GetLocalTime()
{
return m_fLocalTime;
}
void CGrannyModelInstance::SetParentModelInstance(const CGrannyModelInstance* c_pParentModelInstance, const char * c_szBoneName)
{
int iBoneIndex;
if (!c_pParentModelInstance->GetBoneIndexByName(c_szBoneName, &iBoneIndex))
return;
SetParentModelInstance(c_pParentModelInstance, iBoneIndex);
}
void CGrannyModelInstance::SetParentModelInstance(const CGrannyModelInstance* c_pParentModelInstance, int iBone)
{
mc_pParentInstance = c_pParentModelInstance;
m_iParentBoneIndex = iBone;
}
bool CGrannyModelInstance::IsEmpty()
{
if (m_pModel)
{
// NO_MESH_BUG_FIX
if (!m_meshMatrices)
return true;
// END_OF_NO_MESH_BUG_FIX
return false;
}
return true;
}
bool CGrannyModelInstance::CreateDeviceObjects()
{
__CreateDynamicVertexBuffer();
return true;
}
void CGrannyModelInstance::DestroyDeviceObjects()
{
__DestroyDynamicVertexBuffer();
}
void CGrannyModelInstance::__Initialize()
{
if (m_pModel)
{
m_pModel->Release();
}
m_pModel = NULL;
mc_pParentInstance = NULL;
m_iParentBoneIndex = 0;
m_pgrnModelInstance = NULL;
// WORK
m_pgrnWorldPoseReal = NULL;
// END_OF_WORK
// TEST
// m_pgrnWorldPose = NULL;
m_ppkSkeletonInst = NULL;
// END_OF_TEST
m_meshMatrices = NULL;
m_pgrnCtrl = NULL;
m_pgrnAni = NULL;
m_dwOldUpdateFrame=0;
}
CGrannyModelInstance::CGrannyModelInstance()
{
m_pModel = NULL;
__Initialize();
}
CGrannyModelInstance::~CGrannyModelInstance()
{
Clear();
}
CDynamicPool<CGrannyModelInstance> CGrannyModelInstance::ms_kPool;
CGrannyModelInstance* CGrannyModelInstance::New()
{
return ms_kPool.Alloc();
}
void CGrannyModelInstance::Delete(CGrannyModelInstance* pkInst)
{
pkInst->Clear();
ms_kPool.Free(pkInst);
}
void CGrannyModelInstance::DestroySystem()
{
ms_kPool.Destroy();
}
@@ -0,0 +1,267 @@
#include "StdAfx.h"
#include "ModelInstance.h"
#include "Model.h"
void CGrannyModelInstance::MakeBoundBox(TBoundBox* pBoundBox,
const float* mat,
const float* OBBMin,
const float* OBBMax,
D3DXVECTOR3* vtMin,
D3DXVECTOR3* vtMax)
{
pBoundBox->sx = OBBMin[0] * mat[0] + OBBMin[1] * mat[4] + OBBMin[2] * mat[8] + mat[12];
pBoundBox->sy = OBBMin[0] * mat[1] + OBBMin[1] * mat[5] + OBBMin[2] * mat[9] + mat[13];
pBoundBox->sz = OBBMin[0] * mat[2] + OBBMin[1] * mat[6] + OBBMin[2] * mat[10] + mat[14];
pBoundBox->ex = OBBMax[0] * mat[0] + OBBMax[1] * mat[4] + OBBMax[2] * mat[8] + mat[12];
pBoundBox->ey = OBBMax[0] * mat[1] + OBBMax[1] * mat[5] + OBBMax[2] * mat[9] + mat[13];
pBoundBox->ez = OBBMax[0] * mat[2] + OBBMax[1] * mat[6] + OBBMax[2] * mat[10] + mat[14];
vtMin->x = min(vtMin->x, pBoundBox->sx);
vtMin->x = min(vtMin->x, pBoundBox->ex);
vtMin->y = min(vtMin->y, pBoundBox->sy);
vtMin->y = min(vtMin->y, pBoundBox->ey);
vtMin->z = min(vtMin->z, pBoundBox->sz);
vtMin->z = min(vtMin->z, pBoundBox->ez);
vtMax->x = max(vtMax->x, pBoundBox->sx);
vtMax->x = max(vtMax->x, pBoundBox->ex);
vtMax->y = max(vtMax->y, pBoundBox->sy);
vtMax->y = max(vtMax->y, pBoundBox->ey);
vtMax->z = max(vtMax->z, pBoundBox->sz);
vtMax->z = max(vtMax->z, pBoundBox->ez);
}
bool CGrannyModelInstance::Intersect(const D3DXMATRIX * c_pMatrix,
float * /*pu*/, float * /*pv*/, float * pt)
{
if (!m_pgrnModelInstance)
return false;
float u, v, t;
bool ret = false;
*pt = 100000000.0f;
float max = 10000000.0f;
D3DXVECTOR3 vtMin, vtMax;
vtMin.x = vtMin.y = vtMin.z = max;
vtMax.x = vtMax.y = vtMax.z = -max;
static stl_stack_pool<TBoundBox> s_boundBoxPool(1024);
s_boundBoxPool.clear();
int meshCount = m_pModel->GetMeshCount();
for (int m = 0; m < meshCount; ++m)
{
//const CGrannyMesh * pMesh = m_pModel->GetMeshPointer(m);
const granny_mesh * pgrnMesh = m_pModel->GetGrannyModelPointer()->MeshBindings[m].Mesh;
for (int b = 0; b < pgrnMesh->BoneBindingCount; ++b)
{
const granny_bone_binding& rgrnBoneBinding = pgrnMesh->BoneBindings[b];
TBoundBox * pBoundBox = s_boundBoxPool.alloc();
// WORK
float * Transform = GrannyGetWorldPose4x4(__GetWorldPosePtr(), __GetMeshBoneIndices(m)[b]);
// END_OF_WORK
MakeBoundBox(pBoundBox,
Transform,
rgrnBoneBinding.OBBMin,
rgrnBoneBinding.OBBMax,
&vtMin,
&vtMax);
pBoundBox->meshIndex = m;
pBoundBox->boneIndex = b;
}
}
if (!IntersectCube(c_pMatrix,
vtMin.x, vtMin.y, vtMin.z,
vtMax.x, vtMax.y, vtMax.z,
ms_vtPickRayOrig, ms_vtPickRayDir,
&u, &v, &t))
{
return ret;
}
return true;
/*
TBoundBox* boundBoxs = s_boundBoxPool.base();
for (int i = 0; i < s_boundBoxPool.size(); ++i)
{
TBoundBox& rcurBoundBox=boundBoxs[i];
if (!IntersectBoundBox(c_pMatrix, rcurBoundBox, &u, &v, &t))
continue;
granny_matrix_4x4* pgrnMatCompositeBuffer = GrannyGetWorldPoseComposite4x4Array(m_pgrnWorldPose);
const CGrannyMesh* c_pMesh = m_pModel->GetMeshPointer(rcurBoundBox.meshIndex);
const granny_mesh* c_pgrnMesh = c_pMesh->GetGrannyMeshPointer();
if (!GrannyMeshIsRigid(c_pgrnMesh))
{
//continue;
ret = true;
}
else
{
D3DXMATRIX matMesh;
int* toBoneIndices = c_pMesh->GetBoneIndices();
D3DXMatrixMultiply(&matMesh, (D3DXMATRIX*) pgrnMatCompositeBuffer[toBoneIndices[0]], c_pMatrix);
granny_tri_material_group* pgrnTriGroups = GrannyGetMeshTriangleGroups(c_pgrnMesh);
int mtrlCount = c_pMesh->GetGrannyMeshPointer()->MaterialBindingCount;
int vtxCount = GrannyGetMeshVertexCount(c_pgrnMesh);
int groupCount = GrannyGetMeshTriangleGroupCount(c_pgrnMesh);
TIndex* modelIndices;
TPNTVertex* modelVertices;
if (m_pModel->LockVertices((void**)&modelIndices, (void**)&modelVertices))
{
TIndex* meshIndices = modelIndices + c_pMesh->GetIndexBasePosition();
TPNTVertex* meshVertices = modelVertices + c_pMesh->GetVertexBasePosition();
for (int i = 0; i < groupCount; ++i)
{
granny_tri_material_group& rgrnTriGroup = pgrnTriGroups[i];
if (rgrnTriGroup.MaterialIndex < 0 || rgrnTriGroup.MaterialIndex >= mtrlCount)
continue;
if (IntersectMesh(&matMesh,
meshVertices,
sizeof(TPNTVertex),
vtxCount,
meshIndices,
GrannyGetMeshIndexCount(c_pgrnMesh),
ms_vtPickRayOrig,
ms_vtPickRayDir,
&u, &v, &t))
{
ret = true;
break;
}
}
m_pModel->UnlockVertices();
}
}
if (ret)
{
*pu = u;
*pv = v;
*pt = -t;
if (c_szModelName)
{
if (!strncmp(c_pgrnMesh->Name, c_szModelName, strlen(c_szModelName)))
return ret;
ret = false;
continue;
}
return ret;
}
}
return (ret);
*/
}
#include "../EterBase/Timer.h"
void CGrannyModelInstance::GetBoundBox(D3DXVECTOR3* vtMin, D3DXVECTOR3* vtMax)
{
if (!m_pgrnModelInstance)
return;
TBoundBox BoundBox;
vtMin->x = vtMin->y = vtMin->z = +100000.0f;
vtMax->x = vtMax->y = vtMax->z = -100000.0f;
int meshCount = m_pModel->GetMeshCount();
for (int m = 0; m < meshCount; ++m)
{
//const CGrannyMesh* pMesh = m_pModel->GetMeshPointer(m);
const granny_mesh* pgrnMesh = m_pModel->GetGrannyModelPointer()->MeshBindings[m].Mesh;
// WORK
int* boneIndices = __GetMeshBoneIndices(m);
// END_OF_WORK
for (int b = 0; b < pgrnMesh->BoneBindingCount; ++b)
{
const granny_bone_binding& rgrnBoneBinding = pgrnMesh->BoneBindings[b];
MakeBoundBox(&BoundBox,
GrannyGetWorldPose4x4(__GetWorldPosePtr(), boneIndices[b]),
rgrnBoneBinding.OBBMin, rgrnBoneBinding.OBBMax, vtMin, vtMax);
}
}
}
bool CGrannyModelInstance::GetMeshMatrixPointer(int iMesh, const D3DXMATRIX ** c_ppMatrix) const
{
if (!m_pgrnModelInstance)
return false;
int meshCount = m_pModel->GetMeshCount();
if (meshCount <= 0)
return false;
// WORK
//const CGrannyMesh * pMesh = m_pModel->GetMeshPointer(iMesh);
*c_ppMatrix = (D3DXMATRIX *)GrannyGetWorldPose4x4(__GetWorldPosePtr(), __GetMeshBoneIndices(iMesh)[0]);
// END_OF_WORK
return true;
}
/*
void CGraphicThingInstance::DrawBoundBox()
{
if (!mc_pMeshVector)
return;
if (!m_pgrnWorldPose)
return;
D3DXVECTOR3 vtMin;
D3DXVECTOR3 vtMax;
SetDiffuseColor(0.0f, 1.0f, 0.0f);
// 캐릭터 꽉차는 바운딩 박스
//GetBoundBox(&vtMin, &vtMax);
//DrawLineCube(vtMin.x, vtMin.y, vtMin.z, vtMax.x, vtMax.y, vtMax.z);
//const CThing::TMeshVector& rmeshVector=mc_pModel->meshVector;
ms_lpd3dMatStack->LoadMatrix(&m_Matrix);
for (size_t m=0; m<mc_pMeshVector->size(); ++m)
{
const CThing::TMesh& rmesh=mc_pMeshVector->at(m);
for (int b=0; b<rmesh.pgrnMesh->BoneBindingCount; ++b)
{
granny_bone_binding& rgrnBoneBinding=rmesh.pgrnMesh->BoneBindings[b];
int* toBoneIndices=GrannyGetMeshBindingToBoneIndices(rmesh.pgrnMeshBinding);
D3DXMATRIX* pmat=(D3DXMATRIX*)GrannyGetWorldPose4x4(m_pgrnWorldPose, toBoneIndices[b]);
D3DXVec3TransformCoord(&vtMin, &D3DXVECTOR3(rgrnBoneBinding.OBBMin), pmat);
D3DXVec3TransformCoord(&vtMax, &D3DXVECTOR3(rgrnBoneBinding.OBBMax), pmat);
DrawLineCube(vtMin.x, vtMin.y, vtMin.z, vtMax.x, vtMax.y, vtMax.z);
}
}
}
*/
@@ -0,0 +1,300 @@
#include "StdAfx.h"
#include "ModelInstance.h"
#include "Model.h"
void CGrannyModelInstance::Clear()
{
m_kMtrlPal.Clear();
DestroyDeviceObjects();
// WORK
__DestroyMeshBindingVector();
// END_OF_WORK
__DestroyMeshMatrices();
__DestroyModelInstance();
__DestroyWorldPose();
__Initialize();
}
void CGrannyModelInstance::SetMainModelPointer(CGrannyModel* pModel, CGraphicVertexBuffer* pkSharedDeformableVertexBuffer)
{
SetLinkedModelPointer(pModel, pkSharedDeformableVertexBuffer, NULL);
}
void CGrannyModelInstance::SetLinkedModelPointer(CGrannyModel* pkModel, CGraphicVertexBuffer* pkSharedDeformableVertexBuffer, CGrannyModelInstance** ppkSkeletonInst)
{
Clear();
if (m_pModel)
m_pModel->Release();
m_pModel = pkModel;
m_pModel->AddReference();
if (pkSharedDeformableVertexBuffer)
__SetSharedDeformableVertexBuffer(pkSharedDeformableVertexBuffer);
else
__CreateDynamicVertexBuffer();
__CreateModelInstance();
// WORK
if (ppkSkeletonInst && *ppkSkeletonInst)
{
m_ppkSkeletonInst = ppkSkeletonInst;
__CreateWorldPose(*ppkSkeletonInst);
__CreateMeshBindingVector(*ppkSkeletonInst);
}
else
{
__CreateWorldPose(NULL);
__CreateMeshBindingVector(NULL);
}
// END_OF_WORK
__CreateMeshMatrices();
ResetLocalTime();
m_kMtrlPal.Copy(pkModel->GetMaterialPalette());
}
// WORK
granny_world_pose* CGrannyModelInstance::__GetWorldPosePtr() const
{
if (m_pgrnWorldPoseReal)
return m_pgrnWorldPoseReal;
if (m_ppkSkeletonInst && *m_ppkSkeletonInst)
return (*m_ppkSkeletonInst)->m_pgrnWorldPoseReal;
assert(m_ppkSkeletonInst!=NULL && "__GetWorldPosePtr - NO HAVE SKELETON");
return NULL;
}
int* CGrannyModelInstance::__GetMeshBoneIndices(unsigned int iMeshBinding) const
{
assert(iMeshBinding<m_vct_pgrnMeshBinding.size());
return (int*)GrannyGetMeshBindingToBoneIndices(m_vct_pgrnMeshBinding[iMeshBinding]);
}
bool CGrannyModelInstance::__CreateMeshBindingVector(CGrannyModelInstance* pkDstModelInst)
{
assert(m_vct_pgrnMeshBinding.empty());
if (!m_pModel)
return false;
granny_model* pgrnModel = m_pModel->GetGrannyModelPointer();
if (!pgrnModel)
return false;
granny_skeleton* pgrnDstSkeleton = pgrnModel->Skeleton;
if (pkDstModelInst && pkDstModelInst->m_pModel && pkDstModelInst->m_pModel->GetGrannyModelPointer())
pgrnDstSkeleton = pkDstModelInst->m_pModel->GetGrannyModelPointer()->Skeleton;
m_vct_pgrnMeshBinding.reserve(pgrnModel->MeshBindingCount);
granny_int32 iMeshBinding;
for (iMeshBinding = 0; iMeshBinding != pgrnModel->MeshBindingCount; ++iMeshBinding)
m_vct_pgrnMeshBinding.push_back(GrannyNewMeshBinding(pgrnModel->MeshBindings[iMeshBinding].Mesh, pgrnModel->Skeleton, pgrnDstSkeleton));
return true;
}
void CGrannyModelInstance::__DestroyMeshBindingVector()
{
std::for_each(m_vct_pgrnMeshBinding.begin(), m_vct_pgrnMeshBinding.end(), GrannyFreeMeshBinding);
m_vct_pgrnMeshBinding.clear();
}
// END_OF_WORK
void CGrannyModelInstance::__CreateWorldPose(CGrannyModelInstance* pkSkeletonInst)
{
assert(m_pgrnModelInstance != NULL);
assert(m_pgrnWorldPoseReal == NULL);
// WORK
if (pkSkeletonInst)
return;
// END_OF_WORK
granny_skeleton * pgrnSkeleton = GrannyGetSourceSkeleton(m_pgrnModelInstance);
// WORK
m_pgrnWorldPoseReal = GrannyNewWorldPose(pgrnSkeleton->BoneCount);
// END_OF_WORK
}
void CGrannyModelInstance::__DestroyWorldPose()
{
if (!m_pgrnWorldPoseReal)
return;
GrannyFreeWorldPose(m_pgrnWorldPoseReal);
m_pgrnWorldPoseReal = NULL;
}
void CGrannyModelInstance::__CreateModelInstance()
{
assert(m_pModel != NULL);
assert(m_pgrnModelInstance == NULL);
const granny_model * pgrnModel = m_pModel->GetGrannyModelPointer();
m_pgrnModelInstance = GrannyInstantiateModel(pgrnModel);
}
void CGrannyModelInstance::__DestroyModelInstance()
{
if (!m_pgrnModelInstance)
return;
GrannyFreeModelInstance(m_pgrnModelInstance);
m_pgrnModelInstance = NULL;
}
void CGrannyModelInstance::__CreateMeshMatrices()
{
assert(m_pModel != NULL);
if (m_pModel->GetMeshCount() <= 0) // 메쉬가 없는 (카메라 같은) 모델도 간혹 있다..
return;
int meshCount = m_pModel->GetMeshCount();
m_meshMatrices = new D3DXMATRIX[meshCount];
}
void CGrannyModelInstance::__DestroyMeshMatrices()
{
if (!m_meshMatrices)
return;
delete [] m_meshMatrices;
m_meshMatrices = NULL;
}
DWORD CGrannyModelInstance::GetDeformableVertexCount()
{
if (!m_pModel)
return 0;
return m_pModel->GetDeformVertexCount();
}
DWORD CGrannyModelInstance::GetVertexCount()
{
if (!m_pModel)
return 0;
return m_pModel->GetVertexCount();
}
// WORK
void CGrannyModelInstance::__SetSharedDeformableVertexBuffer(CGraphicVertexBuffer* pkSharedDeformableVertexBuffer)
{
m_pkSharedDeformableVertexBuffer = pkSharedDeformableVertexBuffer;
}
bool CGrannyModelInstance::__IsDeformableVertexBuffer()
{
if (m_pkSharedDeformableVertexBuffer)
return true;
return m_kLocalDeformableVertexBuffer.IsEmpty();
}
IDirect3DVertexBuffer8* CGrannyModelInstance::__GetDeformableD3DVertexBufferPtr()
{
return __GetDeformableVertexBufferRef().GetD3DVertexBuffer();
}
CGraphicVertexBuffer& CGrannyModelInstance::__GetDeformableVertexBufferRef()
{
if (m_pkSharedDeformableVertexBuffer)
return *m_pkSharedDeformableVertexBuffer;
return m_kLocalDeformableVertexBuffer;
}
void CGrannyModelInstance::__CreateDynamicVertexBuffer()
{
assert(m_pModel != NULL);
assert(m_kLocalDeformableVertexBuffer.IsEmpty());
int vtxCount = m_pModel->GetDeformVertexCount();
if (0 != vtxCount)
{
if (!m_kLocalDeformableVertexBuffer.Create(vtxCount,
D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1,
//D3DUSAGE_DYNAMIC, D3DPOOL_SYSTEMMEM
D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED
))
return;
}
}
void CGrannyModelInstance::__DestroyDynamicVertexBuffer()
{
m_kLocalDeformableVertexBuffer.Destroy();
m_pkSharedDeformableVertexBuffer = NULL;
}
// END_OF_WORK
bool CGrannyModelInstance::GetBoneIndexByName(const char * c_szBoneName, int * pBoneIndex) const
{
assert(m_pgrnModelInstance != NULL);
granny_skeleton * pgrnSkeleton = GrannyGetSourceSkeleton(m_pgrnModelInstance);
if (!GrannyFindBoneByName(pgrnSkeleton, c_szBoneName, pBoneIndex))
return false;
return true;
}
const float * CGrannyModelInstance::GetBoneMatrixPointer(int iBone) const
{
const float* bones = GrannyGetWorldPose4x4(__GetWorldPosePtr(), iBone);
if (!bones)
{
granny_model* pModel = m_pModel->GetGrannyModelPointer();
//TraceError("GrannyModelInstance(%s).GetBoneMatrixPointer(boneIndex(%d)).NOT_FOUND_BONE", pModel->Name, iBone);
return NULL;
}
return bones;
}
const float * CGrannyModelInstance::GetCompositeBoneMatrixPointer(int iBone) const
{
// NOTE : GrannyGetWorldPose4x4는 스케일 값등이 잘못나올 수 있음.. 그래니가 속도를 위해
// GrannyGetWorldPose4x4에 모든 matrix 원소를 제 값으로 넣지 않음
return GrannyGetWorldPoseComposite4x4(__GetWorldPosePtr(), iBone);
}
void CGrannyModelInstance::ReloadTexture()
{
assert("\307\366\300\347 \273\347\277\353\307\317\301\366 \276\312\300\275 - CGrannyModelInstance::ReloadTexture()");
/*
assert(m_pModel != NULL);
const CGrannyMaterialPalette & c_rGrannyMaterialPalette = m_pModel->GetMaterialPalette();
DWORD dwMaterialCount = c_rGrannyMaterialPalette.GetMaterialCount();
for (DWORD dwMtrIndex = 0; dwMtrIndex < dwMaterialCount; ++dwMtrIndex)
{
const CGrannyMaterial & c_rGrannyMaterial = c_rGrannyMaterialPalette.GetMaterialRef(dwMtrIndex);
CGraphicImage * pImageStage0 = c_rGrannyMaterial.GetImagePointer(0);
if (pImageStage0)
pImageStage0->Reload();
CGraphicImage * pImageStage1 = c_rGrannyMaterial.GetImagePointer(1);
if (pImageStage1)
pImageStage1->Reload();
}
*/
}
@@ -0,0 +1,148 @@
#include "StdAfx.h"
#include "ModelInstance.h"
#include "Model.h"
void CGrannyModelInstance::CopyMotion(CGrannyModelInstance * pModelInstance, bool bIsFreeSourceControl)
{
if (!pModelInstance->IsMotionPlaying())
return;
if (m_pgrnCtrl)
GrannyFreeControl(m_pgrnCtrl);
float localTime = GetLocalTime();
m_pgrnAni = pModelInstance->m_pgrnAni;
m_pgrnCtrl = GrannyPlayControlledAnimation(localTime, m_pgrnAni, m_pgrnModelInstance);
if (!m_pgrnCtrl)
return;
GrannySetControlSpeed(m_pgrnCtrl, GrannyGetControlSpeed(pModelInstance->m_pgrnCtrl));
GrannySetControlLoopCount(m_pgrnCtrl, GrannyGetControlLoopCount(pModelInstance->m_pgrnCtrl));
GrannySetControlEaseIn(m_pgrnCtrl, true);
GrannySetControlEaseOut(m_pgrnCtrl, false);
GrannySetControlRawLocalClock(m_pgrnCtrl, GrannyGetControlRawLocalClock(pModelInstance->m_pgrnCtrl));
GrannyFreeControlOnceUnused(m_pgrnCtrl);
if (bIsFreeSourceControl)
{
GrannyFreeControl(pModelInstance->m_pgrnCtrl);
pModelInstance->m_pgrnCtrl = NULL;
}
}
bool CGrannyModelInstance::IsMotionPlaying()
{
if (!m_pgrnCtrl)
return false;
if (GrannyControlIsComplete(m_pgrnCtrl))
return false;
return true;
}
void CGrannyModelInstance::SetMotionPointer(const CGrannyMotion * pMotion, float blendTime, int loopCount, float speedRatio)
{
// TEST
if (!m_pgrnWorldPoseReal)
return;
// END_OF_TEST
granny_model_instance * pgrnModelInstance = m_pgrnModelInstance;
if (!pgrnModelInstance)
return;
float localTime = GetLocalTime();
bool isFirst=false;
if (m_pgrnCtrl)
{
//float durationLeft = GrannyGetControlDurationLeft(m_pgrnCtrl);
//float easeOutTime = (blendTime < durationLeft) ? blendTime : durationLeft;
//float oldCtrlFinishTime = GrannyEaseControlOut(m_pgrnCtrl, blendTime); //easeOutTime);
GrannySetControlEaseOutCurve(m_pgrnCtrl, localTime, localTime + blendTime, 1.0f, 1.0f, 0.0f, 0.0f);
GrannySetControlEaseIn(m_pgrnCtrl, false);
GrannySetControlEaseOut(m_pgrnCtrl, true);
//Tracef("easeOut %f\n", easeOutTime);
GrannyCompleteControlAt(m_pgrnCtrl, localTime + blendTime);
//GrannyCompleteControlAt(m_pgrnCtrl, oldCtrlFinishTime);
//GrannyCompleteControlAt(m_pgrnCtrl, localTime);
GrannyFreeControlIfComplete(m_pgrnCtrl);
}
else
{
isFirst=true;
}
m_pgrnAni = pMotion->GetGrannyAnimationPointer();
m_pgrnCtrl = GrannyPlayControlledAnimation(localTime, m_pgrnAni, pgrnModelInstance);
if (!m_pgrnCtrl)
return;
GrannySetControlSpeed(m_pgrnCtrl, speedRatio);
GrannySetControlLoopCount(m_pgrnCtrl, loopCount);
if (isFirst)
{
GrannySetControlEaseIn(m_pgrnCtrl, false);
GrannySetControlEaseOut(m_pgrnCtrl, false);
}
else
{
GrannySetControlEaseIn(m_pgrnCtrl, true);
GrannySetControlEaseOut(m_pgrnCtrl, false);
if (blendTime > 0.0f)
GrannySetControlEaseInCurve(m_pgrnCtrl, localTime, localTime + blendTime, 0.0f, 0.0f, 1.0f, 1.0f);
}
//GrannyEaseControlIn(m_pgrnCtrl, blendTime, false);
GrannyFreeControlOnceUnused(m_pgrnCtrl);
//Tracef("easeIn %f\n", blendTime);
}
void CGrannyModelInstance::ChangeMotionPointer(const CGrannyMotion* pMotion, int loopCount, float speedRatio)
{
granny_model_instance * pgrnModelInstance = m_pgrnModelInstance;
if (!pgrnModelInstance)
return;
// 보간 되는 앞부분을 스킵 하기 위해 LocalTime 을 어느 정도 무시한다. - [levites]
float fSkipTime = 0.3f;
float localTime = GetLocalTime() - fSkipTime;
if (m_pgrnCtrl)
{
GrannySetControlEaseIn(m_pgrnCtrl, false);
GrannySetControlEaseOut(m_pgrnCtrl, false);
GrannyCompleteControlAt(m_pgrnCtrl, localTime);
GrannyFreeControlIfComplete(m_pgrnCtrl);
}
m_pgrnAni = pMotion->GetGrannyAnimationPointer();
m_pgrnCtrl = GrannyPlayControlledAnimation(localTime, m_pgrnAni, pgrnModelInstance);
if (!m_pgrnCtrl)
return;
GrannySetControlSpeed(m_pgrnCtrl, speedRatio);
GrannySetControlLoopCount(m_pgrnCtrl, loopCount);
GrannySetControlEaseIn(m_pgrnCtrl, false);
GrannySetControlEaseOut(m_pgrnCtrl, false);
GrannyFreeControlOnceUnused(m_pgrnCtrl);
}
void CGrannyModelInstance::SetMotionAtEnd()
{
if (!m_pgrnCtrl)
return;
//Tracef("%f\n", endingTime);
float endingTime = GrannyGetControlLocalDuration(m_pgrnCtrl);
GrannySetControlRawLocalClock(m_pgrnCtrl, endingTime);
}
@@ -0,0 +1,407 @@
#include "StdAfx.h"
#include "../EterLib/StateManager.h"
#include "ModelInstance.h"
#include "Model.h"
#ifdef _TEST
#include "../EterLib/GrpScreen.h"
void Granny_RenderBoxBones(const granny_skeleton* pkGrnSkeleton, const granny_world_pose* pkGrnWorldPose, const D3DXMATRIX& matBase)
{
D3DXMATRIX matWorld;
CScreen screen;
for (int iBone = 0; iBone != pkGrnSkeleton->BoneCount; ++iBone)
{
const granny_bone& rkGrnBone = pkGrnSkeleton->Bones[iBone];
const D3DXMATRIX* c_matBone=(const D3DXMATRIX*)GrannyGetWorldPose4x4(pkGrnWorldPose, iBone);
D3DXMatrixMultiply(&matWorld, c_matBone, &matBase);
STATEMANAGER.SetTransform(D3DTS_WORLD, &matWorld);
screen.RenderBox3d(-5.0f, -5.0f, -5.0f, 5.0f, 5.0f, 5.0f);
}
}
#endif
void CGrannyModelInstance::DeformNoSkin(const D3DXMATRIX * c_pWorldMatrix)
{
if (IsEmpty())
return;
// DELETED
//m_pgrnWorldPose = m_pgrnWorldPoseReal;
///////////////////////////////
UpdateWorldPose();
UpdateWorldMatrices(c_pWorldMatrix);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Render
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// With One Texture
void CGrannyModelInstance::RenderWithOneTexture()
{
// FIXME : Deform, Render, BlendRender를 묶어 상위에서 걸러주는 것이 더 나을 듯 - [levites]
if (IsEmpty())
return;
#ifdef _TEST
Granny_RenderBoxBones(GrannyGetSourceSkeleton(m_pgrnModelInstance), m_pgrnWorldPose, TEST_matWorld);
if (GetAsyncKeyState('P'))
Tracef("render %x", m_pgrnModelInstance);
return;
#endif
STATEMANAGER.SetVertexShader(ms_pntVS);
// WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr();
// END_OF_WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithOneTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithOneTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
}
void CGrannyModelInstance::BlendRenderWithOneTexture()
{
if (IsEmpty())
return;
// WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr();
// END_OF_WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
STATEMANAGER.SetVertexShader(ms_pntVS);
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithOneTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_BLEND_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithOneTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_BLEND_PNT);
}
}
// With Two Texture
void CGrannyModelInstance::RenderWithTwoTexture()
{
// FIXME : Deform, Render, BlendRender를 묶어 상위에서 걸러주는 것이 더 나을 듯 - [levites]
if (IsEmpty())
return;
STATEMANAGER.SetVertexShader(ms_pntVS);
// WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr();
// END_OF_WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithTwoTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithTwoTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
}
void CGrannyModelInstance::BlendRenderWithTwoTexture()
{
if (IsEmpty())
return;
// WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr();
// END_OF_WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
STATEMANAGER.SetVertexShader(ms_pntVS);
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithTwoTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_BLEND_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithTwoTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_BLEND_PNT);
}
}
void CGrannyModelInstance::RenderWithoutTexture()
{
if (IsEmpty())
return;
STATEMANAGER.SetVertexShader(ms_pntVS);
STATEMANAGER.SetTexture(0, NULL);
STATEMANAGER.SetTexture(1, NULL);
// WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = __GetDeformableD3DVertexBufferPtr();
// END_OF_WORK
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_DIFFUSE_PNT);
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_BLEND_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_DIFFUSE_PNT);
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_BLEND_PNT);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Render Mesh List
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// With One Texture
void CGrannyModelInstance::RenderMeshNodeListWithOneTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType)
{
assert(m_pModel != NULL);
LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer();
assert(lpd3dIdxBuf != NULL);
const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType);
while (pMeshNode)
{
const CGrannyMesh * pMesh = pMeshNode->pMesh;
int vtxMeshBasePos = pMesh->GetVertexBasePosition();
STATEMANAGER.SetIndices(lpd3dIdxBuf, vtxMeshBasePos);
STATEMANAGER.SetTransform(D3DTS_WORLD, &m_meshMatrices[pMeshNode->iMesh]);
/////
const CGrannyMesh::TTriGroupNode* pTriGroupNode = pMesh->GetTriGroupNodeList(eMtrlType);
int vtxCount = pMesh->GetVertexCount();
while (pTriGroupNode)
{
ms_faceCount += pTriGroupNode->triCount;
CGrannyMaterial& rkMtrl=m_kMtrlPal.GetMaterialRef(pTriGroupNode->mtrlIndex);
rkMtrl.ApplyRenderState();
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount);
rkMtrl.RestoreRenderState();
pTriGroupNode = pTriGroupNode->pNextTriGroupNode;
}
/////
pMeshNode = pMeshNode->pNextMeshNode;
}
}
// With Two Texture
void CGrannyModelInstance::RenderMeshNodeListWithTwoTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType)
{
assert(m_pModel != NULL);
LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer();
assert(lpd3dIdxBuf != NULL);
const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType);
while (pMeshNode)
{
const CGrannyMesh * pMesh = pMeshNode->pMesh;
int vtxMeshBasePos = pMesh->GetVertexBasePosition();
STATEMANAGER.SetIndices(lpd3dIdxBuf, vtxMeshBasePos);
STATEMANAGER.SetTransform(D3DTS_WORLD, &m_meshMatrices[pMeshNode->iMesh]);
/////
const CGrannyMesh::TTriGroupNode* pTriGroupNode = pMesh->GetTriGroupNodeList(eMtrlType);
int vtxCount = pMesh->GetVertexCount();
while (pTriGroupNode)
{
ms_faceCount += pTriGroupNode->triCount;
const CGrannyMaterial& rkMtrl=m_kMtrlPal.GetMaterialRef(pTriGroupNode->mtrlIndex);
STATEMANAGER.SetTexture(0, rkMtrl.GetD3DTexture(0));
STATEMANAGER.SetTexture(1, rkMtrl.GetD3DTexture(1));
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount);
pTriGroupNode = pTriGroupNode->pNextTriGroupNode;
}
/////
pMeshNode = pMeshNode->pNextMeshNode;
}
}
// Without Texture
void CGrannyModelInstance::RenderMeshNodeListWithoutTexture(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType)
{
assert(m_pModel != NULL);
LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer();
assert(lpd3dIdxBuf != NULL);
const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType);
while (pMeshNode)
{
const CGrannyMesh * pMesh = pMeshNode->pMesh;
int vtxMeshBasePos = pMesh->GetVertexBasePosition();
STATEMANAGER.SetIndices(lpd3dIdxBuf, vtxMeshBasePos);
STATEMANAGER.SetTransform(D3DTS_WORLD, &m_meshMatrices[pMeshNode->iMesh]);
/////
const CGrannyMesh::TTriGroupNode* pTriGroupNode = pMesh->GetTriGroupNodeList(eMtrlType);
int vtxCount = pMesh->GetVertexCount();
while (pTriGroupNode)
{
ms_faceCount += pTriGroupNode->triCount;
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount);
pTriGroupNode = pTriGroupNode->pNextTriGroupNode;
}
/////
pMeshNode = pMeshNode->pNextMeshNode;
}
}
/*
void CGrannyModelInstance::RenderMeshNodeList(CGrannyMesh::EType eMeshType, CGrannyMaterial::EType eMtrlType)
{
assert(m_pModel != NULL);
LPDIRECT3DINDEXBUFFER8 lpd3dIdxBuf = m_pModel->GetD3DIndexBuffer();
assert(lpd3dIdxBuf != NULL);
const CGrannyModel::TMeshNode * pMeshNode = m_pModel->GetMeshNodeList(eMeshType, eMtrlType);
while (pMeshNode)
{
const CGrannyMesh * pMesh = pMeshNode->pMesh;
int vtxMeshBasePos = pMesh->GetVertexBasePosition();
STATEMANAGER.SetIndices(lpd3dIdxBuf, vtxMeshBasePos);
STATEMANAGER.SetTransform(D3DTS_WORLD, &m_meshMatrices[pMeshNode->iMesh]);
/////
const CGrannyMesh::TTriGroupNode* pTriGroupNode = pMesh->GetTriGroupNodeList(eMtrlType);
int vtxCount = pMesh->GetVertexCount();
while (pTriGroupNode)
{
ms_faceCount += pTriGroupNode->triCount;
STATEMANAGER.SetTexture(0, pTriGroupNode->lpd3dTextures[0]);
if (pTriGroupNode->lpd3dTextures[1])
STATEMANAGER.SetTexture(1, pTriGroupNode->lpd3dTextures[1]);
else
{
STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
STATEMANAGER.SetTexture(1, m_FogInstance.GetTexturePointer()->GetD3DTexture());
D3DXMATRIX mat;
memset(&mat, 0, sizeof(D3DXMATRIX));
mat._31 = -0.001f;
mat._41 = -7.0f;
mat._42 = 0.5f;
STATEMANAGER.SetTransform(D3DTS_TEXTURE1, &mat);
}
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vtxCount, pTriGroupNode->idxPos, pTriGroupNode->triCount);
if (!pTriGroupNode->lpd3dTextures[1])
{
STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
STATEMANAGER.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
pTriGroupNode = pTriGroupNode->pNextTriGroupNode;
}
/////
pMeshNode = pMeshNode->pNextMeshNode;
}
}
void CGrannyModelInstance::RenderToShadowMap()
{
if (IsEmpty())
return;
STATEMANAGER.SetVertexShader(ms_pntVS);
// LPDIRECT3DVERTEXBUFFER8 lpd3dDynamicPNTVtxBuf = m_dynamicPNTVtxBuf.GetD3DVertexBuffer();
LPDIRECT3DVERTEXBUFFER8 lpd3dDeformPNTVtxBuf = m_dynamicPNTVtxBuf.GetD3DVertexBuffer();
LPDIRECT3DVERTEXBUFFER8 lpd3dRigidPNTVtxBuf = m_pModel->GetPNTD3DVertexBuffer();
// STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, TRUE);
// STATEMANAGER.SaveRenderState(D3DRS_ALPHAREF, 0);
// STATEMANAGER.SaveRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
//
// if (lpd3dDynamicPNTVtxBuf)
// {
// STATEMANAGER.SetStreamSource(0, lpd3dDynamicPNTVtxBuf, sizeof(TPNTVertex));
// RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_BLEND_PNT);
// }
//
// STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE);
// STATEMANAGER.RestoreRenderState(D3DRS_ALPHAREF);
// STATEMANAGER.RestoreRenderState(D3DRS_ALPHAFUNC);
if (lpd3dDeformPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dDeformPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_DEFORM, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
if (lpd3dRigidPNTVtxBuf)
{
STATEMANAGER.SetStreamSource(0, lpd3dRigidPNTVtxBuf, sizeof(TPNTVertex));
RenderMeshNodeListWithoutTexture(CGrannyMesh::TYPE_RIGID, CGrannyMaterial::TYPE_DIFFUSE_PNT);
}
}
*/
@@ -0,0 +1,208 @@
#include "StdAfx.h"
#include "../EterBase/Debug.h"
#include "ModelInstance.h"
#include "Model.h"
void CGrannyModelInstance::Update(DWORD dwAniFPS)
{
if (!dwAniFPS)
return;
const DWORD c_dwCurUpdateFrame = (DWORD) (GetLocalTime() * static_cast<float>(ANIFPS_MAX));
const DWORD ANIFPS_STEP = ANIFPS_MAX/dwAniFPS;
if (c_dwCurUpdateFrame>ANIFPS_STEP && c_dwCurUpdateFrame/ANIFPS_STEP==m_dwOldUpdateFrame/ANIFPS_STEP)
return;
m_dwOldUpdateFrame=c_dwCurUpdateFrame;
GrannyFreeCompletedModelControls(m_pgrnModelInstance); //Black screen fix
//DWORD t1=timeGetTime();
GrannySetModelClock(m_pgrnModelInstance, GetLocalTime());
//DWORD t2=timeGetTime();
#ifdef __PERFORMANCE_CHECKER__
{
static FILE* fp=fopen("perf_grn_setmodelclock.txt", "w");
if (t2-t1>3)
{
fprintf(fp, "%f:%x:- GrannySetModelClock(time=%f) = %dms\n", timeGetTime()/1000.0f, this, GetLocalTime(), t2-t1);
fflush(fp);
}
}
#endif
}
void CGrannyModelInstance::UpdateLocalTime(float fElapsedTime)
{
m_fSecondsElapsed = fElapsedTime;
m_fLocalTime += fElapsedTime;
}
void CGrannyModelInstance::UpdateTransform(D3DXMATRIX * pMatrix, float fSecondsElapsed)
{
if (!m_pgrnModelInstance)
{
TraceError("CGrannyModelIstance::UpdateTransform - m_pgrnModelInstance = NULL");
return;
}
GrannyUpdateModelMatrix(m_pgrnModelInstance, fSecondsElapsed, (const float *) pMatrix, (float *) pMatrix, false);
//Tracef("%f %f %f",pMatrix->_41,pMatrix->_42,pMatrix->_43);
}
void CGrannyModelInstance::Deform(const D3DXMATRIX * c_pWorldMatrix)
{
if (IsEmpty())
return;
// DELETED
//m_pgrnWorldPose = m_pgrnWorldPoseReal;
/////////////////////////////////////////////
UpdateWorldPose();
UpdateWorldMatrices(c_pWorldMatrix);
if (m_pModel->CanDeformPNTVertices())
{
// WORK
CGraphicVertexBuffer& rkDeformableVertexBuffer = __GetDeformableVertexBufferRef();
TPNTVertex* pntVertices;
if (rkDeformableVertexBuffer.LockRange(m_pModel->GetDeformVertexCount(), (void **)&pntVertices))
{
DeformPNTVertices(pntVertices);
rkDeformableVertexBuffer.Unlock();
}
else
{
TraceError("GRANNY DEFORM DYNAMIC BUFFER LOCK ERROR");
}
// END_OF_WORK
}
}
//////////////////////////////////////////////////////
class CGrannyLocalPose
{
public:
CGrannyLocalPose()
{
m_pgrnLocalPose = NULL;
m_boneCount = 0;
}
virtual ~CGrannyLocalPose()
{
if (m_pgrnLocalPose)
GrannyFreeLocalPose(m_pgrnLocalPose);
}
granny_local_pose * Get(int boneCount)
{
if (m_pgrnLocalPose)
{
if (m_boneCount >= boneCount)
return m_pgrnLocalPose;
GrannyFreeLocalPose(m_pgrnLocalPose);
}
m_boneCount = boneCount;
m_pgrnLocalPose = GrannyNewLocalPose(m_boneCount);
return m_pgrnLocalPose;
}
private:
granny_local_pose * m_pgrnLocalPose;
int m_boneCount;
};
//////////////////////////////////////////////////////
void CGrannyModelInstance::UpdateSkeleton(const D3DXMATRIX * c_pWorldMatrix, float /*fLocalTime*/)
{
// DELETED
//m_pgrnWorldPose = m_pgrnWorldPoseReal;
///////////////////////////////////////////
UpdateWorldPose();
UpdateWorldMatrices(c_pWorldMatrix);
}
void CGrannyModelInstance::UpdateWorldPose()
{
// WEP = m_iParentBoneIndex != 0 -> UpdateWorldPose(O)
// LOD = UpdateWorldPose(O)
// Hair = UpdateWorldPose(X)
if (m_ppkSkeletonInst)
if (*m_ppkSkeletonInst!=this)
return;
static CGrannyLocalPose s_SharedLocalPose;
granny_skeleton * pgrnSkeleton = GrannyGetSourceSkeleton(m_pgrnModelInstance);
granny_local_pose * pgrnLocalPose = s_SharedLocalPose.Get(pgrnSkeleton->BoneCount);
const float * pAttachBoneMatrix = (mc_pParentInstance) ? mc_pParentInstance->GetBoneMatrixPointer(m_iParentBoneIndex) : NULL;
GrannySampleModelAnimationsAccelerated(m_pgrnModelInstance, pgrnSkeleton->BoneCount, pAttachBoneMatrix, pgrnLocalPose, __GetWorldPosePtr());
/*
GrannySampleModelAnimations(m_pgrnModelInstance, 0, pgrnSkeleton->BoneCount, pgrnLocalPose);
GrannyBuildWorldPose(pgrnSkeleton, 0, pgrnSkeleton->BoneCount, pgrnLocalPose, pAttachBoneMatrix, m_pgrnWorldPose);
*/
GrannyFreeCompletedModelControls(m_pgrnModelInstance);
}
void CGrannyModelInstance::UpdateWorldMatrices(const D3DXMATRIX* c_pWorldMatrix)
{
// NO_MESH_BUG_FIX
if (!m_meshMatrices)
return;
// END_OF_NO_MESH_BUG_FIX
assert(m_pModel != NULL);
assert(ms_lpd3dMatStack != NULL);
int meshCount = m_pModel->GetMeshCount();
granny_matrix_4x4 * pgrnMatCompositeBuffer = GrannyGetWorldPoseComposite4x4Array(__GetWorldPosePtr());
D3DXMATRIX * boneMatrices = (D3DXMATRIX *) pgrnMatCompositeBuffer;
for (int i = 0; i < meshCount; ++i)
{
D3DXMATRIX & rWorldMatrix = m_meshMatrices[i];
const CGrannyMesh * pMesh = m_pModel->GetMeshPointer(i);
// WORK
int * boneIndices = __GetMeshBoneIndices(i);
// END_OF_WORK
if (pMesh->CanDeformPNTVertices())
{
rWorldMatrix = *c_pWorldMatrix;
}
else
{
int iBone = *boneIndices;
D3DXMatrixMultiply(&rWorldMatrix, &boneMatrices[iBone], c_pWorldMatrix);
}
}
#ifdef _TEST
TEST_matWorld = *c_pWorldMatrix;
#endif
}
void CGrannyModelInstance::DeformPNTVertices(void * pvDest)
{
assert(m_pModel != NULL);
assert(m_pModel->CanDeformPNTVertices());
// WORK
m_pModel->DeformPNTVertices(pvDest, (D3DXMATRIX *) GrannyGetWorldPoseComposite4x4Array(__GetWorldPosePtr()), m_vct_pgrnMeshBinding);
// END_OF_WORK
}
+70
View File
@@ -0,0 +1,70 @@
#include "StdAfx.h"
#include "Motion.h"
CGrannyMotion::CGrannyMotion()
{
Initialize();
}
CGrannyMotion::~CGrannyMotion()
{
Destroy();
}
bool CGrannyMotion::IsEmpty()
{
return m_pgrnAni ? false : true;
}
void CGrannyMotion::Destroy()
{
Initialize();
}
void CGrannyMotion::Initialize()
{
m_pgrnAni = NULL;
}
bool CGrannyMotion::BindGrannyAnimation(granny_animation * pgrnAni)
{
assert(IsEmpty());
m_pgrnAni = pgrnAni;
return true;
}
granny_animation* CGrannyMotion::GetGrannyAnimationPointer() const
{
return m_pgrnAni;
}
const char * CGrannyMotion::GetName() const
{
return m_pgrnAni->Name;
}
float CGrannyMotion::GetDuration() const
{
return m_pgrnAni->Duration;
}
void CGrannyMotion::GetTextTrack(const char * c_szTextTrackName, int * pCount, float * pArray) const
{
if (m_pgrnAni->TrackGroupCount != 1)
{
// assert(!"CGrannyMotion::GetTextTrack - TrackCount is not 1");
}
granny_track_group * pTrack = m_pgrnAni->TrackGroups[0];
for (int i = 0; i < pTrack->TextTrackCount; ++i)
{
granny_text_track & rTextTrack = pTrack->TextTracks[i];
for (int j = 0; j < rTextTrack.EntryCount; ++j)
if (!_stricmp(c_szTextTrackName, rTextTrack.Entries[j].Text))
pArray[(*pCount)++] = rTextTrack.Entries[j].TimeStamp;
}
}
+242
View File
@@ -0,0 +1,242 @@
#include "StdAfx.h"
#include "../EterBase/Debug.h"
#include "Thing.h"
#include "ThingInstance.h"
CGraphicThing::CGraphicThing(const char* c_szFileName) : CResource(c_szFileName)
{
Initialize();
}
CGraphicThing::~CGraphicThing()
{
//OnClear();
Clear();
}
void CGraphicThing::Initialize()
{
m_pgrnFile = NULL;
m_pgrnFileInfo = NULL;
m_pgrnAni = NULL;
m_models = NULL;
m_motions = NULL;
}
void CGraphicThing::OnClear()
{
if (m_motions)
delete [] m_motions;
if (m_models)
delete [] m_models;
if (m_pgrnFile)
GrannyFreeFile(m_pgrnFile);
Initialize();
}
CGraphicThing::TType CGraphicThing::Type()
{
static TType s_type = StringToType("CGraphicThing");
return s_type;
}
bool CGraphicThing::OnIsEmpty() const
{
return m_pgrnFile ? false : true;
}
bool CGraphicThing::OnIsType(TType type)
{
if (CGraphicThing::Type() == type)
return true;
return CResource::OnIsType(type);
}
bool CGraphicThing::CreateDeviceObjects()
{
if (!m_pgrnFileInfo)
return true;
for (int m = 0; m < m_pgrnFileInfo->ModelCount; ++m)
{
CGrannyModel & rModel = m_models[m];
rModel.CreateDeviceObjects();
}
return true;
}
void CGraphicThing::DestroyDeviceObjects()
{
if (!m_pgrnFileInfo)
return;
for (int m = 0; m < m_pgrnFileInfo->ModelCount; ++m)
{
CGrannyModel & rModel = m_models[m];
rModel.DestroyDeviceObjects();
}
}
bool CGraphicThing::CheckModelIndex(int iModel) const
{
if (!m_pgrnFileInfo)
{
Tracef("m_pgrnFileInfo == NULL: %s\n", GetFileName());
return false;
}
assert(m_pgrnFileInfo != NULL);
if (iModel < 0)
return false;
if (iModel >= m_pgrnFileInfo->ModelCount)
return false;
return true;
}
bool CGraphicThing::CheckMotionIndex(int iMotion) const
{
// Temporary
if (!m_pgrnFileInfo)
return false;
// Temporary
assert(m_pgrnFileInfo != NULL);
if (iMotion < 0)
return false;
if (iMotion >= m_pgrnFileInfo->AnimationCount)
return false;
return true;
}
CGrannyModel * CGraphicThing::GetModelPointer(int iModel)
{
assert(CheckModelIndex(iModel));
assert(m_models != NULL);
return m_models + iModel;
}
CGrannyMotion * CGraphicThing::GetMotionPointer(int iMotion)
{
assert(CheckMotionIndex(iMotion));
if (iMotion >= m_pgrnFileInfo->AnimationCount)
return NULL;
assert(m_motions != NULL);
return (m_motions + iMotion);
}
int CGraphicThing::GetModelCount() const
{
if (!m_pgrnFileInfo)
return 0;
return (m_pgrnFileInfo->ModelCount);
}
int CGraphicThing::GetMotionCount() const
{
if (!m_pgrnFileInfo)
return 0;
return (m_pgrnFileInfo->AnimationCount);
}
bool CGraphicThing::OnLoad(int iSize, const void * c_pvBuf)
{
if (!c_pvBuf)
return false;
m_pgrnFile = GrannyReadEntireFileFromMemory(iSize, (void *) c_pvBuf);
if (!m_pgrnFile)
return false;
m_pgrnFileInfo = GrannyGetFileInfo(m_pgrnFile);
if (!m_pgrnFileInfo)
return false;
LoadModels();
LoadMotions();
return true;
}
// SUPPORT_LOCAL_TEXTURE
static std::string gs_modelLocalPath;
const std::string& GetModelLocalPath()
{
return gs_modelLocalPath;
}
// END_OF_SUPPORT_LOCAL_TEXTURE
bool CGraphicThing::LoadModels()
{
assert(m_pgrnFile != NULL);
assert(m_models == NULL);
if (m_pgrnFileInfo->ModelCount <= 0)
return false;
// SUPPORT_LOCAL_TEXTURE
const std::string& fileName = GetFileNameString();
//char localPath[256] = "";
if (fileName.length() > 2 && fileName[1] != ':')
{
int sepPos = fileName.rfind('\\');
gs_modelLocalPath.assign(fileName, 0, sepPos+1);
}
// END_OF_SUPPORT_LOCAL_TEXTURE
int modelCount = m_pgrnFileInfo->ModelCount;
m_models = new CGrannyModel[modelCount];
for (int m = 0; m < modelCount; ++m)
{
CGrannyModel & rModel = m_models[m];
granny_model * pgrnModel = m_pgrnFileInfo->Models[m];
if (!rModel.CreateFromGrannyModelPointer(pgrnModel))
return false;
}
GrannyFreeFileSection(m_pgrnFile, GrannyStandardRigidVertexSection);
GrannyFreeFileSection(m_pgrnFile, GrannyStandardRigidIndexSection);
GrannyFreeFileSection(m_pgrnFile, GrannyStandardDeformableIndexSection);
GrannyFreeFileSection(m_pgrnFile, GrannyStandardTextureSection);
return true;
}
bool CGraphicThing::LoadMotions()
{
assert(m_pgrnFile != NULL);
assert(m_motions == NULL);
if (m_pgrnFileInfo->AnimationCount <= 0)
return false;
int motionCount = m_pgrnFileInfo->AnimationCount;
m_motions = new CGrannyMotion[motionCount];
for (int m = 0; m < motionCount; ++m)
if (!m_motions[m].BindGrannyAnimation(m_pgrnFileInfo->Animations[m]))
return false;
return true;
}
@@ -0,0 +1,967 @@
#include "StdAfx.h"
#include "../EterBase/Debug.h"
#include "../EterLib/Camera.h"
#include "../EterBase/Timer.h"
#include "ThingInstance.h"
#include "Thing.h"
#include "ModelInstance.h"
CDynamicPool<CGraphicThingInstance> CGraphicThingInstance::ms_kPool;
CGraphicThing* CGraphicThingInstance::GetBaseThingPtr()
{
if (m_modelThingSetVector.empty())
return NULL;
TModelThingSet& rkModelThingSet=m_modelThingSetVector[0];
if (rkModelThingSet.m_pLODThingRefVector.empty())
return NULL;
CGraphicThing::TRef* proThing=rkModelThingSet.m_pLODThingRefVector[0];
if (!proThing)
return NULL;
CGraphicThing::TRef roThing=*proThing;
return roThing.GetPointer();
}
bool CGraphicThingInstance::LessRenderOrder(CGraphicThingInstance* pkThingInst)
{
return (GetBaseThingPtr()<pkThingInst->GetBaseThingPtr());
}
void CGraphicThingInstance::CreateSystem(UINT uCapacity)
{
ms_kPool.Create(uCapacity);
}
void CGraphicThingInstance::DestroySystem()
{
ms_kPool.Destroy();
}
CGraphicThingInstance* CGraphicThingInstance::New()
{
return ms_kPool.Alloc();
}
void CGraphicThingInstance::Delete(CGraphicThingInstance* pkThingInst)
{
pkThingInst->Clear();
ms_kPool.Free(pkThingInst);
}
void CGraphicThingInstance::SetMotionAtEnd()
{
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), std::mem_fn(&CGrannyLODController::SetMotionAtEnd));
}
bool CGraphicThingInstance::Picking(const D3DXVECTOR3 & v, const D3DXVECTOR3 & dir, float & out_x, float & out_y)
{
if (!m_pHeightAttributeInstance)
return false;
return m_pHeightAttributeInstance->Picking(v,dir,out_x,out_y);
}
void CGraphicThingInstance::OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector)
{
assert(pscdVector);
CStaticCollisionDataVector::const_iterator it;
for(it = pscdVector->begin();it!=pscdVector->end();++it)
{
AddCollision(&(*it),&GetTransform());
}
}
void CGraphicThingInstance::OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance)
{
assert(pAttributeInstance);
SetHeightInstance(pAttributeInstance);
}
bool CGraphicThingInstance::OnGetObjectHeight(float fX, float fY, float * pfHeight)
{
if (m_pHeightAttributeInstance && m_pHeightAttributeInstance->GetHeight(fX, fY, pfHeight))
return true;
return false;
}
void CGraphicThingInstance::BuildBoundingSphere()
{
D3DXVECTOR3 v3Min, v3Max;
GetBoundBox(0, &v3Min, &v3Max);
m_v3Center = (v3Min + v3Max) * 0.5f;
D3DXVECTOR3 vDelta = (v3Max - v3Min);
m_fRadius = D3DXVec3Length(&vDelta) * 0.5f + 50.0f; // extra length for attached objects
}
bool CGraphicThingInstance::GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius)
{
if (m_fRadius <= 0)
{
BuildBoundingSphere();
fRadius = m_fRadius;
v3Center = m_v3Center;
}
else
{
fRadius = m_fRadius;
v3Center = m_v3Center;
}
D3DXVec3TransformCoord(&v3Center, &v3Center, &GetTransform());
return true;
}
void CGraphicThingInstance::BuildBoundingAABB()
{
D3DXVECTOR3 v3Min, v3Max;
GetBoundBox(0, &v3Min, &v3Max);
m_v3Center = (v3Min + v3Max) * 0.5f;
m_v3Min = v3Min;
m_v3Max = v3Max;
}
bool CGraphicThingInstance::GetBoundingAABB(D3DXVECTOR3 & v3Min, D3DXVECTOR3 & v3Max)
{
BuildBoundingAABB();
v3Min = m_v3Min;
v3Max = m_v3Max;
D3DXVec3TransformCoord(&m_v3Center, &m_v3Center, &GetTransform());
return true;
}
void CGraphicThingInstance::CalculateBBox()
{
GetBoundBox(&m_v3BBoxMin, &m_v3BBoxMax);
m_v4TBBox[0] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f);
m_v4TBBox[1] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f);
m_v4TBBox[2] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f);
m_v4TBBox[3] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f);
m_v4TBBox[4] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f);
m_v4TBBox[5] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f);
m_v4TBBox[6] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f);
m_v4TBBox[7] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f);
const D3DXMATRIX & c_rmatTransform = GetTransform();
for (DWORD i = 0; i < 8; ++i)
{
D3DXVec4Transform(&m_v4TBBox[i], &m_v4TBBox[i], &c_rmatTransform);
if (0 == i)
{
m_v3TBBoxMin.x = m_v4TBBox[i].x;
m_v3TBBoxMin.y = m_v4TBBox[i].y;
m_v3TBBoxMin.z = m_v4TBBox[i].z;
m_v3TBBoxMax.x = m_v4TBBox[i].x;
m_v3TBBoxMax.y = m_v4TBBox[i].y;
m_v3TBBoxMax.z = m_v4TBBox[i].z;
}
else
{
if (m_v3TBBoxMin.x > m_v4TBBox[i].x)
m_v3TBBoxMin.x = m_v4TBBox[i].x;
if (m_v3TBBoxMax.x < m_v4TBBox[i].x)
m_v3TBBoxMax.x = m_v4TBBox[i].x;
if (m_v3TBBoxMin.y > m_v4TBBox[i].y)
m_v3TBBoxMin.y = m_v4TBBox[i].y;
if (m_v3TBBoxMax.y < m_v4TBBox[i].y)
m_v3TBBoxMax.y = m_v4TBBox[i].y;
if (m_v3TBBoxMin.z > m_v4TBBox[i].z)
m_v3TBBoxMin.z = m_v4TBBox[i].z;
if (m_v3TBBoxMax.z < m_v4TBBox[i].z)
m_v3TBBoxMax.z = m_v4TBBox[i].z;
}
}
}
bool CGraphicThingInstance::CreateDeviceObjects()
{
CGrannyLODController::FCreateDeviceObjects createDeviceObjects;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), createDeviceObjects);
return true;
}
void CGraphicThingInstance::DestroyDeviceObjects()
{
CGrannyLODController::FDestroyDeviceObjects destroyDeviceObjects;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), destroyDeviceObjects);
}
bool CGraphicThingInstance::CheckModelInstanceIndex(int iModelInstance)
{
if (iModelInstance < 0)
return false;
int max = m_LODControllerVector.size();
if (iModelInstance >= max)
return false;
return true;
}
bool CGraphicThingInstance::CheckModelThingIndex(int iModelThing)
{
if (iModelThing < 0)
return false;
int max = m_modelThingSetVector.size();
if (iModelThing >= max)
return false;
return true;
}
bool CGraphicThingInstance::CheckMotionThingIndex(DWORD dwMotionKey)
{
std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey);
if (m_roMotionThingMap.end() == itor)
return false;
return true;
}
bool CGraphicThingInstance::GetMotionThingPointer(DWORD dwKey, CGraphicThing ** ppMotion)
{
if (!CheckMotionThingIndex(dwKey))
return false;
*ppMotion = m_roMotionThingMap[dwKey]->GetPointer();
return true;
}
bool CGraphicThingInstance::IsMotionThing()
{
return !m_roMotionThingMap.empty();
}
void CGraphicThingInstance::ReserveModelInstance(int iCount)
{
stl_wipe(m_LODControllerVector);
for (int i = 0; i < iCount; ++i)
{
CGrannyLODController * pInstance = new CGrannyLODController;
m_LODControllerVector.push_back(pInstance);
}
}
void CGraphicThingInstance::ReserveModelThing(int iCount)
{
m_modelThingSetVector.resize(iCount);
}
bool CGraphicThingInstance::FindBoneIndex(int iModelInstance, const char* c_szBoneName, int* iRetBone)
{
assert(CheckModelInstanceIndex(iModelInstance));
CGrannyModelInstance * pModelInstance = m_LODControllerVector[iModelInstance]->GetModelInstance();
if (!pModelInstance)
return false;
return pModelInstance->GetBoneIndexByName(c_szBoneName, iRetBone);
}
void CGraphicThingInstance::AttachModelInstance(int iDstModelInstance, const char * c_szBoneName, int iSrcModelInstance)
{
if (!CheckModelInstanceIndex(iSrcModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance);
return;
}
if (!CheckModelInstanceIndex(iDstModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance);
return;
}
CGrannyLODController * pSrcLODController = m_LODControllerVector[iSrcModelInstance];
CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance];
pDstLODController->AttachModelInstance(pSrcLODController, c_szBoneName);
}
void CGraphicThingInstance::AttachModelInstance(int iDstModelInstance, const char * c_szBoneName, CGraphicThingInstance & rSrcInstance, int iSrcModelInstance)
{
if (!CheckModelInstanceIndex(iDstModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance);
return;
}
if (!rSrcInstance.CheckModelInstanceIndex(iSrcModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance);
return;
}
CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance];
CGrannyLODController * pSrcLODController = rSrcInstance.m_LODControllerVector[iSrcModelInstance];
pDstLODController->AttachModelInstance(pSrcLODController, c_szBoneName);
}
void CGraphicThingInstance::DetachModelInstance(int iDstModelInstance, CGraphicThingInstance & rSrcInstance, int iSrcModelInstance)
{
if (!CheckModelInstanceIndex(iDstModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, iSrcModelInstance=%d)", iDstModelInstance, iSrcModelInstance);
return;
}
if (!rSrcInstance.CheckModelInstanceIndex(iSrcModelInstance))
{
TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, iSrcModelInstance=%d)", iDstModelInstance, iSrcModelInstance);
return;
}
CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance];
CGrannyLODController * pSrcLODController = rSrcInstance.m_LODControllerVector[iSrcModelInstance];
pDstLODController->DetachModelInstance(pSrcLODController);
}
bool CGraphicThingInstance::GetBonePosition(int iModelIndex, int iBoneIndex, float * pfx, float * pfy, float * pfz)
{
assert(CheckModelInstanceIndex(iModelIndex));
CGrannyModelInstance * pModelInstance = m_LODControllerVector[iModelIndex]->GetModelInstance();
if (!pModelInstance)
return false;
const float * pfMatrix = pModelInstance->GetBoneMatrixPointer(iBoneIndex);
*pfx = pfMatrix[12];
*pfy = pfMatrix[13];
*pfz = pfMatrix[14];
return true;
}
//iSkelInstance 가 있으면 기본 본에 Link(본이 붙는것)시키고,
//없으면 기본 본에 attach(좌표만 가져다 쓰는것) 됩니다.
bool CGraphicThingInstance::SetModelInstance(int iDstModelInstance, int iSrcModelThing, int iSrcModel,int iSkelInstance)
{
if (!CheckModelInstanceIndex(iDstModelInstance))
{
TraceError("CGraphicThingInstance::SetModelInstance(iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iDstModelInstance, iSrcModelThing, iSrcModel);
return false;
}
if (!CheckModelThingIndex(iSrcModelThing))
{
TraceError("CGraphicThingInstance::SetModelInstance(iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iDstModelInstance, iSrcModelThing, iSrcModel);
return false;
}
CGrannyLODController * pController = m_LODControllerVector[iDstModelInstance];
if (!pController)
return false;
// HAIR_LINK
CGrannyLODController * pSkelController = NULL;
if (iSkelInstance != DONTUSEVALUE)
{
if (!CheckModelInstanceIndex(iSkelInstance))
{
TraceError("CGraphicThingInstance::SetModelInstanceByOtherSkeletonInstance(iSkelInstance=%d, iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iSkelInstance, iDstModelInstance, iSrcModelThing, iSrcModel);
return false;
}
pSkelController = m_LODControllerVector[iSkelInstance];
if (!pSkelController)
return false;
}
// END_OF_HAIR_LINK
TModelThingSet & rModelThingSet = m_modelThingSetVector[iSrcModelThing];
pController->Clear();
for (DWORD i = 0; i < rModelThingSet.m_pLODThingRefVector.size(); ++i)
{
if (rModelThingSet.m_pLODThingRefVector[i]->IsNull())
return false;
pController->AddModel(rModelThingSet.m_pLODThingRefVector[i]->GetPointer(), iSrcModel, pSkelController);
}
return true;
}
void CGraphicThingInstance::SetMaterialImagePointer(UINT ePart, const char* c_szImageName, CGraphicImage* pImage)
{
if (ePart>=m_LODControllerVector.size())
{
TraceError("CGraphicThingInstance::SetMaterialImagePointer(ePart(%d)<uPartCount(%d), c_szImageName=%s, pImage=%s) - ePart OUT OF RANGE",
ePart, m_LODControllerVector.size(), c_szImageName, pImage->GetFileName());
return;
}
if (!m_LODControllerVector[ePart])
{
TraceError("CGraphicThingInstance::SetMaterialImagePointer(ePart(%d), c_szImageName=%s, pImage=%s) - ePart Data is NULL",
ePart, m_LODControllerVector.size(), c_szImageName, pImage->GetFileName());
return;
}
m_LODControllerVector[ePart]->SetMaterialImagePointer(c_szImageName, pImage);
}
void CGraphicThingInstance::SetMaterialData(UINT ePart, const char* c_szImageName, SMaterialData kMaterialData)
{
if (ePart>=m_LODControllerVector.size())
{
TraceError("CGraphicThingInstance::SetMaterialData(ePart(%d)<uPartCount(%d)) - ePart OUT OF RANGE",
ePart, m_LODControllerVector.size());
return;
}
if (!m_LODControllerVector[ePart])
{
TraceError("CGraphicThingInstance::SetMaterialData(ePart(%d)) - ePart Data is NULL",
ePart, m_LODControllerVector.size());
return;
}
m_LODControllerVector[ePart]->SetMaterialData(c_szImageName, kMaterialData);
}
void CGraphicThingInstance::SetSpecularInfo(UINT ePart, const char* c_szMtrlName, BOOL bEnable, float fPower)
{
if (ePart>=m_LODControllerVector.size())
{
TraceError("CGraphicThingInstance::SetSpecularInfo(ePart(%d)<uPartCount(%d)) - ePart OUT OF RANGE",
ePart, m_LODControllerVector.size());
return;
}
if (!m_LODControllerVector[ePart])
{
TraceError("CGraphicThingInstance::SetSpecularInfo(ePart(%d)) - ePart Data is NULL",
ePart, m_LODControllerVector.size());
return;
}
m_LODControllerVector[ePart]->SetSpecularInfo(c_szMtrlName, bEnable, fPower);
}
bool CGraphicThingInstance::SetMotion(DWORD dwMotionKey, float blendTime, int loopCount, float speedRatio)
{
if (!CheckMotionThingIndex(dwMotionKey))
return false;
std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey);
CGraphicThing::TRef * proMotionThing = itor->second;
CGraphicThing * pMotionThing = proMotionThing->GetPointer();
if (!pMotionThing)
return false;
if (!pMotionThing->CheckMotionIndex(0))
return false;
CGrannyLODController::FSetMotionPointer SetMotionPointer;
SetMotionPointer.m_pMotion = pMotionThing->GetMotionPointer(0);
SetMotionPointer.m_blendTime = blendTime;
SetMotionPointer.m_loopCount = loopCount;
SetMotionPointer.m_speedRatio = speedRatio;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), SetMotionPointer);
return true;
}
bool CGraphicThingInstance::ChangeMotion(DWORD dwMotionKey, int loopCount, float speedRatio)
{
if (!CheckMotionThingIndex(dwMotionKey))
return false;
std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey);
CGraphicThing::TRef * proMotionThing = itor->second;
CGraphicThing * pMotionThing = proMotionThing->GetPointer();
if (!pMotionThing)
return false;
if (!pMotionThing->CheckMotionIndex(0))
return false;
CGrannyLODController::FChangeMotionPointer ChangeMotionPointer;
ChangeMotionPointer.m_pMotion = pMotionThing->GetMotionPointer(0);
ChangeMotionPointer.m_loopCount = loopCount;
ChangeMotionPointer.m_speedRatio = speedRatio;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), ChangeMotionPointer);
return true;
}
void CGraphicThingInstance::SetEndStopMotion()
{
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), CGrannyLODController::FEndStopMotionPointer());
}
void CGraphicThingInstance::RegisterModelThing(int iModelThing, CGraphicThing * pModelThing)
{
if (!CheckModelThingIndex(iModelThing))
{
TraceError("CGraphicThingInstance::RegisterModelThing(iModelThing=%d, pModelThing=%s)\n", iModelThing, pModelThing->GetFileName());
return;
}
m_modelThingSetVector[iModelThing].Clear();
if (pModelThing)
RegisterLODThing(iModelThing, pModelThing);
}
void CGraphicThingInstance::RegisterLODThing(int iModelThing, CGraphicThing * pModelThing)
{
assert(CheckModelThingIndex(iModelThing));
CGraphicThing::TRef * pModelRef = new CGraphicThing::TRef;
pModelRef->SetPointer(pModelThing);
m_modelThingSetVector[iModelThing].m_pLODThingRefVector.push_back(pModelRef);
}
void CGraphicThingInstance::RegisterMotionThing(DWORD dwMotionKey, CGraphicThing* pMotionThing)
{
CGraphicThing::TRef * pMotionRef = new CGraphicThing::TRef;
pMotionRef->SetPointer(pMotionThing);
m_roMotionThingMap.insert(std::map<DWORD, CGraphicThing::TRef *>::value_type(dwMotionKey, pMotionRef));
}
void CGraphicThingInstance::ResetLocalTime()
{
//m_clockLast = GrannyGetSystemSeconds();
m_fLastLocalTime = 0.0f;
m_fLocalTime = 0.0f;
CGrannyLODController::FResetLocalTime resetLocalTime;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), resetLocalTime);
}
/*
void CGraphicThingInstance::SetMotionSpeed(float fRate)
{
m_fMotionTimeSpeed = fRate;
}
*/
void CGraphicThingInstance::InsertDelay(float fDelay)
{
m_fDelay = fDelay;
}
float CGraphicThingInstance::GetLastLocalTime()
{
return m_fLastLocalTime;
}
float CGraphicThingInstance::GetLocalTime()
{
return m_fLocalTime;
}
float CGraphicThingInstance::GetSecondElapsed()
{
return m_fSecondElapsed;
}
float CGraphicThingInstance::GetAverageSecondElapsed()
{
return m_fAverageSecondElapsed;
}
bool CGraphicThingInstance::Intersect(float* pu, float* pv, float* pt)
{
if (!CGraphicObjectInstance::isShow())
return false;
if (!m_bUpdated)
return false;
if (m_LODControllerVector.empty())
{
//TraceError("CGraphicThingInstance::Intersect - m_LODControllerVector is empty");
return false;
}
return m_LODControllerVector[0]->Intersect(&GetTransform(), pu, pv, pt);
}
void CGraphicThingInstance::GetBoundBox(D3DXVECTOR3* vtMin, D3DXVECTOR3* vtMax)
{
vtMin->x = vtMin->y = vtMin->z = 100000.0f;
vtMax->x = vtMax->y = vtMax->z = -100000.0f;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), CGrannyLODController::FBoundBox(vtMin, vtMax));
}
BOOL CGraphicThingInstance::GetBoundBox(DWORD dwModelInstanceIndex, D3DXVECTOR3 * vtMin, D3DXVECTOR3 * vtMax)
{
if (!CheckModelInstanceIndex(dwModelInstanceIndex))
return FALSE;
vtMin->x = vtMin->y = vtMin->z = 100000.0f;
vtMax->x = vtMax->y = vtMax->z = -100000.0f;
CGrannyLODController * pController = m_LODControllerVector[dwModelInstanceIndex];
if (!pController->isModelInstance())
return FALSE;
CGrannyModelInstance * pModelInstance = pController->GetModelInstance();
pModelInstance->GetBoundBox(vtMin, vtMax);
return TRUE;
}
BOOL CGraphicThingInstance::GetBoneMatrix(DWORD dwModelInstanceIndex, DWORD dwBoneIndex, D3DXMATRIX ** ppMatrix)
{
if (!CheckModelInstanceIndex(dwModelInstanceIndex))
return FALSE;
CGrannyModelInstance * pModelInstance = m_LODControllerVector[dwModelInstanceIndex]->GetModelInstance();
if (!pModelInstance)
return FALSE;
*ppMatrix = (D3DXMATRIX *)pModelInstance->GetBoneMatrixPointer(dwBoneIndex);
if (!*ppMatrix)
return FALSE;
return TRUE;
}
BOOL CGraphicThingInstance::GetCompositeBoneMatrix(DWORD dwModelInstanceIndex, DWORD dwBoneIndex, D3DXMATRIX ** ppMatrix)
{
if (!CheckModelInstanceIndex(dwModelInstanceIndex))
return FALSE;
CGrannyModelInstance * pModelInstance = m_LODControllerVector[dwModelInstanceIndex]->GetModelInstance();
if (!pModelInstance)
{
//TraceError("CGraphicThingInstance::GetCompositeBoneMatrix(dwModelInstanceIndex=%d, dwBoneIndex=%d, D3DXMATRIX ** ppMatrix)", dwModelInstanceIndex, dwBoneIndex);
return FALSE;
}
*ppMatrix = (D3DXMATRIX *)pModelInstance->GetCompositeBoneMatrixPointer(dwBoneIndex);
return TRUE;
}
void CGraphicThingInstance::UpdateTransform(D3DXMATRIX * pMatrix, float fSecondsElapsed, int iModelInstanceIndex)
{
//TraceError("%s",GetBaseThingPtr()->GetFileName());
int nLODCount=m_LODControllerVector.size();
if (iModelInstanceIndex>=nLODCount)
{
//TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d)",
// fSecondsElapsed, iModelInstanceIndex, nLODCount);
return;
}
CGrannyLODController* pkLODCtrl=m_LODControllerVector[iModelInstanceIndex];
if (!pkLODCtrl)
{
//TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d) - m_LODControllerVector[iModelInstanceIndex] == NULL",
// fSecondsElapsed, iModelInstanceIndex, nLODCount);
return;
}
CGrannyModelInstance * pModelInstance = pkLODCtrl->GetModelInstance();
if (!pModelInstance)
{
/* TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d) - pkLODCtrl->GetModelInstance() == NULL",
fSecondsElapsed, iModelInstanceIndex, nLODCount);*/
return;
}
pModelInstance->UpdateTransform(pMatrix, fSecondsElapsed);
}
void CGraphicThingInstance::DeformAll()
{
m_bUpdated = true;
CGrannyLODController::FDeformAll deform;
deform.mc_pWorldMatrix = &m_worldMatrix;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), deform);
}
void CGraphicThingInstance::DeformNoSkin()
{
m_bUpdated = true;
std::vector<CGrannyLODController*>::iterator i;
for (i=m_LODControllerVector.begin(); i!=m_LODControllerVector.end(); ++i)
{
CGrannyLODController* pkLOD=*i;
if (pkLOD->isModelInstance())
pkLOD->DeformNoSkin(&m_worldMatrix);
}
}
void CGraphicThingInstance::OnDeform()
{
m_bUpdated = true;
CGrannyLODController::FDeform deform;
deform.mc_pWorldMatrix = &m_worldMatrix;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), deform);
}
void CGraphicThingInstance::__SetLocalTime(float fLocalTime)
{
m_fLastLocalTime = m_fLocalTime;
m_fLocalTime = fLocalTime;
CGrannyLODController::FSetLocalTime SetLocalTime;
SetLocalTime.fLocalTime = fLocalTime;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), SetLocalTime);
}
void CGraphicThingInstance::UpdateLODLevel()
{
CCamera * pcurCamera = CCameraManager::Instance().GetCurrentCamera();
if (!pcurCamera)
{
TraceError("CGraphicThingInstance::UpdateLODLevel - GetCurrentCamera() == NULL");
return;
}
const D3DXVECTOR3 & c_rv3TargetPosition = pcurCamera->GetTarget();
const D3DXVECTOR3 & c_rv3CameraPosition = pcurCamera->GetEye();
const D3DXVECTOR3 & c_v3Position = GetPosition();
// NOTE : 중심으로부터의 거리 계산에 z값 차이는 사용하지 않는다. - [levites]
CGrannyLODController::FUpdateLODLevel update;
update.fDistanceFromCenter = sqrtf((c_rv3TargetPosition.x - c_v3Position.x) * (c_rv3TargetPosition.x - c_v3Position.x) +
(c_rv3TargetPosition.y - c_v3Position.y) * (c_rv3TargetPosition.y - c_v3Position.y));
update.fDistanceFromCamera = sqrtf((c_rv3CameraPosition.x - c_v3Position.x) * (c_rv3CameraPosition.x - c_v3Position.x) +
(c_rv3CameraPosition.y - c_v3Position.y) * (c_rv3CameraPosition.y - c_v3Position.y) +
(c_rv3CameraPosition.z - c_v3Position.z) * (c_rv3CameraPosition.z - c_v3Position.z));
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), update);
}
void CGraphicThingInstance::UpdateTime()
{
//granny_system_clock clockNow = GrannyGetSystemSeconds();
//m_fSecondElapsed = GrannyGetSecondsElapsed(&m_clockLast, &clockNow) * m_fMotionTimeSpeed;
//DWORD t1=ELTimer_GetMSec();
m_fSecondElapsed=CTimer::Instance().GetElapsedSecond();
if (m_fDelay > m_fSecondElapsed)
{
m_fDelay -= m_fSecondElapsed;
m_fSecondElapsed = 0.0f;
}
else
{
m_fSecondElapsed -= m_fDelay;
m_fDelay = 0.0f;
}
m_fLastLocalTime = m_fLocalTime;
m_fLocalTime += m_fSecondElapsed;
m_fAverageSecondElapsed = m_fAverageSecondElapsed + (m_fSecondElapsed - m_fAverageSecondElapsed) / 4.0f;
//m_clockLast = clockNow;
CGrannyLODController::FUpdateTime update;
update.fElapsedTime = m_fSecondElapsed;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), update);
}
void CGraphicThingInstance::OnUpdate()
{
#ifdef __PERFORMANCE_CHECKER__
DWORD t1=timeGetTime();
#endif
UpdateLODLevel();
#ifdef __PERFORMANCE_CHECKER__
DWORD t2=timeGetTime();
#endif
UpdateTime();
#ifdef __PERFORMANCE_CHECKER__
DWORD t3=timeGetTime();
#endif
#ifdef __PERFORMANCE_CHECKER__
{
static FILE* fp=fopen("perf_thing_onupdate.txt", "w");
if (t3-t1>3)
{
fprintf(fp, "GTU.Total %d (Time %f)\n",
t3-t1, ELTimer_GetMSec()/1000.0f);
fprintf(fp, "GTU.CAL %d\n", t2-t1);
fprintf(fp, "GTU.UP %d\n", t3-t2);
fprintf(fp, "-------------------------------- \n");
fflush(fp);
}
fflush(fp);
}
#endif
}
void CGraphicThingInstance::OnRender()
{
RenderWithOneTexture();
}
void CGraphicThingInstance::OnBlendRender()
{
BlendRenderWithOneTexture();
}
void CGraphicThingInstance::RenderWithOneTexture()
{
//assert(m_bUpdated);
if (!m_bUpdated)
return;
CGrannyLODController::FRenderWithOneTexture render;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), render);
}
void CGraphicThingInstance::BlendRenderWithOneTexture()
{
//assert(m_bUpdated);
if (!m_bUpdated)
return;
CGrannyLODController::FBlendRenderWithOneTexture blendRender;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), blendRender);
}
void CGraphicThingInstance::RenderWithTwoTexture()
{
//assert(m_bUpdated);
if (!m_bUpdated)
return;
CGrannyLODController::FRenderWithTwoTexture render;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), render);
}
void CGraphicThingInstance::BlendRenderWithTwoTexture()
{
//assert(m_bUpdated);
if (!m_bUpdated)
return;
CGrannyLODController::FRenderWithTwoTexture blendRender;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), blendRender);
}
void CGraphicThingInstance::OnRenderToShadowMap()
{
if (!m_bUpdated)
return;
CGrannyLODController::FRenderToShadowMap RenderToShadowMap;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderToShadowMap);
}
void CGraphicThingInstance::OnRenderShadow()
{
CGrannyLODController::FRenderShadow RenderShadow;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderShadow);
}
void CGraphicThingInstance::OnRenderPCBlocker()
{
CGrannyLODController::FRenderWithOneTexture RenderPCBlocker;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderPCBlocker);
}
DWORD CGraphicThingInstance::GetLODControllerCount() const
{
return m_LODControllerVector.size();
}
CGrannyLODController * CGraphicThingInstance::GetLODControllerPointer(DWORD dwModelIndex) const
{
assert(dwModelIndex < m_LODControllerVector.size());
return m_LODControllerVector[dwModelIndex];
}
CGrannyLODController * CGraphicThingInstance::GetLODControllerPointer(DWORD dwModelIndex)
{
assert(dwModelIndex < m_LODControllerVector.size());
return m_LODControllerVector[dwModelIndex];
}
BYTE CGraphicThingInstance::GetLODLevel(DWORD dwModelInstance)
{
assert(dwModelInstance < m_LODControllerVector.size());
return (m_LODControllerVector[dwModelInstance]->GetLODLevel());
}
float CGraphicThingInstance::GetHeight()
{
if (m_LODControllerVector.empty())
return 0.0f;
CGrannyModelInstance * pModelInstance = m_LODControllerVector[0]->GetModelInstance();
if (!pModelInstance)
return 0.0f;
D3DXVECTOR3 vtMin, vtMax;
pModelInstance->GetBoundBox(&vtMin, &vtMax);
return fabs(vtMin.z - vtMax.z);
}
void CGraphicThingInstance::ReloadTexture()
{
CGrannyLODController::FReloadTexture ReloadTexture;
std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), ReloadTexture);
}
bool CGraphicThingInstance::HaveBlendThing()
{
for (int i = 0; i < m_LODControllerVector.size(); i++)
{
if (m_LODControllerVector[i]->HaveBlendThing())
return true;
}
return false;
}
void CGraphicThingInstance::OnClear()
{
stl_wipe(m_LODControllerVector);
stl_wipe_second(m_roMotionThingMap);
for (DWORD d = 0; d < m_modelThingSetVector.size(); ++d)
m_modelThingSetVector[d].Clear();
}
void CGraphicThingInstance::OnInitialize()
{
m_bUpdated = false;
m_fLastLocalTime = 0.0f;
m_fLocalTime = 0.0f;
m_fDelay = 0.0;
m_fSecondElapsed = 0.0f;
m_fAverageSecondElapsed = 0.03f;
m_fRadius = -1.0f;
m_v3Center = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
ResetLocalTime();
}
CGraphicThingInstance::CGraphicThingInstance()
{
Initialize();
}
CGraphicThingInstance::~CGraphicThingInstance()
{
}
+55
View File
@@ -0,0 +1,55 @@
#include "StdAfx.h"
#include "Util.h"
/*
bool GrannyMeshGetTextureAnimation(granny_mesh* pgrnMesh, float* puVelocity, float* pvVelocity)
{
static granny_data_type_definition s_UVType[] =
{
{GrannyInt32Member, "UV Animation Flag"},
{GrannyInt32Member, "X Velocity"},
{GrannyInt32Member, "Y Velocity"},
{GrannyEndMember}
};
typedef struct SUVData
{
granny_int32 UVAnimationFlag;
granny_int32 xVelocity;
granny_int32 yVelocity;
} TUVData;
TUVData UVData;
granny_variant& rExtendedData = pgrnMesh->ExtendedData;
GrannyConvertSingleObject(rExtendedData.Type, rExtendedData.Object, s_UVType, &UVData);
*puVelocity = float(UVData.xVelocity) / 100000.0f;
*pvVelocity = float(UVData.yVelocity) / 100000.0f;
return UVData.UVAnimationFlag ? true : false;
}
*/
/*
bool GrannyMeshIsTextureAnimation(granny_mesh* pgrnMesh)
{
if (GrannyMeshIsRigid(pgrnMesh))
{
float xVelocity, yVelocity;
if (GrannyMeshGetTextureAnimation(pgrnMesh, &xVelocity, &yVelocity))
return true;
}
return false;
}
*/
bool GrannyMeshIsDeform(granny_mesh* pgrnMesh)
{
if (GrannyMeshIsRigid(pgrnMesh))
return false;
return true;
}
@@ -0,0 +1,840 @@
#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 : 거리가 가까워 졌을때만.. - [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
{
const auto _vv__ = (s.v3Position - m_attribute.v3Position);
if (D3DXVec3LengthSq(&_vv__)>=(s.fRadius+m_attribute.fRadius)*(m_attribute.fRadius+s.fRadius))
return D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXVECTOR3 c;
const auto _vv__2 = (s.v3Position - s.v3LastPosition);
const auto _vv_s_2 = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
D3DXVec3Cross(&c, &_vv__2, &_vv_s_2);
float sum = - D3DXVec3Dot(&c,&_vv__);
float mul = (s.fRadius+m_attribute.fRadius)*(s.fRadius+m_attribute.fRadius)-D3DXVec3LengthSq(&_vv__);
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 : 거리가 가까워 졌을때만.. - [levites]
const auto _vv__3 = (s.v3Position - m_attribute.v3Position);
const auto _vv__4 = (s.v3LastPosition - m_attribute.v3Position);
if (fabs(D3DXVec3Dot(&_vv__3, &m_attribute.v3Normal)) <
fabs(D3DXVec3Dot(&_vv__4, &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);
const auto vv = (s.v3Position - m_attribute.v3Position);
float t= - D3DXVec3Dot(&m_attribute.v3Normal, &vv)/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);
const auto vv = (oa - ob);
return (D3DXVec3LengthSq(&vv)<=(c_rattribute.fRadius+s.fRadius)*(c_rattribute.fRadius+s.fRadius));
}
bool CCylinderCollisionInstance::OnMovementCollisionDynamicSphere(const CDynamicSphereInstance & s) const
{
if (CollideCylinderVSDynamicSphere(m_attribute, s))
{
// NOTE : 거리가 가까워 졌을때만.. - [levites]
if (GetVector3Distance(s.v3Position, m_attribute.v3Position) <
GetVector3Distance(s.v3LastPosition, m_attribute.v3Position))
return true;
}
// NOTE : 이동 거리가 클 경우 빈틈없이 (원 크기 단위로) 이동하면서 전부 체크 해 본다 - [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;
const auto vv = (s.v3Position - v3Position);
if (D3DXVec3LengthSq(&vv)>=(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;
const auto vssa = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
D3DXVec3Cross(&c, &advance, &vssa);
const auto svsvs = (s.v3Position - v3Position);
float sum = - D3DXVec3Dot(&c,&svsvs);
float mul = (s.fRadius+m_attribute.fRadius)*(s.fRadius+m_attribute.fRadius)-D3DXVec3LengthSq(&svsvs);
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; }
const auto vv = (v3Temp - s.v3Position);
if(D3DXVec3LengthSq(&vv) < 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);
}
@@ -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()
{
}
@@ -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];
}
+41
View File
@@ -302,6 +302,33 @@ typedef enum _D3DTEXTURESTAGESTATETYPE
D3DTSS_FORCE_DWORD = 0x7fffffff,
} D3DTEXTURESTAGESTATETYPE;
// D3D8 texture coordinate generation, transform flags and addressing (d3d8types.h).
enum : DWORD {
D3DTSS_TCI_PASSTHRU = 0x00000000,
D3DTSS_TCI_CAMERASPACENORMAL = 0x00010000,
D3DTSS_TCI_CAMERASPACEPOSITION = 0x00020000,
D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR = 0x00030000,
};
typedef enum _D3DTEXTURETRANSFORMFLAGS
{
D3DTTFF_DISABLE = 0,
D3DTTFF_COUNT1 = 1,
D3DTTFF_COUNT2 = 2,
D3DTTFF_COUNT3 = 3,
D3DTTFF_COUNT4 = 4,
D3DTTFF_PROJECTED = 256,
D3DTTFF_FORCE_DWORD = 0x7fffffff,
} D3DTEXTURETRANSFORMFLAGS;
typedef enum _D3DTEXTUREADDRESS
{
D3DTADDRESS_WRAP = 1,
D3DTADDRESS_MIRROR = 2,
D3DTADDRESS_CLAMP = 3,
D3DTADDRESS_BORDER = 4,
D3DTADDRESS_MIRRORONCE = 5,
D3DTADDRESS_FORCE_DWORD = 0x7fffffff,
} D3DTEXTUREADDRESS;
// D3D8 texture-stage arguments (d3d8types.h D3DTA_*).
enum : DWORD {
D3DTA_SELECTMASK = 0x0000000f,
@@ -386,6 +413,20 @@ typedef enum _D3DCULL {
#define D3DTS_WORLD1 D3DTS_WORLDMATRIX(1)
#define D3DTS_WORLD2 D3DTS_WORLDMATRIX(2)
#define D3DTS_WORLD3 D3DTS_WORLDMATRIX(3)
#define D3DUSAGE_RENDERTARGET 0x00000001L
#define D3DUSAGE_DEPTHSTENCIL 0x00000002L
#define D3DUSAGE_WRITEONLY 0x00000008L
#define D3DUSAGE_SOFTWAREPROCESSING 0x00000010L
#define D3DUSAGE_DONOTCLIP 0x00000020L
#define D3DUSAGE_POINTS 0x00000040L
#define D3DUSAGE_RTPATCHES 0x00000080L
#define D3DUSAGE_NPATCHES 0x00000100L
#define D3DUSAGE_DYNAMIC 0x00000200L
#define D3DLOCK_READONLY 0x00000010L
#define D3DLOCK_DISCARD 0x00002000L
#define D3DLOCK_NOOVERWRITE 0x00001000L
#define D3DLOCK_NOSYSLOCK 0x00000800L
#define D3DLOCK_NO_DIRTY_UPDATE 0x00008000L
#define D3DFVF_RESERVED0 0x001
#define D3DFVF_POSITION_MASK 0x00E
#define D3DFVF_XYZ 0x002
+11
View File
@@ -79,6 +79,17 @@ D3DXVECTOR4* D3DXVec3Transform(D3DXVECTOR4* pOut, const D3DXVECTOR3* pV, const D
return pOut;
}
D3DXVECTOR4* D3DXVec4Transform(D3DXVECTOR4* pOut, const D3DXVECTOR4* pV, const D3DXMATRIX* pM)
{
D3DXVECTOR4 out;
out.x = pM->m[0][0] * pV->x + pM->m[1][0] * pV->y + pM->m[2][0] * pV->z + pM->m[3][0] * pV->w;
out.y = pM->m[0][1] * pV->x + pM->m[1][1] * pV->y + pM->m[2][1] * pV->z + pM->m[3][1] * pV->w;
out.z = pM->m[0][2] * pV->x + pM->m[1][2] * pV->y + pM->m[2][2] * pV->z + pM->m[3][2] * pV->w;
out.w = pM->m[0][3] * pV->x + pM->m[1][3] * pV->y + pM->m[2][3] * pV->z + pM->m[3][3] * pV->w;
*pOut = out;
return pOut;
}
D3DXVECTOR3* D3DXVec3TransformCoord(D3DXVECTOR3* pOut, const D3DXVECTOR3* pV, const D3DXMATRIX* pM)
{
const FLOAT norm = pM->m[0][3] * pV->x + pM->m[1][3] * pV->y + pM->m[2][3] * pV->z + pM->m[3][3];
+1
View File
@@ -335,6 +335,7 @@ D3DXVECTOR3* D3DXVec3Normalize(D3DXVECTOR3* pOut, const D3DXVECTOR3* pV);
D3DXVECTOR4* D3DXVec3Transform(D3DXVECTOR4* pOut, const D3DXVECTOR3* pV, const D3DXMATRIX* pM);
D3DXVECTOR3* D3DXVec3TransformCoord(D3DXVECTOR3* pOut, const D3DXVECTOR3* pV, const D3DXMATRIX* pM);
D3DXVECTOR3* D3DXVec3TransformNormal(D3DXVECTOR3* pOut, const D3DXVECTOR3* pV, const D3DXMATRIX* pM);
D3DXVECTOR4* D3DXVec4Transform(D3DXVECTOR4* pOut, const D3DXVECTOR4* pV, const D3DXMATRIX* pM);
// --- D3DXMATRIX ---
inline D3DXMATRIX* D3DXMatrixIdentity(D3DXMATRIX* pOut)
+358 -4
View File
@@ -1,7 +1,8 @@
#pragma once
// Shim for RAD Granny 2.11 <granny.h> (40250 extern/include): the scalar types and structs that
// EterGrnLib headers name, with the SDK's layout; every other Granny object is opaque. Loading and
// skinning go through platform/ (backed by libgr2), never through these declarations.
// Shim for RAD Granny 2.11 <granny.h> (40250 extern/include): the scalar types, the public data structs
// EterGrnLib reads (SDK field names and order) and the functions it calls. The file-data structs are
// built from libgr2 and the runtime objects (file, model instance, control, pose, binding, deformer)
// stay opaque; both live in platform/EterGrnLib/GrannyRuntime.cpp.
#include <stdint.h>
typedef uint32_t granny_uint32;
@@ -11,10 +12,14 @@ typedef int16_t granny_int16;
typedef uint8_t granny_uint8;
typedef int8_t granny_int8;
typedef float granny_real32;
typedef double granny_real64x;
typedef granny_uint32 granny_bool32;
typedef granny_int32 granny_int32x;
typedef granny_uint32 granny_uint32x;
typedef uintptr_t granny_uintaddrx;
typedef granny_real32 granny_triple[3];
typedef granny_real32 granny_quad[4];
typedef granny_real32 granny_matrix_4x4[4][4];
typedef enum granny_member_type
{
@@ -46,6 +51,76 @@ typedef enum granny_member_type
Grannymember_type_forceint = 0x7fffffff
} granny_member_type;
typedef enum granny_material_texture_type
{
GrannyUnknownTextureType,
GrannyAmbientColorTexture,
GrannyDiffuseColorTexture,
GrannySpecularColorTexture,
GrannySelfIlluminationTexture,
GrannyOpacityTexture,
GrannyBumpHeightTexture,
GrannyReflectionTexture,
GrannyRefractionTexture,
GrannyDisplacementTexture,
GrannyOnePastLastMaterialTextureType,
Grannymaterial_texture_type_forceint = 0x7fffffff
} granny_material_texture_type;
typedef enum granny_deformation_type
{
GrannyDeformPosition = 1,
GrannyDeformPositionNormal,
GrannyDeformPositionNormalTangent,
GrannyDeformPositionNormalTangentBinormal,
Grannydeformation_type_forceint = 0x7fffffff
} granny_deformation_type;
typedef enum granny_deformer_tail_flags
{
GrannyDontAllowUncopiedTail,
GrannyAllowUncopiedTail,
GrannyAllowUninitializedDestTail,
Grannydeformer_tail_flags_forceint = 0x7fffffff
} granny_deformer_tail_flags;
typedef enum granny_standard_section_index
{
GrannyStandardMainSection = 0,
GrannyStandardRigidVertexSection = 1,
GrannyStandardRigidIndexSection = 2,
GrannyStandardDeformableVertexSection = 3,
GrannyStandardDeformableIndexSection = 4,
GrannyStandardTextureSection = 5,
GrannyStandardDiscardableSection = 6,
GrannyStandardUnloadedSection = 7,
GrannyStandardSectionCount = 8,
Grannystandard_section_index_forceint = 0x7fffffff
} granny_standard_section_index;
typedef enum granny_log_message_type
{
GrannyIgnoredLogMessage,
GrannyNoteLogMessage,
GrannyWarningLogMessage,
GrannyErrorLogMessage,
GrannyOnePastLastMessageType,
Grannylog_message_type_forceint = 0x7fffffff
} granny_log_message_type;
typedef granny_int32 granny_log_message_origin;
#define GrannyVertexPositionName "Position"
#define GrannyVertexNormalName "Normal"
#define GrannyVertexTangentName "Tangent"
#define GrannyVertexBinormalName "Binormal"
#define GrannyVertexTangentBinormalCrossName "TangentBinormalCross"
#define GrannyVertexBoneWeightsName "BoneWeights"
#define GrannyVertexBoneIndicesName "BoneIndices"
#define GrannyVertexDiffuseColorName "DiffuseColor"
#define GrannyVertexSpecularColorName "SpecularColor"
#define GrannyVertexTextureCoordinatesName "TextureCoordinates"
#define GrannyVertexMorphCurvePrefix "VertexMorphCurve"
struct granny_data_type_definition
{
granny_member_type Type;
@@ -57,9 +132,10 @@ struct granny_data_type_definition
};
struct granny_animation;
struct granny_bone;
struct granny_control;
struct granny_file;
struct granny_file_info;
struct granny_local_pose;
struct granny_material;
struct granny_mesh;
struct granny_mesh_binding;
@@ -67,4 +143,282 @@ struct granny_mesh_deformer;
struct granny_model;
struct granny_model_instance;
struct granny_skeleton;
struct granny_texture;
struct granny_world_pose;
struct granny_conversion_handler;
struct granny_variant
{
granny_data_type_definition* Type;
void* Object;
};
struct granny_transform
{
granny_uint32 Flags;
granny_triple Position;
granny_quad Orientation;
granny_triple ScaleShear[3];
};
struct granny_texture
{
char const* FromFileName;
granny_int32 TextureType;
granny_int32 Width;
granny_int32 Height;
granny_int32 Encoding;
granny_int32 SubFormat;
granny_variant ExtendedData;
};
struct granny_material_map
{
char const* Usage;
granny_material* Material;
};
struct granny_material
{
char const* Name;
granny_int32 MapCount;
granny_material_map* Maps;
granny_texture* Texture;
granny_variant ExtendedData;
};
struct granny_bone
{
char const* Name;
granny_int32 ParentIndex;
granny_transform LocalTransform;
granny_matrix_4x4 InverseWorld4x4;
granny_real32 LODError;
granny_variant ExtendedData;
};
struct granny_skeleton
{
char const* Name;
granny_int32 BoneCount;
granny_bone* Bones;
granny_int32 LODType;
granny_variant ExtendedData;
};
struct granny_vertex_data
{
granny_data_type_definition* VertexType;
granny_int32 VertexCount;
granny_uint8* Vertices;
granny_int32 VertexComponentNameCount;
char const** VertexComponentNames;
};
struct granny_tri_material_group
{
granny_int32 MaterialIndex;
granny_int32 TriFirst;
granny_int32 TriCount;
};
struct granny_tri_topology
{
granny_int32 GroupCount;
granny_tri_material_group* Groups;
granny_int32 IndexCount;
granny_int32* Indices;
granny_int32 Index16Count;
granny_uint16* Indices16;
};
struct granny_material_binding
{
granny_material* Material;
};
struct granny_bone_binding
{
char const* BoneName;
granny_triple OBBMin;
granny_triple OBBMax;
granny_int32 TriangleCount;
granny_int32* TriangleIndices;
};
struct granny_mesh
{
char const* Name;
granny_vertex_data* PrimaryVertexData;
granny_int32 MorphTargetCount;
void* MorphTargets;
granny_tri_topology* PrimaryTopology;
granny_int32 MaterialBindingCount;
granny_material_binding* MaterialBindings;
granny_int32 BoneBindingCount;
granny_bone_binding* BoneBindings;
granny_variant ExtendedData;
};
struct granny_model_mesh_binding
{
granny_mesh* Mesh;
};
struct granny_model
{
char const* Name;
granny_skeleton* Skeleton;
granny_transform InitialPlacement;
granny_int32 MeshBindingCount;
granny_model_mesh_binding* MeshBindings;
granny_variant ExtendedData;
};
struct granny_text_track_entry
{
granny_real32 TimeStamp;
char const* Text;
};
struct granny_text_track
{
char const* Name;
granny_int32 EntryCount;
granny_text_track_entry* Entries;
};
struct granny_track_group
{
char const* Name;
granny_int32 TextTrackCount;
granny_text_track* TextTracks;
granny_transform InitialPlacement;
granny_int32 Flags;
granny_variant ExtendedData;
};
struct granny_animation
{
char const* Name;
granny_real32 Duration;
granny_real32 TimeStep;
granny_real32 Oversampling;
granny_int32 TrackGroupCount;
granny_track_group** TrackGroups;
granny_int32 DefaultLoopCount;
granny_int32 Flags;
granny_variant ExtendedData;
};
struct granny_file_info
{
char const* FromFileName;
granny_int32 TextureCount;
granny_texture** Textures;
granny_int32 MaterialCount;
granny_material** Materials;
granny_int32 SkeletonCount;
granny_skeleton** Skeletons;
granny_int32 MeshCount;
granny_mesh** Meshes;
granny_int32 ModelCount;
granny_model** Models;
granny_int32 AnimationCount;
granny_animation** Animations;
granny_variant ExtendedData;
};
struct granny_system_clock
{
granny_uint32 Data[4];
};
typedef void granny_log_function(granny_log_message_type Type, granny_log_message_origin Origin,
char const* File, granny_int32x Line, char const* Message, void* UserData);
struct granny_log_callback
{
granny_log_function* Function;
void* UserData;
};
extern granny_data_type_definition* GrannyPNT332VertexType;
// Files
granny_file* GrannyReadEntireFileFromMemory(granny_int32x MemorySize, void const* Memory);
granny_file_info* GrannyGetFileInfo(granny_file* File);
void GrannyFreeFile(granny_file* File);
void GrannyFreeFileSection(granny_file* File, granny_int32x SectionIndex);
void GrannySetLogCallback(granny_log_callback const* LogCallback);
// Data types
granny_int32x GrannyGetTotalTypeSize(granny_data_type_definition const* TypeDefinition);
bool GrannyFindMatchingMember(granny_data_type_definition const* SourceType, void const* SourceObject,
char const* DestMemberName, granny_variant* Result);
void GrannyConvertSingleObject(granny_data_type_definition const* SourceType, void const* SourceObject,
granny_data_type_definition const* DestType, void* DestObject,
granny_conversion_handler* OverrideHandler);
// Materials, skeletons, meshes
granny_texture* GrannyGetMaterialTextureByType(granny_material const* Material, granny_material_texture_type Type);
bool GrannyFindBoneByName(granny_skeleton const* Skeleton, char const* BoneName, granny_int32x* BoneIndex);
bool GrannyMeshIsRigid(granny_mesh const* Mesh);
granny_int32x GrannyGetMeshVertexCount(granny_mesh const* Mesh);
granny_data_type_definition* GrannyGetMeshVertexType(granny_mesh const* Mesh);
void* GrannyGetMeshVertices(granny_mesh const* Mesh);
void GrannyCopyMeshVertices(granny_mesh const* Mesh, granny_data_type_definition const* VertexType, void* DestVertices);
granny_int32x GrannyGetMeshIndexCount(granny_mesh const* Mesh);
void GrannyCopyMeshIndices(granny_mesh const* Mesh, granny_int32x BytesPerIndex, void* DestIndices);
granny_int32x GrannyGetMeshTriangleGroupCount(granny_mesh const* Mesh);
granny_tri_material_group* GrannyGetMeshTriangleGroups(granny_mesh const* Mesh);
// Mesh binding and deformation
granny_mesh_binding* GrannyNewMeshBinding(granny_mesh const* Mesh, granny_skeleton const* FromSkeleton, granny_skeleton const* ToSkeleton);
void GrannyFreeMeshBinding(granny_mesh_binding* Binding);
granny_int32x const* GrannyGetMeshBindingToBoneIndices(granny_mesh_binding const* Binding);
granny_mesh_deformer* GrannyNewMeshDeformer(granny_data_type_definition const* InputVertexLayout,
granny_data_type_definition const* OutputVertexLayout,
granny_deformation_type DeformationType, granny_deformer_tail_flags TailFlag);
void GrannyFreeMeshDeformer(granny_mesh_deformer* Deformer);
void GrannyDeformVertices(granny_mesh_deformer const* Deformer, granny_int32x const* MatrixIndices,
granny_real32 const* MatrixBuffer4x4, granny_int32x VertexCount,
void const* SourceVertices, void* DestVertices);
// Model instances and controls
granny_model_instance* GrannyInstantiateModel(granny_model const* Model);
void GrannyFreeModelInstance(granny_model_instance* ModelInstance);
granny_skeleton* GrannyGetSourceSkeleton(granny_model_instance const* Model);
void GrannySetModelClock(granny_model_instance const* ModelInstance, granny_real32 NewClock);
void GrannyFreeCompletedModelControls(granny_model_instance const* ModelInstance);
void GrannyUpdateModelMatrix(granny_model_instance const* ModelInstance, granny_real32 SecondsElapsed,
granny_real32 const* ModelMatrix4x4, granny_real32* DestMatrix4x4, bool Inverse);
granny_control* GrannyPlayControlledAnimation(granny_real32 StartTime, granny_animation const* Animation, granny_model_instance* Model);
void GrannyFreeControl(granny_control* Control);
void GrannyFreeControlOnceUnused(granny_control* Control);
bool GrannyFreeControlIfComplete(granny_control* Control);
bool GrannyControlIsComplete(granny_control const* Control);
void GrannyCompleteControlAt(granny_control* Control, granny_real32 AtSeconds);
void GrannySetControlSpeed(granny_control* Control, granny_real32 Speed);
granny_real32 GrannyGetControlSpeed(granny_control const* Control);
void GrannySetControlLoopCount(granny_control* Control, granny_int32x LoopCount);
granny_int32x GrannyGetControlLoopCount(granny_control const* Control);
void GrannySetControlRawLocalClock(granny_control* Control, granny_real32 LocalClock);
granny_real32 GrannyGetControlRawLocalClock(granny_control* Control);
granny_real32 GrannyGetControlLocalDuration(granny_control const* Control);
void GrannySetControlEaseIn(granny_control* Control, bool EaseIn);
void GrannySetControlEaseOut(granny_control* Control, bool EaseOut);
void GrannySetControlEaseInCurve(granny_control* Control, granny_real32 StartSeconds, granny_real32 EndSeconds,
granny_real32 StartValue, granny_real32 StartTangent, granny_real32 EndTangent, granny_real32 EndValue);
void GrannySetControlEaseOutCurve(granny_control* Control, granny_real32 StartSeconds, granny_real32 EndSeconds,
granny_real32 StartValue, granny_real32 StartTangent, granny_real32 EndTangent, granny_real32 EndValue);
// Poses
granny_local_pose* GrannyNewLocalPose(granny_int32x BoneCount);
void GrannyFreeLocalPose(granny_local_pose* LocalPose);
granny_world_pose* GrannyNewWorldPose(granny_int32x BoneCount);
void GrannyFreeWorldPose(granny_world_pose* WorldPose);
void GrannySampleModelAnimationsAccelerated(granny_model_instance const* ModelInstance, granny_int32x BoneCount,
granny_real32 const* Offset4x4, granny_local_pose* Scratch, granny_world_pose* Result);
granny_real32* GrannyGetWorldPose4x4(granny_world_pose const* WorldPose, granny_int32x BoneIndex);
granny_real32* GrannyGetWorldPoseComposite4x4(granny_world_pose const* WorldPose, granny_int32x BoneIndex);
granny_matrix_4x4* GrannyGetWorldPoseComposite4x4Array(granny_world_pose const* WorldPose);