mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-06-30 19:03:42 -04:00
Fixed trailing whitespace
- Removed trailing whitespace from bindings and examples.
This commit is contained in:
@ -15,17 +15,17 @@ public partial class models_billboard
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 5.0f, 4.0f, 5.0f );
|
||||
@ -33,15 +33,15 @@ public partial class models_billboard
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
||||
Vector3 billPosition = new Vector3( 0.0f, 2.0f, 0.0f ); // Position where draw billboard
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -49,34 +49,34 @@ public partial class models_billboard
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(bill); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,114 +13,114 @@ public partial class models_box_collisions
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 0.0f, 10.0f, 10.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Vector3 playerPosition = new Vector3( 0.0f, 1.0f, 2.0f );
|
||||
Vector3 playerSize = new Vector3( 1.0f, 2.0f, 1.0f );
|
||||
Color playerColor = GREEN;
|
||||
|
||||
|
||||
Vector3 enemyBoxPos = new Vector3( -4.0f, 1.0f, 0.0f );
|
||||
Vector3 enemyBoxSize = new Vector3( 2.0f, 2.0f, 2.0f );
|
||||
|
||||
|
||||
Vector3 enemySpherePos = new Vector3( 4.0f, 0.0f, 0.0f );
|
||||
float enemySphereSize = 1.5f;
|
||||
|
||||
|
||||
bool collision = false;
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Move player
|
||||
if (IsKeyDown(KEY_RIGHT)) playerPosition.x += 0.2f;
|
||||
else if (IsKeyDown(KEY_LEFT)) playerPosition.x -= 0.2f;
|
||||
else if (IsKeyDown(KEY_DOWN)) playerPosition.z += 0.2f;
|
||||
else if (IsKeyDown(KEY_UP)) playerPosition.z -= 0.2f;
|
||||
|
||||
|
||||
collision = false;
|
||||
|
||||
|
||||
// Check collisions player vs enemy-box
|
||||
if (CheckCollisionBoxes(
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new Vector3( playerPosition.x + playerSize.x/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2,
|
||||
enemyBoxPos.y - enemyBoxSize.y/2,
|
||||
enemyBoxPos.z - enemyBoxSize.z/2 ),
|
||||
new BoundingBox(new Vector3( enemyBoxPos.x - enemyBoxSize.x/2,
|
||||
enemyBoxPos.y - enemyBoxSize.y/2,
|
||||
enemyBoxPos.z - enemyBoxSize.z/2 ),
|
||||
new Vector3( enemyBoxPos.x + enemyBoxSize.x/2,
|
||||
enemyBoxPos.y + enemyBoxSize.y/2,
|
||||
enemyBoxPos.y + enemyBoxSize.y/2,
|
||||
enemyBoxPos.z + enemyBoxSize.z/2 )))) collision = true;
|
||||
|
||||
|
||||
// Check collisions player vs enemy-sphere
|
||||
if (CheckCollisionBoxSphere(
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new BoundingBox(new Vector3( playerPosition.x - playerSize.x/2,
|
||||
playerPosition.y - playerSize.y/2,
|
||||
playerPosition.z - playerSize.z/2 ),
|
||||
new Vector3( playerPosition.x + playerSize.x/2,
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
playerPosition.y + playerSize.y/2,
|
||||
playerPosition.z + playerSize.z/2 )),
|
||||
enemySpherePos, enemySphereSize)) collision = true;
|
||||
|
||||
|
||||
if (collision) playerColor = RED;
|
||||
else playerColor = GREEN;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Draw enemy-box
|
||||
DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY);
|
||||
DrawCubeWires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY);
|
||||
|
||||
|
||||
// Draw enemy-sphere
|
||||
DrawSphere(enemySpherePos, enemySphereSize, GRAY);
|
||||
DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY);
|
||||
|
||||
|
||||
// Draw player
|
||||
DrawCubeV(playerPosition, playerSize, playerColor);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Move player with cursors to collide", 220, 40, 20, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,39 +15,39 @@ public partial class models_cubicmap
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 16.0f, 14.0f, 16.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
||||
|
||||
|
||||
Mesh mesh = GenMeshCubicmap(image, new Vector3( 1.0f, 1.0f, 1.0f ));
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
|
||||
|
||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
|
||||
|
||||
Vector3 mapPosition = new Vector3( -16.0f, 0.0f, -8.0f ); // Set model position
|
||||
|
||||
|
||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -55,40 +55,40 @@ public partial class models_cubicmap
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, mapPosition, 1.0f, WHITE);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawTextureEx(cubicmap, new Vector2( screenWidth - cubicmap.width*4 - 20, 20 ), 0.0f, 4.0f, WHITE);
|
||||
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
|
||||
|
||||
|
||||
DrawText("cubicmap image used to", 658, 90, 10, GRAY);
|
||||
DrawText("generate map 3d model", 658, 104, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(cubicmap); // Unload cubicmap texture
|
||||
UnloadTexture(texture); // Unload map texture
|
||||
UnloadModel(model); // Unload map model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ public partial class models_geometric_shapes
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 0.0f, 10.0f, 10.0f );
|
||||
@ -32,10 +32,10 @@ public partial class models_geometric_shapes
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f );
|
||||
camera.fovy = 45.0f;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -43,44 +43,44 @@ public partial class models_geometric_shapes
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, GOLD);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawSphere(new Vector3(-1.0f, 0.0f, -2.0f), 1.0f, GREEN);
|
||||
DrawSphereWires(new Vector3(1.0f, 0.0f, 2.0f), 2.0f, 16, 16, LIME);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
|
||||
DrawCylinderWires(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
|
||||
DrawCylinderWires(new Vector3(4.5f, -1.0f, 2.0f), 1.0f, 1.0f, 2.0f, 6, BROWN);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, GOLD);
|
||||
DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,36 +15,36 @@ public partial class models_heightmap
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||
|
||||
|
||||
// Define our custom camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 18.0f, 16.0f, 18.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
||||
|
||||
|
||||
Mesh mesh = GenMeshHeightmap(image, new Vector3( 16, 8, 16 )); // Generate heightmap mesh (RAM and VRAM)
|
||||
Model model = LoadModelFromMesh(mesh); // Load model from generated mesh
|
||||
|
||||
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
Vector3 mapPosition = new Vector3( -8.0f, 0.0f, -8.0f ); // Define model position
|
||||
|
||||
|
||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set an orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -52,38 +52,38 @@ public partial class models_heightmap
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, mapPosition, 1.0f, RED);
|
||||
|
||||
|
||||
DrawGrid(20, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE);
|
||||
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,26 +15,26 @@ public partial class models_mesh_generation
|
||||
* Copyright (c) 2017 Ramon Santamaria (Ray San)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const int NUM_MODELS = 7;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation");
|
||||
|
||||
|
||||
// We generate a isChecked image for texturing
|
||||
Image isChecked = GenImageChecked(2, 2, 1, 1, RED, GREEN);
|
||||
Texture2D texture = LoadTextureFromImage(isChecked);
|
||||
UnloadImage(isChecked);
|
||||
|
||||
|
||||
Model[] models = new Model[NUM_MODELS];
|
||||
|
||||
|
||||
models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5));
|
||||
models[1] = LoadModelFromMesh(GenMeshCube(2.0f, 1.0f, 2.0f));
|
||||
models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32));
|
||||
@ -42,54 +42,54 @@ public partial class models_mesh_generation
|
||||
models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16));
|
||||
models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0f, 16, 32));
|
||||
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
|
||||
|
||||
|
||||
// Set isChecked texture as default diffuse component for all models material
|
||||
for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[(int)MAP_ALBEDO].texture = texture;
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 5.0f, 5.0f, 5.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
|
||||
// Model drawing position
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
int currentModel = 0;
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_ORBITAL); // Set a orbital camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update internal camera and our camera
|
||||
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
currentModel = (currentModel + 1)%NUM_MODELS; // Cycle between the textures
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(models[currentModel], position, 1.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f));
|
||||
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f));
|
||||
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE);
|
||||
|
||||
|
||||
switch(currentModel)
|
||||
{
|
||||
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE); break;
|
||||
@ -101,20 +101,20 @@ public partial class models_mesh_generation
|
||||
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Unload models data (GPU VRAM)
|
||||
for (int i = 0; i < NUM_MODELS; i++) UnloadModel(models[i]);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,19 +17,19 @@ public partial class models_mesh_picking
|
||||
* Example contributed by Joel Davis (@joeld42)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const float FLT_MAX = 3.40282347E+38F;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
camera.position = new Vector3( 20.0f, 20.0f, 20.0f ); // Camera3D position
|
||||
@ -37,27 +37,27 @@ public partial class models_mesh_picking
|
||||
camera.up = new Vector3( 0.0f, 1.6f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Ray ray; // Picking ray
|
||||
|
||||
|
||||
Model tower = LoadModel("resources/models/turret.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png"); // Load model texture
|
||||
tower.material.maps[(int)MAP_ALBEDO].texture = texture; // Set model diffuse texture
|
||||
|
||||
|
||||
Vector3 towerPos = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
BoundingBox towerBBox = MeshBoundingBox(tower.mesh); // Get mesh bounding box
|
||||
bool hitMeshBBox = false;
|
||||
bool hitTriangle = false;
|
||||
|
||||
|
||||
// Test triangle
|
||||
Vector3 ta = new Vector3( -25.0f, 0.5f, 0.0f );
|
||||
Vector3 ta = new Vector3( -25.0f, 0.5f, 0.0f );
|
||||
Vector3 tb = new Vector3( -4.0f, 2.5f, 1.0f );
|
||||
Vector3 tc = new Vector3( -8.0f, 6.5f, 0.0f );
|
||||
|
||||
Vector3 bary = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
|
||||
Vector3 bary = new Vector3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FREE); // Set a free camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Main game loop
|
||||
@ -66,143 +66,143 @@ public partial class models_mesh_picking
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
|
||||
|
||||
// Display information about closest hit
|
||||
RayHitInfo nearestHit = new RayHitInfo();
|
||||
string hitObjectName = "None";
|
||||
nearestHit.distance = FLT_MAX;
|
||||
nearestHit.hit = false;
|
||||
Color cursorColor = WHITE;
|
||||
|
||||
|
||||
// Get ray and test against ground, triangle, and mesh
|
||||
ray = GetMouseRay(GetMousePosition(), camera);
|
||||
|
||||
|
||||
// Check ray collision aginst ground plane
|
||||
RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f);
|
||||
|
||||
|
||||
if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = groundHitInfo;
|
||||
cursorColor = GREEN;
|
||||
hitObjectName = "Ground";
|
||||
}
|
||||
|
||||
|
||||
// Check ray collision against test triangle
|
||||
RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc);
|
||||
|
||||
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
|
||||
|
||||
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = triHitInfo;
|
||||
cursorColor = PURPLE;
|
||||
hitObjectName = "Triangle";
|
||||
|
||||
|
||||
bary = Vector3Barycenter(nearestHit.position, ta, tb, tc);
|
||||
hitTriangle = true;
|
||||
}
|
||||
}
|
||||
else hitTriangle = false;
|
||||
|
||||
|
||||
RayHitInfo meshHitInfo;
|
||||
|
||||
|
||||
// Check ray collision against bounding box first, before trying the full ray-mesh test
|
||||
if (CheckCollisionRayBox(ray, towerBBox))
|
||||
if (CheckCollisionRayBox(ray, towerBBox))
|
||||
{
|
||||
hitMeshBBox = true;
|
||||
|
||||
|
||||
// Check ray collision against model
|
||||
// NOTE: It considers model.transform matrix!
|
||||
meshHitInfo = GetCollisionRayModel(ray, ref tower);
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
meshHitInfo = GetCollisionRayModel(ray, ref tower);
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
{
|
||||
nearestHit = meshHitInfo;
|
||||
cursorColor = ORANGE;
|
||||
hitObjectName = "Mesh";
|
||||
}
|
||||
|
||||
} hitMeshBBox = false;
|
||||
|
||||
} hitMeshBBox = false;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Draw the tower
|
||||
// WARNING: If scale is different than 1.0f,
|
||||
// WARNING: If scale is different than 1.0f,
|
||||
// not considered by GetCollisionRayModel()
|
||||
DrawModel(tower, towerPos, 1.0f, WHITE);
|
||||
|
||||
|
||||
// Draw the test triangle
|
||||
DrawLine3D(ta, tb, PURPLE);
|
||||
DrawLine3D(tb, tc, PURPLE);
|
||||
DrawLine3D(tc, ta, PURPLE);
|
||||
|
||||
|
||||
// Draw the mesh bbox if we hit it
|
||||
if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME);
|
||||
|
||||
|
||||
// If we hit something, draw the cursor at the hit point
|
||||
if (nearestHit.hit)
|
||||
if (nearestHit.hit)
|
||||
{
|
||||
DrawCube(nearestHit.position, 0.3f, 0.3f, 0.3f, cursorColor);
|
||||
DrawCubeWires(nearestHit.position, 0.3f, 0.3f, 0.3f, RED);
|
||||
|
||||
|
||||
Vector3 normalEnd;
|
||||
normalEnd.x = nearestHit.position.x + nearestHit.normal.x;
|
||||
normalEnd.y = nearestHit.position.y + nearestHit.normal.y;
|
||||
normalEnd.z = nearestHit.position.z + nearestHit.normal.z;
|
||||
|
||||
|
||||
DrawLine3D(nearestHit.position, normalEnd, RED);
|
||||
}
|
||||
|
||||
|
||||
DrawRay(ray, MAROON);
|
||||
|
||||
|
||||
DrawGrid(10, 10.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw some debug GUI text
|
||||
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
|
||||
|
||||
if (nearestHit.hit)
|
||||
|
||||
if (nearestHit.hit)
|
||||
{
|
||||
int ypos = 70;
|
||||
|
||||
|
||||
DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK);
|
||||
|
||||
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
|
||||
nearestHit.position.x,
|
||||
nearestHit.position.y,
|
||||
|
||||
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
|
||||
nearestHit.position.x,
|
||||
nearestHit.position.y,
|
||||
nearestHit.position.z), 10, ypos + 15, 10, BLACK);
|
||||
|
||||
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||
nearestHit.normal.x,
|
||||
nearestHit.normal.y,
|
||||
|
||||
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||
nearestHit.normal.x,
|
||||
nearestHit.normal.y,
|
||||
nearestHit.normal.z), 10, ypos + 30, 10, BLACK);
|
||||
|
||||
|
||||
if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK);
|
||||
}
|
||||
|
||||
|
||||
DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY);
|
||||
|
||||
|
||||
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(tower); // Unload model
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,17 @@ public partial class models_obj_loading
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 8.0f, 8.0f, 8.0f ); // Camera3D position
|
||||
@ -33,15 +33,15 @@ public partial class models_obj_loading
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D mode type
|
||||
|
||||
|
||||
Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
|
||||
model.material.maps[(int)MAP_ALBEDO].texture = texture; // Set map diffuse texture
|
||||
Vector3 position = new Vector3( 0.0f, 0.0f, 0.0f ); // Set model position
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -49,39 +49,39 @@ public partial class models_obj_loading
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
DrawGizmo(position); // Draw gizmo
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
UnloadModel(model); // Unload model
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public partial class models_orthographic_projection
|
||||
{
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
||||
*
|
||||
* This program is heavily based on the geometric objects example
|
||||
*
|
||||
@ -17,88 +17,88 @@ public partial class models_orthographic_projection
|
||||
* Copyright (c) 2018 Max Danielsson ref Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public const float FOVY_PERSPECTIVE = 45.0f;
|
||||
public const float WIDTH_ORTHOGRAPHIC = 10.0f;
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 0.0f, 10.0f, 10.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE );
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
camera.fovy = WIDTH_ORTHOGRAPHIC;
|
||||
camera.type = CAMERA_ORTHOGRAPHIC;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
camera.fovy = FOVY_PERSPECTIVE;
|
||||
camera.type = CAMERA_PERSPECTIVE;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawCube(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, RED);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, 2.0f), 2.0f, 5.0f, 2.0f, GOLD);
|
||||
DrawCubeWires(new Vector3(-4.0f, 0.0f, -2.0f), 3.0f, 6.0f, 2.0f, MAROON);
|
||||
|
||||
|
||||
DrawSphere(new Vector3(-1.0f, 0.0f, -2.0f), 1.0f, GREEN);
|
||||
DrawSphereWires(new Vector3(1.0f, 0.0f, 2.0f), 2.0f, 16, 16, LIME);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
|
||||
DrawCylinderWires(new Vector3(4.0f, 0.0f, -2.0f), 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
|
||||
DrawCylinderWires(new Vector3(4.5f, -1.0f, 2.0f), 1.0f, 1.0f, 2.0f, 6, BROWN);
|
||||
|
||||
|
||||
DrawCylinder(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, GOLD);
|
||||
DrawCylinderWires(new Vector3(1.0f, 0.0f, -4.0f), 0.0f, 1.5f, 3.0f, 8, PINK);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY);
|
||||
|
||||
|
||||
if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK);
|
||||
else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,48 +15,48 @@ public partial class models_skybox
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
public static int Main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800;
|
||||
int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera = new Camera3D(new Vector3( 1.0f, 1.0f, 1.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ), 45.0f, 0 );
|
||||
|
||||
// Load skybox model
|
||||
|
||||
// Load skybox model
|
||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||
Model skybox = LoadModelFromMesh(cube);
|
||||
|
||||
|
||||
// Load skybox shader and set required locations
|
||||
// NOTE: Some locations are automatically set at shader loading
|
||||
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs");
|
||||
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), new int[]{ (int)MAP_CUBEMAP }, 1);
|
||||
|
||||
|
||||
// Load cubemap shader and setup required shader locations
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs");
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), new int[]{ 0 }, 1);
|
||||
|
||||
|
||||
// Load HDR panorama (sphere) texture
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr");
|
||||
|
||||
|
||||
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
|
||||
// NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
|
||||
skybox.material.maps[(int)MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512);
|
||||
|
||||
|
||||
UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated
|
||||
UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore
|
||||
|
||||
|
||||
SetCameraMode(camera, (int)CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
@ -64,34 +64,34 @@ public partial class models_skybox
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(ref camera); // Update camera
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(skybox, new Vector3(0, 0, 0), 1.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(skybox); // Unload skybox model (and textures)
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ public partial class models_yaw_pitch_roll
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
// Draw angle gauge controls
|
||||
//void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -33,42 +33,42 @@ public partial class models_yaw_pitch_roll
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)");
|
||||
|
||||
|
||||
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png");
|
||||
Texture2D texBackground = LoadTexture("resources/background.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[(int)MAP_ALBEDO].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture
|
||||
|
||||
|
||||
GenTextureMipmaps(ref model.material.maps[(int)MAP_ALBEDO].texture);
|
||||
|
||||
|
||||
Camera3D camera = new Camera3D();
|
||||
camera.position = new Vector3( 0.0f, 60.0f, -120.0f );// Camera3D position perspective
|
||||
camera.target = new Vector3( 0.0f, 12.0f, 0.0f ); // Camera3D looking at point
|
||||
camera.up = new Vector3( 0.0f, 1.0f, 0.0f ); // Camera3D up vector (rotation towards target)
|
||||
camera.fovy = 30.0f; // Camera3D field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE; // Camera3D type
|
||||
|
||||
|
||||
float pitch = 0.0f;
|
||||
float roll = 0.0f;
|
||||
float yaw = 0.0f;
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// Plane roll (x-axis) controls
|
||||
if (IsKeyDown(KEY_LEFT)) roll += 1.0f;
|
||||
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f;
|
||||
@ -77,7 +77,7 @@ public partial class models_yaw_pitch_roll
|
||||
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;
|
||||
@ -86,7 +86,7 @@ public partial class models_yaw_pitch_roll
|
||||
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;
|
||||
@ -95,101 +95,101 @@ public partial class models_yaw_pitch_roll
|
||||
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 = (int)pitch;
|
||||
while (pitchOffset > 180) pitchOffset -= 360;
|
||||
while (pitchOffset < -180) pitchOffset += 360;
|
||||
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;
|
||||
float scaleFactor = 0.5f;
|
||||
|
||||
|
||||
BeginTextureMode(framebuffer);
|
||||
|
||||
|
||||
BeginBlendMode((int)BLEND_ALPHA);
|
||||
|
||||
|
||||
DrawTexturePro(texBackground, new Rectangle( 0, 0, texBackground.width, texBackground.height ),
|
||||
new Rectangle( centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor),
|
||||
new Vector2( texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
|
||||
|
||||
|
||||
DrawTexturePro(texPitch, new Rectangle( 0, 0, texPitch.width, texPitch.height ),
|
||||
new Rectangle( centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor ),
|
||||
new Vector2( texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor ), roll, WHITE);
|
||||
|
||||
|
||||
DrawTexturePro(texPlane, new Rectangle( 0, 0, texPlane.width, texPlane.height ),
|
||||
new Rectangle( centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor ),
|
||||
new Vector2( texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor ), 0, WHITE);
|
||||
|
||||
|
||||
EndBlendMode();
|
||||
|
||||
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
// Draw 3D model (recomended to draw 3D always before 2D)
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
DrawModel(model, new Vector3( 0, 6.0f, 0 ), 1.0f, WHITE); // Draw 3d model with texture
|
||||
DrawGrid(10, 10.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw 2D GUI stuff
|
||||
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);
|
||||
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 390, 10, DARKGRAY);
|
||||
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY);
|
||||
|
||||
|
||||
// Draw framebuffer texture
|
||||
DrawTextureRec(framebuffer.texture, new Rectangle( 0, 0, framebuffer.texture.width, -framebuffer.texture.height ),
|
||||
new 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(texBackground);
|
||||
UnloadTexture(texPitch);
|
||||
UnloadTexture(texPlane);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Draw angle gauge controls
|
||||
static void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, string title, Color color)
|
||||
{
|
||||
@ -197,10 +197,10 @@ public partial class models_yaw_pitch_roll
|
||||
Rectangle dstRec = new Rectangle( x, y, angleGauge.width, angleGauge.height );
|
||||
Vector2 origin = new Vector2( angleGauge.width/2, angleGauge.height/2);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user