mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 03:18:14 +00:00
Update models_loading_vox.c
This commit is contained in:
@@ -40,7 +40,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
const char* voxFileNames[] = {
|
const char *voxFileNames[] = {
|
||||||
"resources/models/vox/chr_knight.vox",
|
"resources/models/vox/chr_knight.vox",
|
||||||
"resources/models/vox/chr_sword.vox",
|
"resources/models/vox/chr_sword.vox",
|
||||||
"resources/models/vox/monu9.vox",
|
"resources/models/vox/monu9.vox",
|
||||||
@@ -57,24 +57,23 @@ int main(void)
|
|||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
// Load MagicaVoxel files
|
// Load MagicaVoxel files
|
||||||
Model models[MAX_VOX_FILES] = { 0 };
|
Model models[MAX_VOX_FILES] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++)
|
for (int i = 0; i < MAX_VOX_FILES; i++)
|
||||||
{
|
{
|
||||||
// Load VOX file and measure time
|
// Load VOX file and measure time
|
||||||
double t0 = GetTime() * 1000.0;
|
double t0 = GetTime()*1000.0;
|
||||||
models[i] = LoadModel(voxFileNames[i]);
|
models[i] = LoadModel(voxFileNames[i]);
|
||||||
double t1 = GetTime() * 1000.0;
|
double t1 = GetTime()*1000.0;
|
||||||
|
|
||||||
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
||||||
|
|
||||||
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
||||||
BoundingBox bb = GetModelBoundingBox(models[i]);
|
BoundingBox bb = GetModelBoundingBox(models[i]);
|
||||||
Vector3 center = { 0 };
|
Vector3 center = { 0 };
|
||||||
center.x = bb.min.x + (((bb.max.x - bb.min.x) / 2));
|
center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
|
||||||
center.z = bb.min.z + (((bb.max.z - bb.min.z) / 2));
|
center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
|
||||||
|
|
||||||
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
||||||
models[i].transform = matTranslate;
|
models[i].transform = matTranslate;
|
||||||
@@ -82,14 +81,13 @@ int main(void)
|
|||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
// Load voxel shader
|
// Load voxel shader
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/voxel_lighting.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/voxel_lighting.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Get some required shader locations
|
// Get some required shader locations
|
||||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||||
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||||
// no need to get the location again if using that uniform name
|
// no need to get the location again if using that uniform name
|
||||||
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
//shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user