mirror of
https://github.com/allankoechke/raylib-cpp.git
synced 2026-11-30 10:59:00 +00:00
Mesh: Have the generator functions return ::Mesh
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
|
||||
#include "raylib-cpp.hpp"
|
||||
|
||||
#include <stdlib.h> // Required for: free()
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
@@ -26,13 +24,13 @@ int main(void)
|
||||
raylib::Camera camera({ 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f);
|
||||
|
||||
raylib::Image imMap("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||
raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM)
|
||||
raylib::Mesh mesh = raylib::Mesh::Cubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f });
|
||||
raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM)
|
||||
Mesh mesh = raylib::Mesh::Cubicmap(imMap, (Vector3){ 1.0f, 1.0f, 1.0f });
|
||||
raylib::Model model(mesh);
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
raylib::Texture texture("resources/cubicmap_atlas.png"); // Load map texture
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
|
||||
// Get map image data to be used for collision detection
|
||||
Color *mapPixels = imMap.LoadColors();
|
||||
@@ -96,11 +94,11 @@ int main(void)
|
||||
camera.BeginMode3D();
|
||||
|
||||
model.Draw(mapPosition); // Draw maze map
|
||||
// DrawCubeV(playerPosition, (Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player
|
||||
// playerPosition.DrawCube((Vector3){ 0.2f, 0.4f, 0.2f }, RED); // Draw player
|
||||
|
||||
camera.EndMode3D();
|
||||
|
||||
cubicmap.Draw((Vector2){ GetScreenWidth() - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
|
||||
cubicmap.Draw((Vector2){ static_cast<float>(GetScreenWidth() - cubicmap.width*4 - 20), 20 }, 0.0f, 4.0f, WHITE);
|
||||
DrawRectangleLines(GetScreenWidth() - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
|
||||
|
||||
// Draw player position radar
|
||||
@@ -114,24 +112,10 @@ int main(void)
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
free(mapPixels); // Unload color array
|
||||
|
||||
/**
|
||||
* TODO: Fix double freeing of Mesh, possibly from UnloadModel() unloading meshes in Model.hpp?
|
||||
*
|
||||
* INFO: TEXTURE: [ID 4] Unloaded texture data from VRAM (GPU)
|
||||
* INFO: VAO: [ID 2] Unloaded vertex data from VRAM (GPU)
|
||||
* INFO: MODEL: Unloaded model (and meshes) from RAM and VRAM
|
||||
* double free or corruption (!prev)
|
||||
*/
|
||||
mesh.vboId = NULL; // This shouldn't be needed, but currently is.
|
||||
UnloadImageColors(mapPixels); // Unload color array
|
||||
|
||||
//UnloadTexture(cubicmap); // Unload cubicmap texture
|
||||
//UnloadTexture(texture); // Unload map texture
|
||||
//UnloadModel(model); // Unload map model
|
||||
|
||||
//CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -58,68 +58,70 @@ class Mesh : public ::Mesh {
|
||||
/**
|
||||
* Generate polygonal mesh
|
||||
*/
|
||||
static Mesh Poly(int sides, float radius) {
|
||||
static ::Mesh Poly(int sides, float radius) {
|
||||
return ::GenMeshPoly(sides, radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate plane mesh (with subdivisions)
|
||||
*/
|
||||
static Mesh Plane(float width, float length, int resX, int resZ) {
|
||||
static ::Mesh Plane(float width, float length, int resX, int resZ) {
|
||||
return ::GenMeshPlane(width, length, resX, resZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cuboid mesh
|
||||
*/
|
||||
static Mesh Cube(float width, float height, float length) {
|
||||
static ::Mesh Cube(float width, float height, float length) {
|
||||
return ::GenMeshCube(width, height, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate sphere mesh (standard sphere)
|
||||
*/
|
||||
static Mesh Sphere(float radius, int rings, int slices) {
|
||||
static ::Mesh Sphere(float radius, int rings, int slices) {
|
||||
return ::GenMeshSphere(radius, rings, slices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate half-sphere mesh (no bottom cap)
|
||||
*/
|
||||
static Mesh HemiSphere(float radius, int rings, int slices) {
|
||||
static ::Mesh HemiSphere(float radius, int rings, int slices) {
|
||||
return ::GenMeshHemiSphere(radius, rings, slices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cylinder mesh
|
||||
*/
|
||||
static Mesh Cylinder(float radius, float height, int slices) {
|
||||
static ::Mesh Cylinder(float radius, float height, int slices) {
|
||||
return ::GenMeshCylinder(radius, height, slices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate torus mesh
|
||||
*/
|
||||
static Mesh Torus(float radius, float size, int radSeg, int sides) {
|
||||
static ::Mesh Torus(float radius, float size, int radSeg, int sides) {
|
||||
return ::GenMeshTorus(radius, size, radSeg, sides);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate trefoil knot mesh
|
||||
*/
|
||||
static Mesh Knot(float radius, float size, int radSeg, int sides) {
|
||||
static ::Mesh Knot(float radius, float size, int radSeg, int sides) {
|
||||
return ::GenMeshKnot(radius, size, radSeg, sides);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate heightmap mesh from image data
|
||||
*/
|
||||
static Mesh Heightmap(::Image heightmap, ::Vector3 size) {
|
||||
static ::Mesh Heightmap(::Image heightmap, ::Vector3 size) {
|
||||
return ::GenMeshHeightmap(heightmap, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cubes-based map mesh from image data
|
||||
*/
|
||||
static Mesh Cubicmap(::Image cubicmap, ::Vector3 cubeSize) {
|
||||
static ::Mesh Cubicmap(::Image cubicmap, ::Vector3 cubeSize) {
|
||||
return ::GenMeshCubicmap(cubicmap, cubeSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,10 +235,12 @@ class Vector3 : public ::Vector3 {
|
||||
::DrawLine3D(*this, endPos, color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3& DrawPoint3D(::Color color) {
|
||||
::DrawPoint3D(*this, color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3& DrawCircle3D(
|
||||
float radius,
|
||||
Vector3 rotationAxis,
|
||||
@@ -252,6 +254,7 @@ class Vector3 : public ::Vector3 {
|
||||
::DrawCube(*this, width, height, length, color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3& DrawCube(::Vector3 size, ::Color color) {
|
||||
::DrawCubeV(*this, size, color);
|
||||
return *this;
|
||||
@@ -261,6 +264,7 @@ class Vector3 : public ::Vector3 {
|
||||
::DrawCubeWires(*this, width, height, length, color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3& DrawCubeWires(::Vector3 size, ::Color color) {
|
||||
::DrawCubeWiresV(*this, size, color);
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user