Loading MD3 and now we need to place models properly
This commit is contained in:
parent
e130c2ba7f
commit
329f1b1663
43
AnimatedModel.h
Normal file
43
AnimatedModel.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include "TextureManager.h"
|
||||||
|
|
||||||
|
namespace ZL
|
||||||
|
{
|
||||||
|
|
||||||
|
struct MeshGroup
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<Texture>> textures;
|
||||||
|
std::vector<VertexDataStruct> meshes;
|
||||||
|
std::vector<VertexRenderStruct> renderMeshes;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnimatedModel
|
||||||
|
{
|
||||||
|
std::vector<MeshGroup> parts;
|
||||||
|
|
||||||
|
void RefreshRenderMeshes()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < parts.size(); i++)
|
||||||
|
{
|
||||||
|
parts[i].renderMeshes.resize(parts[i].meshes.size());
|
||||||
|
|
||||||
|
for (int j = 0; j < parts[i].meshes.size(); j++)
|
||||||
|
{
|
||||||
|
parts[i].renderMeshes[j].AssignFrom(parts[i].meshes[j]);
|
||||||
|
parts[i].renderMeshes[j].RefreshVBO();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
7
Game.cpp
7
Game.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "AnimatedModel.h"
|
||||||
|
|
||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
@ -26,7 +27,7 @@ namespace ZL
|
|||||||
std::shared_ptr<Texture> pipeTexturePtr;
|
std::shared_ptr<Texture> pipeTexturePtr;
|
||||||
std::shared_ptr<Texture> gameOverTexturePtr;
|
std::shared_ptr<Texture> gameOverTexturePtr;
|
||||||
std::shared_ptr<Texture> testObjTexturePtr;
|
std::shared_ptr<Texture> testObjTexturePtr;
|
||||||
std::shared_ptr<Texture> md3TexturePtr;
|
//std::shared_ptr<Texture> md3TexturePtr;
|
||||||
|
|
||||||
VertexRenderStruct birdMesh;
|
VertexRenderStruct birdMesh;
|
||||||
|
|
||||||
@ -42,8 +43,8 @@ namespace ZL
|
|||||||
VertexDataStruct testObjMesh;
|
VertexDataStruct testObjMesh;
|
||||||
VertexRenderStruct testObjMeshMutable;
|
VertexRenderStruct testObjMeshMutable;
|
||||||
|
|
||||||
std::vector<VertexDataStruct> testmd3;
|
ZL::AnimatedModel testmd3;
|
||||||
std::vector<VertexRenderStruct> testmd3mutable;
|
//std::vector<VertexRenderStruct> testmd3mutable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
Game.h
9
Game.h
@ -4,6 +4,7 @@
|
|||||||
#include "Physics.h"
|
#include "Physics.h"
|
||||||
#include "TextureManager.h"
|
#include "TextureManager.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "AnimatedModel.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace ZL
|
namespace ZL
|
||||||
@ -98,7 +99,7 @@ namespace ZL
|
|||||||
extern std::shared_ptr<Texture> pipeTexturePtr;
|
extern std::shared_ptr<Texture> pipeTexturePtr;
|
||||||
extern std::shared_ptr<Texture> gameOverTexturePtr;
|
extern std::shared_ptr<Texture> gameOverTexturePtr;
|
||||||
extern std::shared_ptr<Texture> testObjTexturePtr;
|
extern std::shared_ptr<Texture> testObjTexturePtr;
|
||||||
extern std::shared_ptr<Texture> md3TexturePtr;
|
//extern std::shared_ptr<Texture> md3TexturePtr;
|
||||||
|
|
||||||
extern VertexRenderStruct birdMesh;
|
extern VertexRenderStruct birdMesh;
|
||||||
|
|
||||||
@ -113,7 +114,9 @@ namespace ZL
|
|||||||
extern VertexDataStruct testObjMesh;
|
extern VertexDataStruct testObjMesh;
|
||||||
extern VertexRenderStruct testObjMeshMutable;
|
extern VertexRenderStruct testObjMeshMutable;
|
||||||
|
|
||||||
extern std::vector<VertexDataStruct> testmd3;
|
|
||||||
extern std::vector<VertexRenderStruct> testmd3mutable;
|
extern ZL::AnimatedModel testmd3;
|
||||||
|
//extern std::vector<VertexDataStruct> testmd3;
|
||||||
|
//extern std::vector<VertexRenderStruct> testmd3mutable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,6 +158,7 @@
|
|||||||
<ClCompile Include="Utils.cpp" />
|
<ClCompile Include="Utils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="AnimatedModel.h" />
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Game.h" />
|
||||||
<ClInclude Include="Math.h" />
|
<ClInclude Include="Math.h" />
|
||||||
<ClInclude Include="md3test.h" />
|
<ClInclude Include="md3test.h" />
|
||||||
|
|||||||
@ -80,5 +80,8 @@
|
|||||||
<ClInclude Include="md3test.h">
|
<ClInclude Include="md3test.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="AnimatedModel.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
27
main.cpp
27
main.cpp
@ -13,8 +13,9 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
#include "AnimatedModel.h"
|
||||||
|
|
||||||
std::vector<ZL::VertexDataStruct> testLoadModel();
|
ZL::AnimatedModel testLoadModel();
|
||||||
|
|
||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
@ -140,16 +141,28 @@ namespace ZL
|
|||||||
renderer.EnableVertexAttribArray(vPositionName);
|
renderer.EnableVertexAttribArray(vPositionName);
|
||||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 6.0, static_cast<float>(Env::width) / static_cast<float>(Env::height), 1, 1000);
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 6.0, static_cast<float>(Env::width) / static_cast<float>(Env::height), 100, 100000);
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
|
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
renderer.TranslateMatrix({ 0,0, -300 });
|
renderer.TranslateMatrix({ 0,0, -30000 });
|
||||||
|
|
||||||
|
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 3.0));
|
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 3.0));
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < GameObjects::testmd3.parts.size(); i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int j = 0; j < GameObjects::testmd3.parts[i].renderMeshes.size(); j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, GameObjects::testmd3.parts[i].textures[0]->getTexID());
|
||||||
|
renderer.DrawVertexRenderStruct(GameObjects::testmd3.parts[i].renderMeshes[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
GameObjects::testObjMeshMutable.AssignFrom(GameObjects::testObjMesh);
|
GameObjects::testObjMeshMutable.AssignFrom(GameObjects::testObjMesh);
|
||||||
GameObjects::testObjMeshMutable.data.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundZ(gs.rotateTimer * M_PI / 3.0)));
|
GameObjects::testObjMeshMutable.data.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundZ(gs.rotateTimer * M_PI / 3.0)));
|
||||||
@ -162,10 +175,11 @@ namespace ZL
|
|||||||
//glBindTexture(GL_TEXTURE_2D, GameObjects::testObjTexturePtr->getTexID());
|
//glBindTexture(GL_TEXTURE_2D, GameObjects::testObjTexturePtr->getTexID());
|
||||||
//renderer.DrawVertexRenderStruct(GameObjects::testObjMeshMutable);
|
//renderer.DrawVertexRenderStruct(GameObjects::testObjMeshMutable);
|
||||||
|
|
||||||
|
/*
|
||||||
glBindTexture(GL_TEXTURE_2D, GameObjects::md3TexturePtr->getTexID());
|
glBindTexture(GL_TEXTURE_2D, GameObjects::md3TexturePtr->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(GameObjects::testmd3mutable[0]);
|
renderer.DrawVertexRenderStruct(GameObjects::testmd3mutable[0]);
|
||||||
renderer.DrawVertexRenderStruct(GameObjects::testmd3mutable[1]);
|
renderer.DrawVertexRenderStruct(GameObjects::testmd3mutable[1]);
|
||||||
|
*/
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
@ -260,6 +274,7 @@ namespace ZL
|
|||||||
|
|
||||||
GameObjects::testmd3 = testLoadModel();
|
GameObjects::testmd3 = testLoadModel();
|
||||||
|
|
||||||
|
/*
|
||||||
GameObjects::testmd3mutable.resize(GameObjects::testmd3.size());
|
GameObjects::testmd3mutable.resize(GameObjects::testmd3.size());
|
||||||
|
|
||||||
for (int i = 0; i < GameObjects::testmd3.size(); i++)
|
for (int i = 0; i < GameObjects::testmd3.size(); i++)
|
||||||
@ -268,7 +283,7 @@ namespace ZL
|
|||||||
|
|
||||||
GameObjects::testmd3mutable[i].data = GameObjects::testmd3[i];
|
GameObjects::testmd3mutable[i].data = GameObjects::testmd3[i];
|
||||||
GameObjects::testmd3mutable[i].RefreshVBO();
|
GameObjects::testmd3mutable[i].RefreshVBO();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//Load shaders:
|
//Load shaders:
|
||||||
renderer.shaderManager.AddShaderFromFiles("default", "./default.vertex", "./default.fragment");
|
renderer.shaderManager.AddShaderFromFiles("default", "./default.vertex", "./default.fragment");
|
||||||
@ -281,7 +296,7 @@ namespace ZL
|
|||||||
GameObjects::gameOverTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp32("./game_over.bmp32"));
|
GameObjects::gameOverTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp32("./game_over.bmp32"));
|
||||||
GameObjects::testObjTexturePtr = std::make_shared<Texture>(CreateTextureDataFromPng("./chair_01_Base_Color.png"));
|
GameObjects::testObjTexturePtr = std::make_shared<Texture>(CreateTextureDataFromPng("./chair_01_Base_Color.png"));
|
||||||
|
|
||||||
GameObjects::md3TexturePtr = std::make_shared<Texture>(CreateTextureDataFromPng("./model/sarge/band.png"));
|
//GameObjects::md3TexturePtr = std::make_shared<Texture>(CreateTextureDataFromPng("./model/sarge/band.png"));
|
||||||
|
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|||||||
1416
md3test.cpp
1416
md3test.cpp
File diff suppressed because it is too large
Load Diff
195
md3test.h
195
md3test.h
@ -1,113 +1,198 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#define SZ_MD3_FILE "model/sarge/upper.md3"
|
#define SZ_MD3_LOWER_FILE "model\\sarge\\lower.md3"
|
||||||
|
#define SZ_MD3_LOWER_SKIN_FILE "model\\sarge\\lower_default.skin"
|
||||||
|
|
||||||
|
#define SZ_MD3_UPPER_FILE "model\\sarge\\upper.md3"
|
||||||
|
#define SZ_MD3_UPPER_SKIN_FILE "model\\sarge\\upper_default.skin"
|
||||||
|
|
||||||
|
#define SZ_MD3_HEAD_FILE "model\\sarge\\head.md3"
|
||||||
|
#define SZ_MD3_HEAD_SKIN_FILE "model\\sarge\\head_default.skin"
|
||||||
|
|
||||||
|
#define SZ_MD3_TEXTURE_PATH "model\\sarge\\"
|
||||||
|
#define SZ_MD3_ANIM_FILE "model\\sarge\\animation.cfg"
|
||||||
|
|
||||||
#define MAX_FILENAME_LENGTH 256
|
#define MAX_FILENAME_LENGTH 256
|
||||||
|
#define MAX_TEXTURES 20
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h> //sprintf(...)
|
#include <stdio.h> //sprintf(...)
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
typedef unsigned int uint32;
|
typedef unsigned int uint32;
|
||||||
typedef int int32;
|
typedef int int32;
|
||||||
typedef unsigned short int uint16;
|
typedef unsigned short int uint16;
|
||||||
typedef short int int16;
|
typedef short int int16;
|
||||||
typedef float float32;
|
typedef float float32;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct stMD3Header
|
struct stMD3Header
|
||||||
{
|
{
|
||||||
char ID[4]; // ID of the file is always "IDP3"
|
char ID[4]; // ID of the file is always "IDP3"
|
||||||
int32 Version; // Version number, usually 15
|
int32 Version; // Version number, usually 15
|
||||||
char Filename[68]; // Filename, sometimes left blank
|
char Filename[68]; // Filename, sometimes left blank
|
||||||
int32 numBoneFrames; // Number of BoneFrames
|
int32 numBoneFrames; // Number of BoneFrames
|
||||||
int32 numTags; // Number of 'tags' per BoneFrame
|
int32 numTags; // Number of 'tags' per BoneFrame
|
||||||
int32 numMeshes; // Number of Meshes/Skins in MaxSkin
|
int32 numMeshes; // Number of Meshes/Skins in MaxSkin
|
||||||
int32 numMaxSkins; // Maximum number of unique skins
|
int32 numMaxSkins; // Maximum number of unique skins
|
||||||
int32 ofsFrames; // Always equal to the length this header
|
int32 ofsFrames; // Always equal to the length this header
|
||||||
int32 ofsTagStart; // Starting position of tag structures
|
int32 ofsTagStart; // Starting position of tag structures
|
||||||
int32 ofMeshSurfaces; // Ending position of tag structure
|
int32 ofMeshSurfaces; // Ending position of tag structure
|
||||||
int32 ofEndOfFile; // Size of file
|
int32 ofEndOfFile; // Size of file
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct stBoneFrame
|
struct stBoneFrame
|
||||||
{
|
{
|
||||||
float32 mins[3];
|
float32 mins[3];
|
||||||
float32 maxs[3];
|
float32 maxs[3];
|
||||||
float32 Position[3];
|
float32 Position[3];
|
||||||
float32 Scale;
|
float32 Scale;
|
||||||
char Creator[16];
|
char Creator[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stAnim
|
struct stAnim
|
||||||
{
|
{
|
||||||
int32 FirstFrame;
|
int32 FirstFrame;
|
||||||
int32 numFrames;
|
int32 numFrames;
|
||||||
int32 LoopingFrames;
|
int32 LoopingFrames;
|
||||||
int32 FPS;
|
int32 FPS;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stSkin
|
struct stSkin
|
||||||
{
|
{
|
||||||
char Name[64];
|
char Name[64];
|
||||||
int32 index;
|
int32 index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stTag
|
struct stTag
|
||||||
{
|
{
|
||||||
char Name[64];
|
char Name[64];
|
||||||
float32 Position[3];
|
float32 Position[3];
|
||||||
float32 Rotation[3][3];
|
float32 Rotation[3][3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stTriangle
|
struct stTriangle
|
||||||
{
|
{
|
||||||
int32 Vertex[3];
|
int32 Vertex[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stTexCoord
|
struct stTexCoord
|
||||||
{
|
{
|
||||||
float32 Coord[2];
|
float32 Coord[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stVertex // = Record
|
struct stVertex // = Record
|
||||||
{
|
{
|
||||||
int16 Vertex[3];
|
int16 Vertex[3];
|
||||||
unsigned char Normal[2];
|
unsigned char Normal[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stMeshHeader
|
struct stMeshHeader
|
||||||
{
|
{
|
||||||
char ID[4];
|
char ID[4];
|
||||||
char Name[64];
|
char Name[64];
|
||||||
int32 flags;
|
int32 flags;
|
||||||
int32 numMeshFrames;
|
int32 numMeshFrames;
|
||||||
int32 numSkins;
|
int32 numSkins;
|
||||||
int32 numVertexes;
|
int32 numVertexes;
|
||||||
int32 numTriangles;
|
int32 numTriangles;
|
||||||
int32 ofsTriangles;
|
int32 ofsTriangles;
|
||||||
int32 ofsSkins;
|
int32 ofsSkins;
|
||||||
int32 ofsTexVector;
|
int32 ofsTexVector;
|
||||||
int32 ofsVertex;
|
int32 ofsVertex;
|
||||||
int32 ofsEndMeshSize;
|
int32 ofsEndMeshSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stMesh
|
struct stMesh
|
||||||
{
|
{
|
||||||
stMeshHeader MeshHeader;
|
stMeshHeader MeshHeader;
|
||||||
stSkin* pSkins;
|
stSkin* pSkins;
|
||||||
stTriangle* pTriangle;
|
stTriangle* pTriangle;
|
||||||
stTexCoord* pTexCoord;
|
stTexCoord* pTexCoord;
|
||||||
stVertex* pVertex;
|
stVertex* pVertex;
|
||||||
|
int texID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct stM3DModel
|
||||||
|
{
|
||||||
|
char m_md3FileName[MAX_FILENAME_LENGTH];
|
||||||
|
stMD3Header m_md3Header;
|
||||||
|
|
||||||
|
stBoneFrame* m_pBoneFrame;
|
||||||
|
stTag* m_pTags;
|
||||||
|
stMesh* m_pMeshes;
|
||||||
|
|
||||||
|
int m_FPS;
|
||||||
|
int m_startFrame;
|
||||||
|
int m_endFrame;
|
||||||
|
int m_nextFrame;
|
||||||
|
int m_anim;
|
||||||
|
float m_poll;
|
||||||
|
//int m_animLower;
|
||||||
|
//int m_animUpper;
|
||||||
|
stM3DModel* m_pLinks[10];
|
||||||
|
|
||||||
|
int m_currentframe;
|
||||||
|
};
|
||||||
|
|
||||||
|
//IDirect3DTexture8* pTextures[MAX_TEXTURES];
|
||||||
|
int g_NumLoadedTextures = 0;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
long filesize(FILE* stream)
|
||||||
|
{
|
||||||
|
long curpos, length;
|
||||||
|
|
||||||
|
curpos = ftell(stream);
|
||||||
|
fseek(stream, 0L, SEEK_END);
|
||||||
|
length = ftell(stream);
|
||||||
|
fseek(stream, curpos, SEEK_SET);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
BOTH_DEATH1 = 0,
|
||||||
|
BOTH_DEAD1 = 1,
|
||||||
|
BOTH_DEATH2 = 2,
|
||||||
|
BOTH_DEAD2 = 3,
|
||||||
|
BOTH_DEATH3 = 4,
|
||||||
|
BOTH_DEAD3 = 5,
|
||||||
|
|
||||||
|
TORSO_GESTURE = 6,
|
||||||
|
TORSO_ATTACK = 7,
|
||||||
|
TORSO_ATTACK2 = 8,
|
||||||
|
TORSO_DROP = 9,
|
||||||
|
TORSO_RAISE = 10,
|
||||||
|
TORSO_STAND = 11,
|
||||||
|
TORSO_STAND2 = 12,
|
||||||
|
|
||||||
|
LEGS_WALKCR = 13,
|
||||||
|
LEGS_WALK = 14,
|
||||||
|
LEGS_RUN = 15,
|
||||||
|
LEGS_BACK = 16,
|
||||||
|
LEGS_SWIM = 17,
|
||||||
|
LEGS_JUMP = 18,
|
||||||
|
LEGS_LAND = 19,
|
||||||
|
LEGS_JUMPB = 20,
|
||||||
|
LEGS_LANDB = 21,
|
||||||
|
LEGS_IDLE = 22,
|
||||||
|
LEGS_IDLECR = 23,
|
||||||
|
LEGS_TURN = 24,
|
||||||
|
|
||||||
|
MAX_ANIMATIONS
|
||||||
|
};
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 921 B After Width: | Height: | Size: 662 B |
Loading…
Reference in New Issue
Block a user