aboutsummaryrefslogtreecommitdiff
path: root/src/models.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2013-11-30 18:12:40 +0100
committerraysan5 <raysan5@gmail.com>2013-11-30 18:12:40 +0100
commit294533ccda115b5e638ab1f9219f86d73c9c4550 (patch)
tree79231c1eba341e091dcbcb5c8182c27222af3195 /src/models.c
parentc7220ab1b3692d81c999fcf37afdf9908d728350 (diff)
downloadraylib-294533ccda115b5e638ab1f9219f86d73c9c4550.tar.gz
raylib-294533ccda115b5e638ab1f9219f86d73c9c4550.zip
Updated to version 1.0.2
Some functions added (collision detection) Check CHANGELOG for details
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/models.c b/src/models.c
index e15ea31f..8e4f3555 100644
--- a/src/models.c
+++ b/src/models.c
@@ -662,6 +662,38 @@ Model LoadModel(const char *fileName)
return model;
}
+// Load a heightmap image as a 3d model
+// TODO: Just do it...
+Model LoadHeightmap(Image heightmap, Vector3 resolution)
+{
+ Model model;
+
+ int mapX = heightmap.width;
+ int mapZ = heightmap.height;
+
+ // NOTE: One vertex per pixel
+ // TODO: Consider resolution when generating model data?
+ int numTriangles = (mapX-1)*(mapZ-1)*2; // One quad every four pixels
+
+ model.numVertices = numTriangles*3;
+
+ model.vertices = (Vector3 *)malloc(model.numVertices * sizeof(Vector3));
+ model.normals = (Vector3 *)malloc(model.numVertices * sizeof(Vector3));
+ model.texcoords = (Vector2 *)malloc(model.numVertices * sizeof(Vector2));
+
+ for(int z = 0; z < mapZ; z++)
+ {
+ for(int x = 0; x < mapX; x++)
+ {
+ // TODO: Fill vertices array with data
+ }
+ }
+
+ //SmoothHeightmap(&model); // TODO: Smooth vertex interpolation
+
+ return model;
+}
+
// Unload 3d model from memory
void UnloadModel(Model model)
{
@@ -743,9 +775,9 @@ void DrawBillboard(Camera camera, Texture2D texture, Vector3 basePos, float size
void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 basePos, float size, Color tint)
{
// NOTE: Billboard size will represent the width, height maintains aspect ratio
- Vector3 centerPos = { basePos.x, basePos.y + size * (float)texture.height/(float)texture.width/2, basePos.z };
- Vector2 sizeRatio = { size, size * (float)texture.height/texture.width };
- Vector3 rotation = { 90, 0, 0 };
+ //Vector3 centerPos = { basePos.x, basePos.y + size * (float)texture.height/(float)texture.width/2, basePos.z };
+ //Vector2 sizeRatio = { size, size * (float)texture.height/texture.width };
+ //Vector3 rotation = { 90, 0, 0 };
// TODO: Calculate Y rotation to face always camera (use matrix)
// OPTION: Lock Y-axis
@@ -766,7 +798,7 @@ void DrawHeightmap(Image heightmap, Vector3 centerPos, Vector3 scale, Color colo
// NOTE: Heightmap resolution will depend on image size (one quad per pixel)
// TODO: Review how this function works... probably we need:
- // Model LoadHeightmap(Image image, Vector3 resolution);
+ // Model LoadHeightmap(Image heightmap, Vector3 resolution);
// NOTE: We are allocating and de-allocating vertex data every frame! --> framerate drops 80%! CRAZY!
Vector3 *terrainVertex = (Vector3 *)malloc(heightmap.width * heightmap.height * sizeof(Vector3));