Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
9
.gitignore
vendored
|
|
@ -114,3 +114,12 @@ project/vs2015/*.opendb
|
||||||
docs/examples/web/*.html
|
docs/examples/web/*.html
|
||||||
docs/examples/web/*/*.html
|
docs/examples/web/*/*.html
|
||||||
!docs/examples/web/loader.html
|
!docs/examples/web/loader.html
|
||||||
|
!docs/examples/web/core/loader.html
|
||||||
|
!docs/examples/web/shapes/loader.html
|
||||||
|
!docs/examples/web/text/loader.html
|
||||||
|
!docs/examples/web/textures/loader.html
|
||||||
|
!docs/examples/web/audio/loader.html
|
||||||
|
!docs/examples/web/physac/loader.html
|
||||||
|
!docs/examples/web/shaders/loader.html
|
||||||
|
!docs/examples/web/models/loader.html
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ $(document).ready(function() {
|
||||||
'shapes_basic_shapes',
|
'shapes_basic_shapes',
|
||||||
'shapes_colors_palette',
|
'shapes_colors_palette',
|
||||||
'shapes_logo_raylib_anim',
|
'shapes_logo_raylib_anim',
|
||||||
|
'shapes_lines_bezier',
|
||||||
'textures_logo_raylib',
|
'textures_logo_raylib',
|
||||||
'textures_image_loading',
|
'textures_image_loading',
|
||||||
'textures_rectangle',
|
'textures_rectangle',
|
||||||
|
|
@ -35,18 +36,19 @@ $(document).ready(function() {
|
||||||
'textures_image_drawing',
|
'textures_image_drawing',
|
||||||
'text_sprite_fonts',
|
'text_sprite_fonts',
|
||||||
'text_bmfont_ttf',
|
'text_bmfont_ttf',
|
||||||
'text_rbmf_fonts',
|
'text_raylib_fonts',
|
||||||
'text_format_text',
|
'text_format_text',
|
||||||
'text_writing_anim',
|
'text_writing_anim',
|
||||||
'text_ttf_loading',
|
'text_ttf_loading',
|
||||||
'text_bmfont_unordered',
|
'text_bmfont_unordered',
|
||||||
|
'text_input_box',
|
||||||
'models_geometric_shapes',
|
'models_geometric_shapes',
|
||||||
'models_box_collisions',
|
'models_box_collisions',
|
||||||
'models_billboard',
|
'models_billboard',
|
||||||
'models_obj_loading',
|
'models_obj_loading',
|
||||||
'models_heightmap',
|
'models_heightmap',
|
||||||
'models_cubicmap',
|
'models_cubicmap',
|
||||||
'models_ray_picking',
|
'models_mesh_picking',
|
||||||
'shaders_model_shader',
|
'shaders_model_shader',
|
||||||
'shaders_shapes_textures',
|
'shaders_shapes_textures',
|
||||||
'shaders_custom_uniform',
|
'shaders_custom_uniform',
|
||||||
|
|
@ -56,68 +58,16 @@ $(document).ready(function() {
|
||||||
'audio_module_playing',
|
'audio_module_playing',
|
||||||
'audio_raw_stream'];
|
'audio_raw_stream'];
|
||||||
|
|
||||||
var exampleDesc = [
|
|
||||||
'basic window',
|
|
||||||
'input keys',
|
|
||||||
'input mouse',
|
|
||||||
'mouse wheel',
|
|
||||||
'input gamepad',
|
|
||||||
'random values',
|
|
||||||
'color select',
|
|
||||||
'drop files',
|
|
||||||
'storage values',
|
|
||||||
'gestures detection',
|
|
||||||
'3d mode',
|
|
||||||
'3d picking',
|
|
||||||
'3d camera free',
|
|
||||||
'3d camera first person',
|
|
||||||
'2d camera',
|
|
||||||
'world screen',
|
|
||||||
'vr simulator',
|
|
||||||
'logo raylib shapes',
|
|
||||||
'basic shapes',
|
|
||||||
'colors palette',
|
|
||||||
'logo raylib anim',
|
|
||||||
'logo raylib texture',
|
|
||||||
'image loading',
|
|
||||||
'texture rectangle',
|
|
||||||
'src-dest. rectangles',
|
|
||||||
'texture to image',
|
|
||||||
'raw data loading',
|
|
||||||
'image processing',
|
|
||||||
'image drawing',
|
|
||||||
'sprite fonts',
|
|
||||||
'bmfonts ttf',
|
|
||||||
'rbmf fonts',
|
|
||||||
'text formatting',
|
|
||||||
'writing animation',
|
|
||||||
'ttf loading',
|
|
||||||
'bmfont unordered',
|
|
||||||
'geometric shapes',
|
|
||||||
'box collisions',
|
|
||||||
'billboard drawing',
|
|
||||||
'obj loading',
|
|
||||||
'heightmap loading',
|
|
||||||
'cubesmap loading',
|
|
||||||
'mesh ray picking',
|
|
||||||
'model shader',
|
|
||||||
'shapes textures shader',
|
|
||||||
'custom uniform in shaders',
|
|
||||||
'postprocessing shaders',
|
|
||||||
'standard lighting',
|
|
||||||
'sound loading',
|
|
||||||
'music streaming',
|
|
||||||
'module playing',
|
|
||||||
'raw stream'];
|
|
||||||
|
|
||||||
for (var i = 0; i < exampleName.length; i++)
|
for (var i = 0; i < exampleName.length; i++)
|
||||||
{
|
{
|
||||||
var filterType = exampleName[i].substring(0, exampleName[i].indexOf("_"));
|
var filterType = exampleName[i].substring(0, exampleName[i].indexOf("_"));
|
||||||
|
var exampleBase = exampleName[i].slice(exampleName[i].indexOf('_') + 1);
|
||||||
|
var exampleDesc = exampleBase.replace('_', ' ');
|
||||||
|
|
||||||
$('#container').append(
|
$('#container').append(
|
||||||
'<div class="mix f' + filterType + '">' +
|
'<div class="mix f' + filterType + '">' +
|
||||||
'<a class="fancybox fancybox.iframe" href="examples/web/loader.html?name=' + filterType + '/' + exampleName[i] + '" title="' + exampleDesc[i] + '">' +
|
'<a class="fancybox fancybox.iframe" href="examples/web/' + filterType + '/' + 'loader.html?name=' + exampleName[i] + '" title="' + exampleDesc + '">' +
|
||||||
'<img width="400" height="225" src="../examples/img/' + filterType + '/' + exampleName[i] + '.png"><div class="extext"><p>' + exampleDesc[i] + '</p></div></a>' +
|
'<img width="400" height="225" src="../examples/web/' + filterType + '/' + exampleName[i] + '.png"><div class="extext"><p>' + exampleDesc + '</p></div></a>' +
|
||||||
'</div>');
|
'</div>');
|
||||||
|
|
||||||
$('#container a .extext').hide();
|
$('#container a .extext').hide();
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,12 @@ $(document).ready(function() {
|
||||||
'sample_space_invaders',
|
'sample_space_invaders',
|
||||||
'sample_floppy',
|
'sample_floppy',
|
||||||
'sample_tetris',
|
'sample_tetris',
|
||||||
'sample_gold_fever',
|
|
||||||
'sample_doom',
|
|
||||||
'game_raylib_features',
|
|
||||||
'game_drturtle',
|
'game_drturtle',
|
||||||
'game_just_do',
|
'game_just_do',
|
||||||
'game_skully_escape',
|
'game_skully_escape',
|
||||||
'game_koala_seasons',
|
'game_koala_seasons',
|
||||||
'game_light_my_ritual',
|
'game_light_my_ritual',
|
||||||
|
'game_wave_collector',
|
||||||
'user_raymario',
|
'user_raymario',
|
||||||
'user_crazyball',
|
'user_crazyball',
|
||||||
'user_tictactoe',
|
'user_tictactoe',
|
||||||
|
|
@ -40,14 +38,12 @@ $(document).ready(function() {
|
||||||
'space invaders',
|
'space invaders',
|
||||||
'floppy',
|
'floppy',
|
||||||
'tetris',
|
'tetris',
|
||||||
'gold fever',
|
|
||||||
'doom',
|
|
||||||
'raylib Features DEMO',
|
|
||||||
'Dr Turtle & Mr Gamera',
|
'Dr Turtle & Mr Gamera',
|
||||||
'JUST DO',
|
'JUST DO',
|
||||||
'Skully Escape',
|
'Skully Escape',
|
||||||
'Koala Seasons',
|
'Koala Seasons',
|
||||||
'LIGHT MY RITUAL',
|
'LIGHT MY RITUAL',
|
||||||
|
'Wave Collector',
|
||||||
'RayMario (Victor Fisac)',
|
'RayMario (Victor Fisac)',
|
||||||
'CrazyBall (Victor Fisac)',
|
'CrazyBall (Victor Fisac)',
|
||||||
'Tic-Tac-Toe (LelixSuper)',
|
'Tic-Tac-Toe (LelixSuper)',
|
||||||
|
|
@ -83,8 +79,6 @@ $(document).ready(function() {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exampleName[i] == 'game_koala_seasons') linkTag = '<a target="_blank" href="http://www.koalaseasons.com" title="' + exampleDesc[i] + '">';
|
|
||||||
|
|
||||||
$('#container').append(
|
$('#container').append(
|
||||||
'<div class="mix f' + filterType + '">' + linkTag +
|
'<div class="mix f' + filterType + '">' + linkTag +
|
||||||
'<img width="400" height="225" src="../games/img/' + exampleName[i] + '.png"><div class="extext"><p>' + exampleDesc[i] + '</p></div></a>' +
|
'<img width="400" height="225" src="../games/img/' + exampleName[i] + '.png"><div class="extext"><p>' + exampleDesc[i] + '</p></div></a>' +
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 246 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
|
@ -52,7 +52,7 @@ int main()
|
||||||
circles[i].color = colors[GetRandomValue(0, 13)];
|
circles[i].color = colors[GetRandomValue(0, 13)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Music xm = LoadMusicStream("resources/audio/mini1111.xm");
|
Music xm = LoadMusicStream("resources/mini1111.xm");
|
||||||
|
|
||||||
PlayMusicStream(xm);
|
PlayMusicStream(xm);
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
// Get timePlayed scaled to bar dimensions
|
||||||
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2;
|
timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40);
|
||||||
|
|
||||||
// Color circles animation
|
// Color circles animation
|
||||||
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
|
||||||
|
|
@ -112,7 +112,7 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(WHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ int main()
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg");
|
Music music = LoadMusicStream("resources/guitar_noodling.ogg");
|
||||||
|
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions (400 pixels)
|
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||||
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4;
|
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <math.h> // Required for: sinf()
|
#include <math.h> // Required for: sinf()
|
||||||
|
|
||||||
#define MAX_SAMPLES 20000
|
#define MAX_SAMPLES 22050
|
||||||
|
#define MAX_SAMPLES_PER_UPDATE 4096
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -29,21 +30,20 @@ int main()
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
// Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono)
|
||||||
AudioStream stream = InitAudioStream(22050, 32, 1);
|
AudioStream stream = InitAudioStream(22050, 16, 1);
|
||||||
|
|
||||||
// Fill audio stream with some samples (sine wave)
|
// Generate samples data from sine wave
|
||||||
float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES);
|
short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES);
|
||||||
|
|
||||||
|
// TODO: Review data generation, it seems data is discontinued for loop,
|
||||||
|
// for that reason, there is a clip everytime audio stream is looped...
|
||||||
for (int i = 0; i < MAX_SAMPLES; i++)
|
for (int i = 0; i < MAX_SAMPLES; i++)
|
||||||
{
|
{
|
||||||
data[i] = sinf(((2*PI*(float)i)/2)*DEG2RAD);
|
data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently)
|
||||||
// for that reason, there is a clip everytime audio stream is looped
|
|
||||||
|
|
||||||
PlayAudioStream(stream);
|
|
||||||
|
|
||||||
int totalSamples = MAX_SAMPLES;
|
int totalSamples = MAX_SAMPLES;
|
||||||
int samplesLeft = totalSamples;
|
int samplesLeft = totalSamples;
|
||||||
|
|
@ -60,10 +60,13 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Refill audio stream if required
|
// Refill audio stream if required
|
||||||
|
// NOTE: Every update we check if stream data has been already consumed and we update
|
||||||
|
// buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE),
|
||||||
|
// but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data...
|
||||||
if (IsAudioBufferProcessed(stream))
|
if (IsAudioBufferProcessed(stream))
|
||||||
{
|
{
|
||||||
int numSamples = 0;
|
int numSamples = 0;
|
||||||
if (samplesLeft >= 4096) numSamples = 4096;
|
if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE;
|
||||||
else numSamples = samplesLeft;
|
else numSamples = samplesLeft;
|
||||||
|
|
||||||
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
|
UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples);
|
||||||
|
|
@ -83,11 +86,11 @@ int main()
|
||||||
|
|
||||||
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
|
DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY);
|
||||||
|
|
||||||
// NOTE: Draw a part of the sine wave (only screen width)
|
// NOTE: Draw a part of the sine wave (only screen width, proportional values)
|
||||||
for (int i = 0; i < GetScreenWidth(); i++)
|
for (int i = 0; i < GetScreenWidth(); i++)
|
||||||
{
|
{
|
||||||
position.x = i;
|
position.x = i;
|
||||||
position.y = 250 + 50*data[i];
|
position.y = 250 + 50*data[i]/32000;
|
||||||
|
|
||||||
DrawPixelV(position, RED);
|
DrawPixelV(position, RED);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ int main()
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
*
|
*
|
||||||
* NOTE: This example requires a Gamepad connected to the system
|
* NOTE: This example requires a Gamepad connected to the system
|
||||||
* raylib is configured to work with the following gamepads:
|
* raylib is configured to work with the following gamepads:
|
||||||
* Xbox 360 Controller (Xbox 360, Xbox One)
|
* - Xbox 360 Controller (Xbox 360, Xbox One)
|
||||||
* PLAYSTATION(R)3 Controller
|
* - PLAYSTATION(R)3 Controller
|
||||||
* Check raylib.h for buttons configuration
|
* Check raylib.h for buttons configuration
|
||||||
*
|
*
|
||||||
* This example has been created using raylib 1.6 (www.raylib.com)
|
* This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Oculus Rift CV1
|
* raylib [core] example - VR Simulator (Oculus Rift CV1 parameters)
|
||||||
*
|
*
|
||||||
* Compile example using:
|
* This example has been created using raylib 1.7 (www.raylib.com)
|
||||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -L. -L..\src\external\OculusSDK\LibOVR -lLibOVRRT32_1 -lraylib -lglfw3 -lopengl32 -lgdi32 -std=c99
|
|
||||||
*
|
|
||||||
* This example has been created using raylib 1.5 (www.raylib.com)
|
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
@ -23,10 +20,9 @@ int main()
|
||||||
|
|
||||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator");
|
||||||
|
|
||||||
// NOTE: If device is not available, it fallbacks to default device (simulator)
|
InitVrSimulator(HMD_OCULUS_RIFT_CV1); // Init VR simulator (Oculus Rift CV1 parameters)
|
||||||
InitVrDevice(HMD_OCULUS_RIFT_CV1); // Init VR device (Oculus Rift CV1)
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera;
|
Camera camera;
|
||||||
|
|
@ -47,10 +43,9 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode)
|
UpdateCamera(&camera); // Update camera (simulator mode)
|
||||||
else if (IsVrDeviceReady()) UpdateVrTracking(&camera); // Update camera with device tracking data
|
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
|
||||||
if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -58,15 +53,19 @@ int main()
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginVrDrawing();
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawGrid(40, 1.0f);
|
DrawGrid(40, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
EndVrDrawing();
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|
@ -76,10 +75,10 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
CloseVrDevice(); // Close VR device
|
CloseVrSimulator(); // Close VR simulator
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
195
docs/examples/src/models/models_mesh_picking.c
Normal file
|
|
@ -0,0 +1,195 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.7 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
* Example contributed by Joel Davis (@joeld42)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
#define FLT_MAX 3.40282347E+38F // Maximum value of a float, defined in <float.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
Camera camera;
|
||||||
|
camera.position = (Vector3){ 10.0f, 8.0f, 10.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 2.3f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
|
||||||
|
Ray ray; // Picking ray
|
||||||
|
|
||||||
|
Model tower = LoadModel("resources/tower.obj"); // Load OBJ model
|
||||||
|
Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture
|
||||||
|
tower.material.texDiffuse = texture; // Set model diffuse texture
|
||||||
|
|
||||||
|
Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
BoundingBox towerBBox = CalculateBoundingBox(tower.mesh);
|
||||||
|
bool hitMeshBBox = false;
|
||||||
|
bool hitTriangle = false;
|
||||||
|
|
||||||
|
// Test triangle
|
||||||
|
Vector3 ta = (Vector3){ -25.0, 0.5, 0.0 };
|
||||||
|
Vector3 tb = (Vector3){ -4.0, 2.5, 1.0 };
|
||||||
|
Vector3 tc = (Vector3){ -8.0, 6.5, 0.0 };
|
||||||
|
|
||||||
|
Vector3 bary = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
SetCameraMode(camera, CAMERA_FREE); // Set a free 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(&camera); // Update camera
|
||||||
|
|
||||||
|
// Display information about closest hit
|
||||||
|
RayHitInfo nearestHit;
|
||||||
|
char *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))
|
||||||
|
{
|
||||||
|
nearestHit = triHitInfo;
|
||||||
|
cursorColor = PURPLE;
|
||||||
|
hitObjectName = "Triangle";
|
||||||
|
|
||||||
|
bary = VectorBarycenter(nearestHit.hitPosition, 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))
|
||||||
|
{
|
||||||
|
hitMeshBBox = true;
|
||||||
|
|
||||||
|
// Check ray collision against mesh
|
||||||
|
meshHitInfo = GetCollisionRayMesh(ray, &tower.mesh);
|
||||||
|
|
||||||
|
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||||
|
{
|
||||||
|
nearestHit = meshHitInfo;
|
||||||
|
cursorColor = ORANGE;
|
||||||
|
hitObjectName = "Mesh";
|
||||||
|
}
|
||||||
|
|
||||||
|
} hitMeshBBox = false;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
Begin3dMode(camera);
|
||||||
|
|
||||||
|
// Draw the tower
|
||||||
|
DrawModel(tower, towerPos, 1.0, 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)
|
||||||
|
{
|
||||||
|
DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor);
|
||||||
|
DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED);
|
||||||
|
|
||||||
|
Vector3 normalEnd;
|
||||||
|
normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x;
|
||||||
|
normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y;
|
||||||
|
normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z;
|
||||||
|
|
||||||
|
DrawLine3D(nearestHit.hitPosition, normalEnd, RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRay(ray, MAROON);
|
||||||
|
|
||||||
|
DrawGrid(100, 1.0f);
|
||||||
|
|
||||||
|
End3dMode();
|
||||||
|
|
||||||
|
// Draw some debug GUI text
|
||||||
|
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK);
|
||||||
|
|
||||||
|
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.hitPosition.x,
|
||||||
|
nearestHit.hitPosition.y,
|
||||||
|
nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK);
|
||||||
|
|
||||||
|
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||||
|
nearestHit.hitNormal.x,
|
||||||
|
nearestHit.hitNormal.y,
|
||||||
|
nearestHit.hitNormal.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);
|
||||||
|
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadModel(tower); // Unload model
|
||||||
|
UnloadTexture(texture); // Unload texture
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -2,17 +2,22 @@
|
||||||
*
|
*
|
||||||
* Physac - Physics demo
|
* Physac - Physics demo
|
||||||
*
|
*
|
||||||
* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations.
|
||||||
* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external'
|
* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 Victor Fisac
|
* Use the following line to compile:
|
||||||
|
*
|
||||||
|
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
|
||||||
|
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017 Victor Fisac
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "physac.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -114,9 +119,10 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
ClosePhysics(); // Unitialize physics
|
ClosePhysics(); // Uninitialize physics
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||