-const Asset3D* importAsset(const char* path) {
+const Solid* importSolid(const char* path) {
const AiScene* scene = importScene(path);
if (scene == NULL) {
return NULL;
// TODO Consider assets with some arrays empty, and prevent zero mallocs
- Asset3D* asset = malloc(sizeof(Asset3D));
- asset->numMeshes = numMeshes;
- asset->meshes = malloc(numMeshes * sizeof(Mesh));
- asset->numMaterials = numMaterials;
- asset->materials = malloc(numMaterials * sizeof(Material));
+ Solid* solid = malloc(sizeof(Solid));
+ solid->numMeshes = numMeshes;
+ solid->meshes = malloc(numMeshes * sizeof(Mesh));
+ solid->numMaterials = numMaterials;
+ solid->materials = malloc(numMaterials * sizeof(Material));
for (unsigned int meshIndex = 0; meshIndex < numMeshes; ++meshIndex) {
const AiMesh* aiMesh = scene->mMeshes[meshIndex];
mesh.faces[faceIndex] = face;
}
- asset->meshes[meshIndex] = mesh;
+ solid->meshes[meshIndex] = mesh;
}
GLuint* textureIds = malloc(numMaterials * sizeof(GLuint));
}
}
- asset->materials[matIndex] = material;
+ solid->materials[matIndex] = material;
}
glBindTexture(GL_TEXTURE_2D, 0);
aiReleaseImport(scene);
- return asset;
+ return solid;
}
static const AiScene* importScene(const char* path) {
#include "geometry.h"
-typedef struct Asset3D Asset3D;
+typedef struct Solid Solid;
typedef struct Mesh Mesh;
typedef struct Face Face;
typedef struct Material Material;
-struct Asset3D {
+struct Solid {
size_t numMeshes;
Mesh* meshes;
size_t numMaterials;
GLuint textureId;
};
-const Asset3D* importAsset(const char* path);
+const Solid* importSolid(const char* path);
#endif
static void drawAxes();
static void renderBlockGrid(const BlockGrid grid);
static void renderCharacter(const Character* character, const Vector3D pos);
-static void drawAsset3D(const Asset3D* asset3D);
+static void drawSolid(const Solid* solid);
float viewportAspectRatio = 1.0f;
glLoadIdentity();
glTranslatef(0.0f, 0.0f, z * BLOCKGRID_CELL_SIZE);
for (size_t x = 0; x < grid.width; ++x) {
- drawAsset3D(getBlockFromGrid(grid, x, z)->asset3D);
+ drawSolid(getBlockFromGrid(grid, x, z)->solid);
glTranslatef(BLOCKGRID_CELL_SIZE, 0.0f, 0.0f);
}
}
static void renderCharacter(const Character* character, const Vector3D pos) {
glMatrixMode(GL_MODELVIEW);
glTranslatef(pos.x, pos.y, pos.z);
- drawAsset3D(character->asset3D);
+ drawSolid(character->solid);
glLoadIdentity();
}
-static void drawAsset3D(const Asset3D* asset3D) {
- if (asset3D == NULL) {
+static void drawSolid(const Solid* solid) {
+ if (solid == NULL) {
return;
}
glMatrixMode(GL_MODELVIEW);
glColor3f(0.5f, 1.0f, 0.0f);
- for (size_t meshIndex = 0; meshIndex < asset3D->numMeshes; ++meshIndex) {
- const Mesh mesh = asset3D->meshes[meshIndex];
+ for (size_t meshIndex = 0; meshIndex < solid->numMeshes; ++meshIndex) {
+ const Mesh mesh = solid->meshes[meshIndex];
glBindTexture(GL_TEXTURE_2D,
- asset3D->materials[mesh.materialIndex].textureId);
+ solid->materials[mesh.materialIndex].textureId);
bool hasNormals = mesh.normals != NULL;
bool hasTextureCoords = mesh.textureCoords != NULL;
#include "player.h"
static Block blockEmpty = { .type = BLOCKTYPE_SPACE,
- .asset3D = NULL };
+ .solid = NULL };
static Block blockWall01 = { .type = BLOCKTYPE_OBSTACLE,
- .asset3D = NULL };
+ .solid = NULL };
static Block* testBlocks[9] = { &blockWall01, &blockWall01, &blockWall01,
&blockEmpty, &blockEmpty, &blockEmpty,
void initLevel() {
- blockWall01.asset3D = importAsset("assets/wall01.3ds");
+ blockWall01.solid = importSolid("assets/wall01.3ds");
buildLevelFromImage(readTga("assets/level01.tga"));
}
typedef struct {
const BlockType type;
- const Asset3D* asset3D;
+ const Solid* solid;
} Block;
typedef struct {
#include "level.h"
#include "player.h"
-Character playerCharacter = { .asset3D = NULL };
+Character playerCharacter = { .solid = NULL };
void initPlayer() {
- playerCharacter.asset3D = importAsset("assets/playercharacter.3ds");
+ playerCharacter.solid = importSolid("assets/playercharacter.3ds");
}
void spawnPlayer() {
#include "engine/asset.h"
typedef struct {
- const Asset3D* asset3D;
+ const Solid* solid;
} Character;
Character playerCharacter;