Rename Asset3D to Solid

master
outfrost 2020-04-30 03:48:24 +02:00
parent c78af1fbe8
commit fd220501c6
7 changed files with 27 additions and 27 deletions

View File

@ -13,7 +13,7 @@ static const char* replaceFileExtension(const AiString path, const char* ext);
const Asset3D* importAsset(const char* path) {
const Solid* importSolid(const char* path) {
const AiScene* scene = importScene(path);
if (scene == NULL) {
return NULL;
@ -24,11 +24,11 @@ const Asset3D* importAsset(const char* path) {
// 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];
@ -76,7 +76,7 @@ const Asset3D* importAsset(const char* path) {
mesh.faces[faceIndex] = face;
}
asset->meshes[meshIndex] = mesh;
solid->meshes[meshIndex] = mesh;
}
GLuint* textureIds = malloc(numMaterials * sizeof(GLuint));
@ -119,12 +119,12 @@ const Asset3D* importAsset(const char* path) {
}
}
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) {

View File

@ -7,12 +7,12 @@
#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;
@ -38,6 +38,6 @@ struct Material {
GLuint textureId;
};
const Asset3D* importAsset(const char* path);
const Solid* importSolid(const char* path);
#endif

View File

@ -14,7 +14,7 @@ static void moveCameraTo(const Vector3D pos);
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;
@ -111,7 +111,7 @@ static void renderBlockGrid(const BlockGrid grid) {
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);
}
}
@ -121,22 +121,22 @@ static void renderBlockGrid(const BlockGrid grid) {
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;

View File

@ -7,9 +7,9 @@
#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,
@ -25,7 +25,7 @@ Vector3D playerSpawnPos = DEFAULT_PLAYER_SPAWN_POS;
void initLevel() {
blockWall01.asset3D = importAsset("assets/wall01.3ds");
blockWall01.solid = importSolid("assets/wall01.3ds");
buildLevelFromImage(readTga("assets/level01.tga"));
}

View File

@ -15,7 +15,7 @@ typedef enum {
typedef struct {
const BlockType type;
const Asset3D* asset3D;
const Solid* solid;
} Block;
typedef struct {

View File

@ -3,12 +3,12 @@
#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() {

View File

@ -6,7 +6,7 @@
#include "engine/asset.h"
typedef struct {
const Asset3D* asset3D;
const Solid* solid;
} Character;
Character playerCharacter;