Merge pull request #504 from Martinfx/master
Fix potential bugs from static analysis
This commit is contained in:
commit
3e0de31424
12 changed files with 110 additions and 126 deletions
|
@ -29,11 +29,11 @@ int main()
|
|||
|
||||
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
||||
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
||||
|
||||
Ray ray; // Picking line ray
|
||||
|
||||
|
||||
Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray
|
||||
|
||||
bool collision = false;
|
||||
|
||||
|
||||
SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
|
@ -45,11 +45,11 @@ int main()
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera); // Update camera
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
ray = GetMouseRay(GetMousePosition(), camera);
|
||||
|
||||
|
||||
// Check collision between ray and box
|
||||
collision = CheckCollisionRayBox(ray,
|
||||
(BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
|
||||
|
@ -65,7 +65,7 @@ int main()
|
|||
|
||||
Begin3dMode(camera);
|
||||
|
||||
if (collision)
|
||||
if (collision)
|
||||
{
|
||||
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED);
|
||||
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON);
|
||||
|
@ -77,15 +77,14 @@ int main()
|
|||
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
|
||||
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
|
||||
}
|
||||
|
||||
|
||||
DrawRay(ray, MAROON);
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
End3dMode();
|
||||
|
||||
|
||||
DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY);
|
||||
|
||||
|
||||
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
@ -100,4 +99,4 @@ int main()
|
|||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example based on Berni work on Raspberry Pi:
|
||||
* Example based on Berni work on Raspberry Pi:
|
||||
* http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
|
@ -30,25 +30,25 @@ int main()
|
|||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
|
||||
|
||||
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
|
||||
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
|
||||
Texture2D texBackground = LoadTexture("resources/background.png");
|
||||
Texture2D texPitch = LoadTexture("resources/pitch.png");
|
||||
Texture2D texPitch = LoadTexture("resources/pitch.png");
|
||||
Texture2D texPlane = LoadTexture("resources/plane.png");
|
||||
|
||||
RenderTexture2D framebuffer = LoadRenderTexture(192, 192);
|
||||
|
||||
|
||||
// Model loading
|
||||
Model model = LoadModel("resources/plane.obj"); // Load OBJ model
|
||||
model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
|
||||
|
||||
|
||||
GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture);
|
||||
|
||||
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective
|
||||
camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 30.0f; // Camera field-of-view Y
|
||||
|
||||
|
||||
float pitch = 0.0f;
|
||||
float roll = 0.0f;
|
||||
float yaw = 0.0f;
|
||||
|
@ -61,7 +61,7 @@ int main()
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Plane roll (x-axis) controls
|
||||
if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
|
||||
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f;
|
||||
|
@ -70,7 +70,7 @@ int main()
|
|||
if (roll > 0.0f) roll -= 0.5f;
|
||||
else if (roll < 0.0f) roll += 0.5f;
|
||||
}
|
||||
|
||||
|
||||
// Plane yaw (y-axis) controls
|
||||
if (IsKeyDown(KEY_S)) yaw += 1.0f;
|
||||
else if (IsKeyDown(KEY_A)) yaw -= 1.0f;
|
||||
|
@ -79,7 +79,7 @@ int main()
|
|||
if (yaw > 0.0f) yaw -= 0.5f;
|
||||
else if (yaw < 0.0f) yaw += 0.5f;
|
||||
}
|
||||
|
||||
|
||||
// Plane pitch (z-axis) controls
|
||||
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f;
|
||||
else if (IsKeyDown(KEY_UP)) pitch -= 0.6f;
|
||||
|
@ -88,7 +88,7 @@ int main()
|
|||
if (pitch > 0.3f) pitch -= 0.3f;
|
||||
else if (pitch < -0.3f) pitch += 0.3f;
|
||||
}
|
||||
|
||||
|
||||
// Wraps the phase of an angle to fit between -180 and +180 degrees
|
||||
int pitchOffset = pitch;
|
||||
while (pitchOffset > 180) pitchOffset -= 360;
|
||||
|
@ -96,20 +96,20 @@ int main()
|
|||
pitchOffset *= 10;
|
||||
|
||||
Matrix transform = MatrixIdentity();
|
||||
|
||||
|
||||
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll));
|
||||
transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch));
|
||||
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw));
|
||||
|
||||
|
||||
model.transform = transform;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
// Draw framebuffer texture (Ahrs Display)
|
||||
int centerX = framebuffer.texture.width/2;
|
||||
int centerY = framebuffer.texture.height/2;
|
||||
|
@ -126,11 +126,11 @@ int main()
|
|||
DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height },
|
||||
(Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor },
|
||||
(Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE);
|
||||
|
||||
|
||||
DrawTexturePro(texPlane, (Rectangle){ 0, 0, texPlane.width, texPlane.height },
|
||||
(Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor },
|
||||
(Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor },
|
||||
(Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE);
|
||||
|
||||
|
||||
EndBlendMode();
|
||||
|
||||
EndTextureMode();
|
||||
|
@ -147,7 +147,7 @@ int main()
|
|||
DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED);
|
||||
DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN);
|
||||
DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE);
|
||||
|
||||
|
||||
DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f));
|
||||
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY);
|
||||
|
@ -155,31 +155,31 @@ int main()
|
|||
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY);
|
||||
|
||||
// Draw framebuffer texture
|
||||
DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height },
|
||||
DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height },
|
||||
(Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f));
|
||||
|
||||
|
||||
DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload all loaded data
|
||||
UnloadModel(model);
|
||||
|
||||
|
||||
UnloadRenderTexture(framebuffer);
|
||||
|
||||
UnloadTexture(texAngleGauge);
|
||||
|
||||
UnloadTexture(texAngleGauge);
|
||||
UnloadTexture(texBackground);
|
||||
UnloadTexture(texPitch);
|
||||
UnloadTexture(texPitch);
|
||||
UnloadTexture(texPlane);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[
|
|||
int textSize = 20;
|
||||
|
||||
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color);
|
||||
|
||||
DrawText(FormatText("%5.1f°", angle), x - MeasureText(FormatText("%5.1f°", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
|
||||
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
|
||||
}
|
||||
|
||||
DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
|
||||
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
|
||||
}
|
||||
|
|
|
@ -76,13 +76,13 @@ int main()
|
|||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
unsigned char key;
|
||||
|
||||
static unsigned char key;
|
||||
|
||||
InitAudioDevice();
|
||||
|
||||
|
||||
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
||||
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
||||
|
||||
|
||||
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
||||
PlayMusicStream(music);
|
||||
|
||||
|
@ -99,23 +99,23 @@ int main()
|
|||
PlaySound(fxWav);
|
||||
key = 0;
|
||||
}
|
||||
|
||||
|
||||
if (key == 'd')
|
||||
{
|
||||
PlaySound(fxOgg);
|
||||
key = 0;
|
||||
}
|
||||
|
||||
|
||||
UpdateMusicStream(music);
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadSound(fxWav); // Unload sound data
|
||||
UnloadSound(fxOgg); // Unload sound data
|
||||
|
||||
|
||||
UnloadMusicStream(music); // Unload music stream data
|
||||
|
||||
|
||||
CloseAudioDevice();
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
|
||||
#define MAX_BUNNIES 100000 // 100K bunnies
|
||||
|
@ -29,15 +28,16 @@ int main()
|
|||
int screenHeight = 960;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark");
|
||||
|
||||
|
||||
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
|
||||
|
||||
|
||||
Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array
|
||||
|
||||
int bunniesCount = 0; // Bunnies counter
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ int main()
|
|||
bunniesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update bunnies
|
||||
for (int i = 0; i < bunniesCount; i++)
|
||||
{
|
||||
|
@ -65,14 +65,14 @@ int main()
|
|||
if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
for (int i = 0; i <= bunniesCount; i++)
|
||||
|
||||
for (int i = 0; i < bunniesCount; i++)
|
||||
{
|
||||
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
|
||||
// batching buffer starts being filled again; before launching the draw call,
|
||||
|
@ -80,11 +80,10 @@ int main()
|
|||
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
|
||||
DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE);
|
||||
}
|
||||
|
||||
|
||||
DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
|
||||
DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
|
||||
DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
|
||||
|
||||
DrawFPS(260, 10);
|
||||
|
||||
EndDrawing();
|
||||
|
@ -94,9 +93,9 @@ int main()
|
|||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
free(bunnies);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ int main()
|
|||
SetPhysicsGravity(0, 0);
|
||||
|
||||
// Create random polygon physics body to shatter
|
||||
PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
|
||||
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -53,7 +53,7 @@ int main()
|
|||
if (needsReset)
|
||||
{
|
||||
// Create random polygon physics body to shatter
|
||||
body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
|
||||
}
|
||||
|
||||
if (IsKeyPressed('R')) // Reset physics input
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue