From 294533ccda115b5e638ab1f9219f86d73c9c4550 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 30 Nov 2013 18:12:40 +0100 Subject: [PATCH] Updated to version 1.0.2 Some functions added (collision detection) Check CHANGELOG for details --- README.md | 2 +- release/win32-mingw/include/raylib.h | 9 ++- release/win32-mingw/lib/libraylib.a | Bin 133040 -> 135180 bytes src/models.c | 40 +++++++++-- src/raylib.h | 8 ++- src/shapes.c | 99 ++++++++++++++++++++++++++- src/textures.c | 30 ++++++++ 7 files changed, 179 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dbcd7a856..ebb528ebf 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ raylib has been developed using exclusively two tools: * Notepad++ (text editor) - [http://notepad-plus-plus.org/](http://notepad-plus-plus.org/) * MinGW (GCC compiler) - [http://www.mingw.org/](http://www.mingw.org/) -Those are the tools I recommended to develop with raylib, actually, my students develop using this tools. +Those are the tools I recommend to develop with raylib, in fact, those are the tools my students use. I believe those are the best tools to train spartan-programmers. Someone could argue about debugging. raylib is a library intended for learning and I think C it's a clear enough language diff --git a/release/win32-mingw/include/raylib.h b/release/win32-mingw/include/raylib.h index 14a3300ee..7f14113f7 100644 --- a/release/win32-mingw/include/raylib.h +++ b/release/win32-mingw/include/raylib.h @@ -1,6 +1,6 @@ /********************************************************************************************* * -* raylib 1.0.1 (www.raylib.com) +* raylib 1.0.2 (www.raylib.com) * * A simple and easy-to-use library to learn C videogames programming * @@ -301,6 +301,11 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); void DrawPoly(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points void DrawPolyLine(Vector2 *points, int numPoints, Color color); // Draw polygon lines +bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision + //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ @@ -313,10 +318,12 @@ void DrawTexture(Texture2D texture, int posX, int posY, Color tint); void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters +Texture2D CreateTexture2D(Image image); // Create a Texture2D from Image data //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) //------------------------------------------------------------------------------------ +SpriteFont GetDefaultFont(); // Get the default SpriteFont SpriteFont LoadSpriteFont(const char *fileName); // Load a SpriteFont image into GPU memory void UnloadSpriteFont(SpriteFont spriteFont); // Unload SpriteFont from GPU memory void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) diff --git a/release/win32-mingw/lib/libraylib.a b/release/win32-mingw/lib/libraylib.a index 028e78705343d0b8fd71bd65ee29e6104d3f42d9..f07e2f65184a1a923aa5902edbf6af6886dbee9d 100644 GIT binary patch delta 15960 zcmb`O33yaR)`shLlAa_460ng75gHO8Y!R}si$Q3JiVtf*KnOt+5+nqYs0<>l1jI}L z(MB)0jHrX6$l&5 zIlWd^)VM~wMi0u%x#iYDg)?X77v~qw8kKWPvC68i4azUNWoFKA$f%&QhUS#~(nFxU zuxIq3qMYoKoH03bOKvO5Ngf>7S~$L9M_86C1cmKoi>w8K2g6@!JghK#T1HO(^t_US z?Aa9qBZ{n+w-grTBo$u8S&h#gDZSIo5=aTGAA5O4O=NYFt4|+0Yq8b5;*&m;Lfm!6 zD|+?nk>)IiVOAJcgi@(jDAg@+Y;23BHPK2Pfl_msF{om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oadModel(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)); diff --git a/src/raylib.h b/src/raylib.h index 54065dd0a..7f14113f7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1,6 +1,6 @@ /********************************************************************************************* * -* raylib 1.0.1 (www.raylib.com) +* raylib 1.0.2 (www.raylib.com) * * A simple and easy-to-use library to learn C videogames programming * @@ -301,6 +301,11 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); void DrawPoly(Vector2 *points, int numPoints, Color color); // Draw a closed polygon defined by points void DrawPolyLine(Vector2 *points, int numPoints, Color color); // Draw polygon lines +bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles +bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles +bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision + //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) //------------------------------------------------------------------------------------ @@ -313,6 +318,7 @@ void DrawTexture(Texture2D texture, int posX, int posY, Color tint); void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters +Texture2D CreateTexture2D(Image image); // Create a Texture2D from Image data //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) diff --git a/src/shapes.c b/src/shapes.c index ea55f1985..564676654 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -2,7 +2,7 @@ * * raylib.shapes * -* Basic functions to draw 2d Shapes +* Basic functions to draw 2d Shapes and check collisions * * Copyright (c) 2013 Ramon Santamaria (Ray San - raysan@raysanweb.com) * @@ -26,7 +26,9 @@ #include "raylib.h" #include // OpenGL functions +#include // Required for abs() function #include // Math related functions, sin() and cos() used on DrawCircle* + // sqrt() and pow() and abs() used on CheckCollision* //---------------------------------------------------------------------------------- // Defines and Macros @@ -323,4 +325,97 @@ void DrawPolyLine(Vector2 *points, int numPoints, Color color) //glDisable(GL_LINE_SMOOTH); } -} +} + +// Check collision between two rectangles +bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2) +{ + bool collision = false; + + int dx = abs((rec1.x + rec1.width / 2) - (rec2.x + rec2.width / 2)); + int dy = abs((rec1.y + rec1.height / 2) - (rec2.y + rec2.height / 2)); + + if ((dx <= (rec1.width / 2 + rec2.width / 2)) && ((dy <= (rec1.height / 2 + rec2.height / 2)))) collision = true; + + return collision; +} + +// Check collision between two circles +bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2) +{ + bool collision = false; + + float dx = center2.x - center1.x; // X distance between centers + float dy = center2.y - center1.y; // Y distance between centers + + float distance = sqrt(dx*dx + dy*dy); // Distance between centers + + if (distance <= (radius1 + radius2)) collision = true; + + return collision; +} + +// Check collision between circle and rectangle +bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec) +{ + bool collision = false; + + float dx = abs((rec.x + rec.width / 2) - center.x); + float dy = abs((rec.y + rec.height / 2) - center.y); + + if ((dx <= (rec.width / 2 + radius)) && (dy <= (rec.height / 2 + radius))) collision = true; + + return collision; +} + +// Get collision rectangle for two rectangles collision +Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) +{ + Rectangle retRec = { 0, 0, 0, 0 }; + + if (CheckCollisionRecs(rec1, rec2)) + { + int dxx = abs(rec1.x - rec2.x); + int dyy = abs(rec1.y - rec2.y); + + if (rec1.x <= rec2.x) + { + if (rec1.y <= rec2.y) + { + retRec.x = rec2.x; + retRec.y = rec2.y; + retRec.width = rec1.width - dxx; + retRec.height = rec1.height - dyy; + } + else + { + retRec.x = rec2.x; + retRec.y = rec1.y; + retRec.width = rec1.width - dxx; + retRec.height = rec2.height - dyy; + } + } + else + { + if (rec1.y <= rec2.y) + { + retRec.x = rec1.x; + retRec.y = rec2.y; + retRec.width = rec2.width - dxx; + retRec.height = rec1.height - dyy; + } + else + { + retRec.x = rec1.x; + retRec.y = rec1.y; + retRec.width = rec2.width - dxx; + retRec.height = rec2.height - dyy; + } + } + + if (retRec.width >= rec2.width) retRec.width = rec2.width; + if (retRec.height >= rec2.height) retRec.height = rec2.height; + } + + return retRec; +} diff --git a/src/textures.c b/src/textures.c index 3ccb5358a..19eb09b42 100644 --- a/src/textures.c +++ b/src/textures.c @@ -157,6 +157,36 @@ Texture2D LoadTextureEx(const char *fileName, bool createPOT, bool mipmaps) return texture; } +// Create a Texture2D from Image data +// NOTE: Image is not unloaded, it should be done manually... +Texture2D CreateTexture2D(Image image) +{ + Texture2D texture; + + // Convert image data to OpenGL texture + //---------------------------------------- + GLuint id; + glGenTextures(1, &id); // Generate Pointer to the Texture + + glBindTexture(GL_TEXTURE_2D, id); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repead on x-axis + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repead on y-axis + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.pixels); + + // NOTE: Not using mipmappings (texture for 2D drawing) + // At this point we have the image converted to texture and uploaded to GPU + + texture.glId = id; + texture.width = image.width; + texture.height = image.height; + + return texture; +} + // Unload texture from GPU memory void UnloadTexture(Texture2D texture) {