Merge pull request #198 from raysan5/develop

Develop branch integration
This commit is contained in:
Ray 2016-11-24 17:26:07 +01:00 • committed by GitHub
commit 17f09cb034
87 changed files with 6812 additions and 4082 deletions

View file

@ -11,21 +11,25 @@ NOTE:
It includes some interesting new features and is a stepping stone towards raylib future. It includes some interesting new features and is a stepping stone towards raylib future.
HUGE changes: HUGE changes:
[rlua] LUA BINDING: Complete raylib LUA binding, all raylib functions ported to LUA plus the +60 code examples. [rlua] LUA BINDING: Complete raylib LUA binding, ALL raylib functions ported to LUA plus the +60 code examples.
[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing. FLAC support added. [audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing, +20 new functions added.
[physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples! [physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples!
other changes: Other changes:
[core] Corrected issue on OSX with HighDPI display [core] Corrected issue on OSX with HighDPI display
[core] Added flag to allow resizable window [core] Added flag to allow resizable window
[core] Allow no default font loading [core] Allow no default font loading
[core] Corrected old issue with mouse buttons on web [core] Corrected old issue with mouse buttons on web
[core] Improved gamepad support, unified across platforms [core] Improved gamepad support, unified across platforms
[core] Gamepad id functionality: GetGamepadName(), IsGamepadName()
[core] Gamepad buttons/axis checking functionality:
[core] Reviewed Android key inputs system, unified with desktop [core] Reviewed Android key inputs system, unified with desktop
[rlgl] Redesigned lighting shader system [rlgl] Redesigned lighting shader system
[rlgl] Reviewed UpdateVrTracking() and rlglLoadRenderTexture()
[rlgl] Updated standard shader for better performance [rlgl] Updated standard shader for better performance
[rlgl] Support alpha on framebuffer: rlglLoadRenderTexture()
[rlgl] Reviewed UpdateVrTracking() to update camera
[rlgl] Added IsVrSimulator() to check for VR simulator
[shapes] Corrected issue on DrawPolyEx() [shapes] Corrected issue on DrawPolyEx()
[textures] Simplified supported image formats support [textures] Simplified supported image formats support
[textures] Improved text drawing within an image: ImageDrawText() [textures] Improved text drawing within an image: ImageDrawText()
@ -33,17 +37,18 @@ other changes:
[textures] Support textures filtering: SetTextureFilter() [textures] Support textures filtering: SetTextureFilter()
[textures] Support textures wrap modes: SetTextureWrap() [textures] Support textures wrap modes: SetTextureWrap()
[text] Improved TTF spritefont generation: LoadSpriteFontTTF() [text] Improved TTF spritefont generation: LoadSpriteFontTTF()
[text] Improved AngelCode fonts support [text] Improved AngelCode fonts support (unordered chars)
[text] Reviewed spacing formatting
[text] Added TraceLog info on image spritefont loading [text] Added TraceLog info on image spritefont loading
[text] Improved text measurement: MeasureTextEx() [text] Improved text measurement: MeasureTextEx()
[models] Improved OBJ loading flexibility [models] Improved OBJ loading flexibility
[models] Reviewed functions: DrawLine3D(), DrawCircle3D()
[models] Removed function: ResolveCollisionCubicmap() [models] Removed function: ResolveCollisionCubicmap()
[camera] Redesigned camera system and ported to header-only [camera] Redesigned camera system and ported to header-only
[camera] Removed function: UpdateCameraPlayer()
[gestures] Redesigned gestures module to header-only [gestures] Redesigned gestures module to header-only
[audio] Simplified Music loading and playing system [audio] Simplified Music loading and playing system
[audio] Added trace on audio device closing [audio] Added trace on audio device closing
[audio] Reviewed Wave struct for reter flexivility [audio] Reviewed Wave struct, improved flexibility
[audio] Support sound data update: UpdateSound() [audio] Support sound data update: UpdateSound()
[audio] Added support for FLAC audio loading/streaming [audio] Added support for FLAC audio loading/streaming
[raygui] Removed raygui from raylib repo (moved to own repo) [raygui] Removed raygui from raylib repo (moved to own repo)
@ -52,8 +57,8 @@ other changes:
[build] Support shared/dynamic raylib compilation [build] Support shared/dynamic raylib compilation
[*] Updated LibOVR to SDK version 1.8 [*] Updated LibOVR to SDK version 1.8
[*] Updated games to latest raylib version [*] Updated games to latest raylib version
[*] Improved Android support
[*] Improved examples and added new ones [*] Improved examples and added new ones
[*] Improved Android support
----------------------------------------------- -----------------------------------------------
Release: raylib 1.5.0 (18 July 2016) Release: raylib 1.5.0 (18 July 2016)

View file

@ -160,7 +160,9 @@ On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new v
Complete raylib LUA binding. All raylib functions plus the +60 code examples have been ported to LUA, now LUA users can enjoy coding videogames in LUA while using all the internal power of raylib. This addition also open the doors to LUA scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to LUA scripts while keep using raylib functionality. Complete raylib LUA binding. All raylib functions plus the +60 code examples have been ported to LUA, now LUA users can enjoy coding videogames in LUA while using all the internal power of raylib. This addition also open the doors to LUA scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to LUA scripts while keep using raylib functionality.
Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added to allow raw audio processing and playing. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more! Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more!
Physac module has been moved to its own repository and it has been improved A LOT, actually, library has been completely rewritten from scratch by @victorfisac, multiple samples have been added together with countless new features to match current standard 2D physic libraries. Results are amazing!
Camera and gestures modules have been reviewed, highly simplified and ported to single-file header-only libraries for easier portability and usage flexibility. Consequently, camera system usage has been simplified in all examples. Camera and gestures modules have been reviewed, highly simplified and ported to single-file header-only libraries for easier portability and usage flexibility. Consequently, camera system usage has been simplified in all examples.
@ -168,8 +170,6 @@ Improved Gamepad support on Windows and Raspberry Pi with the addition of new fu
Improved textures and text functionality, adding new functions for texture filtering control and better TTF/AngelCode fonts loading and generation support. Improved textures and text functionality, adding new functions for texture filtering control and better TTF/AngelCode fonts loading and generation support.
Physac module has been moved to its own repository and it has been improved A LOT, actually, library has been completely rewritten by @victorfisac, multiple samples have been added and countless new features to match current standard 2D physic libraries.
Build system improvement. Added support for raylib dynamic library generation (raylib.dll) for users that prefer dynamic library linking. Also thinking on advance users, it has been added pre-configured Visual Studio C++ 2015 solution with raylib project and C/C++ examples for users that prefer that professional IDE and compiler. Build system improvement. Added support for raylib dynamic library generation (raylib.dll) for users that prefer dynamic library linking. Also thinking on advance users, it has been added pre-configured Visual Studio C++ 2015 solution with raylib project and C/C++ examples for users that prefer that professional IDE and compiler.
New examples, new functions, complete code-base review, multiple bugs corrected... this is raylib 1.6. Enjoy making games. New examples, new functions, complete code-base review, multiple bugs corrected... this is raylib 1.6. Enjoy making games.

View file

@ -2,6 +2,8 @@
# #
# raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten) # raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
# #
# NOTE: By default examples are compiled using raylib static library and OpenAL Soft shared library
#
# Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) # Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
# #
# This software is provided "as-is", without any express or implied warranty. In no event # This software is provided "as-is", without any express or implied warranty. In no event
@ -26,6 +28,9 @@
# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() # WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
PLATFORM ?= PLATFORM_DESKTOP PLATFORM ?= PLATFORM_DESKTOP
# define NO to use OpenAL Soft as static library (shared by default)
SHARED_OPENAL ?= YES
# determine PLATFORM_OS in case PLATFORM_DESKTOP selected # determine PLATFORM_OS in case PLATFORM_DESKTOP selected
ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM),PLATFORM_DESKTOP)
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
@ -62,12 +67,13 @@ endif
# define compiler flags: # define compiler flags:
# -O2 defines optimization level # -O2 defines optimization level
# -s strip unnecessary data from build
# -Wall turns on most, but not all, compiler warnings # -Wall turns on most, but not all, compiler warnings
# -std=c99 use standard C from 1999 revision # -std=c99 use standard C from 1999 revision
ifeq ($(PLATFORM),PLATFORM_RPI) ifeq ($(PLATFORM),PLATFORM_RPI)
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline
else else
CFLAGS = -O2 -Wall -std=c99 CFLAGS = -O2 -s -Wall -std=c99
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
@ -151,7 +157,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
else else
# libraries for Windows desktop compiling # libraries for Windows desktop compiling
# NOTE: GLFW3 and OpenAL Soft libraries should be installed # NOTE: GLFW3 and OpenAL Soft libraries should be installed
LIBS = -lraylib -lglfw3 -lopengl32 -lopenal32 -lgdi32 LIBS = -lraylib -lglfw3 -lopengl32 -lgdi32
# if static OpenAL Soft required, define the corresponding libs
ifeq ($(SHARED_OPENAL),NO)
LIBS += -lopenal32 -lwinmm
CFLAGS += -Wl,-allow-multiple-definition
else
LIBS += -lopenal32dll
endif
endif endif
endif endif
endif endif
@ -215,6 +228,8 @@ EXAMPLES = \
text_format_text \ text_format_text \
text_font_select \ text_font_select \
text_writing_anim \ text_writing_anim \
text_ttf_loading \
text_bmfont_unordered \
models_geometric_shapes \ models_geometric_shapes \
models_box_collisions \ models_box_collisions \
models_billboard \ models_billboard \
@ -230,6 +245,11 @@ EXAMPLES = \
audio_music_stream \ audio_music_stream \
audio_module_playing \ audio_module_playing \
audio_raw_stream \ audio_raw_stream \
physics_demo \
physics_friction \
physics_movement \
physics_restitution \
physics_shatter \
fix_dylib \ fix_dylib \
@ -400,6 +420,14 @@ text_font_select: text_font_select.c
text_writing_anim: text_writing_anim.c text_writing_anim: text_writing_anim.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - text ttf loading
text_ttf_loading: text_ttf_loading.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [text] example - text bmfont unordered
text_bmfont_unordered: text_bmfont_unordered.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [models] example - basic geometric 3d shapes # compile [models] example - basic geometric 3d shapes
models_geometric_shapes: models_geometric_shapes.c models_geometric_shapes: models_geometric_shapes.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
@ -464,6 +492,26 @@ audio_module_playing: audio_module_playing.c
audio_raw_stream: audio_raw_stream.c audio_raw_stream: audio_raw_stream.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics demo
physics_demo: physics_demo.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics friction
physics_friction: physics_friction.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics movement
physics_movement: physics_movement.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics restitution
physics_restitution: physics_restitution.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
# compile [physac] example - physics shatter
physics_shatter: physics_shatter.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
# fix dylib install path name for each executable (MAC) # fix dylib install path name for each executable (MAC)
fix_dylib: fix_dylib:
ifeq ($(PLATFORM_OS),OSX) ifeq ($(PLATFORM_OS),OSX)

View file

@ -30,6 +30,8 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)"); InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
@ -49,13 +51,6 @@ int main()
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f; circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
circles[i].color = colors[GetRandomValue(0, 13)]; circles[i].color = colors[GetRandomValue(0, 13)];
} }
// Load postprocessing bloom shader
Shader shader = LoadShader("resources/shaders/glsl330/base.vs",
"resources/shaders/glsl330/bloom.fs");
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
Music xm = LoadMusicStream("resources/audio/mini1111.xm"); Music xm = LoadMusicStream("resources/audio/mini1111.xm");
@ -117,28 +112,17 @@ int main()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(WHITE);
BeginTextureMode(target); // Enable drawing to texture for (int i = MAX_CIRCLES - 1; i >= 0; i--)
{
for (int i = MAX_CIRCLES - 1; i >= 0; i--) DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
{ }
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha));
}
EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
BeginShaderMode(shader);
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
EndShaderMode();
// Draw time bar // Draw time bar
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY); DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY);
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON); DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, MAROON);
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, WHITE); DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -146,9 +130,6 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadShader(shader); // Unload shader
UnloadRenderTexture(target); // Unload render texture
UnloadMusicStream(xm); // Unload music stream buffers from RAM UnloadMusicStream(xm); // Unload music stream buffers from RAM
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)

View file

@ -37,13 +37,6 @@ for i = MAX_CIRCLES, 1, -1 do
circles[i].color = colors[GetRandomValue(1, 14)] circles[i].color = colors[GetRandomValue(1, 14)]
end end
-- Load postprocessing bloom shader
local shader = LoadShader("resources/shaders/glsl330/base.vs",
"resources/shaders/glsl330/bloom.fs")
-- Create a RenderTexture2D to be used for render to texture
local target = LoadRenderTexture(screenWidth, screenHeight)
local xm = LoadMusicStream("resources/audio/mini1111.xm") local xm = LoadMusicStream("resources/audio/mini1111.xm")
PlayMusicStream(xm) PlayMusicStream(xm)
@ -83,22 +76,11 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
BeginDrawing() BeginDrawing()
ClearBackground(BLACK) ClearBackground(RAYWHITE)
BeginTextureMode(target) -- Enable drawing to texture for i = MAX_CIRCLES, 1, -1 do
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha))
for i = MAX_CIRCLES, 1, -1 do end
DrawCircleV(circles[i].position, circles[i].radius, Fade(circles[i].color, circles[i].alpha))
end
EndTextureMode() -- End drawing to texture (now we have a texture available for next passes)
BeginShaderMode(shader)
-- NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
DrawTextureRec(target.texture, Rectangle(0, 0, target.texture.width, -target.texture.height), Vector2(0, 0), WHITE)
EndShaderMode()
-- Draw time bar -- Draw time bar
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY) DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
@ -111,10 +93,7 @@ end
-- De-Initialization -- De-Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
UnloadShader(shader) -- Unload shader UnloadMusicStream(xm) -- Unload music stream buffers from RAM
UnloadRenderTexture(target) -- Unload render texture
UnloadMusicStream(xm) -- Unload music stream buffers from RAM
CloseAudioDevice() -- Close audio device (music streaming is automatically stopped) CloseAudioDevice() -- Close audio device (music streaming is automatically stopped)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -32,6 +32,8 @@
int main() int main()
{ {
// Initialization
//--------------------------------------------------------------------------------------
unsigned char key; unsigned char key;
InitAudioDevice(); InitAudioDevice();
@ -43,7 +45,9 @@ int main()
PlayMusicStream(music); PlayMusicStream(music);
printf("\nPress s or d to play sounds...\n"); printf("\nPress s or d to play sounds...\n");
//--------------------------------------------------------------------------------------
// Main loop
while (key != KEY_ESCAPE) while (key != KEY_ESCAPE)
{ {
if (kbhit()) key = getch(); if (kbhit()) key = getch();
@ -63,15 +67,15 @@ int main()
UpdateMusicStream(music); UpdateMusicStream(music);
} }
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadSound(fxWav); // Unload sound data UnloadSound(fxWav); // Unload sound data
UnloadSound(fxOgg); // Unload sound data UnloadSound(fxOgg); // Unload sound data
UnloadMusicStream(music); // Unload music stream data UnloadMusicStream(music); // Unload music stream data
CloseAudioDevice(); CloseAudioDevice();
//--------------------------------------------------------------------------------------
printf("\n\nPress ENTER to close...");
getchar();
return 0; return 0;
} }

View file

@ -19,7 +19,7 @@ local screenHeight = 450
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person") InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person")
-- Define the camera to look into our 3d world (position, target, up vector) -- Define the camera to look into our 3d world (position, target, up vector)
local camera = Camera(Vector3(0.0, 10.0, 10.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 60.0) local camera = Camera(Vector3(4.0, 2.0, 4.0), Vector3(0.0, 1.8, 0.0), Vector3(0.0, 1.0, 0.0), 60.0)
-- Generates some random columns -- Generates some random columns
local heights = {} local heights = {}
@ -34,17 +34,16 @@ end
local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position local playerPosition = Vector3(4.0, 2.0, 4.0) -- Define player position
SetCameraMode(CameraMode.FIRST_PERSON) -- Set a first person camera mode SetCameraMode(camera, CameraMode.FIRST_PERSON) -- Set a first person camera mode
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera, playerPosition = UpdateCameraPlayer(camera, playerPosition) -- Update camera and player position camera = UpdateCamera(camera) -- Update camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View file

@ -18,26 +18,23 @@ InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
-- Define the camera to look into our 3d world -- Define the camera to look into our 3d world
local camera = {} local camera = {}
camera.position = Vector3(0.0, 10.0, 10.0) -- Camera position camera.position = Vector3(10.0, 10.0, 10.0) -- Camera position
camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point camera.target = Vector3(0.0, 0.0, 0.0) -- Camera looking at point
camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target) camera.up = Vector3(0.0, 1.0, 0.0) -- Camera up vector (rotation towards target)
camera.fovy = 45.0 -- Camera field-of-view Y camera.fovy = 45.0 -- Camera field-of-view Y
local cubePosition = Vector3(0.0, 0.0, 0.0) local cubePosition = Vector3(0.0, 0.0, 0.0)
SetCameraMode(CameraMode.FREE) -- Set a free camera mode SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View file

@ -30,18 +30,16 @@ local ray = Ray(Vector3(0, 0, 0), Vector3(0, 0, 0)) -- Picking line ray
local collision = false local collision = false
SetCameraMode(CameraMode.FREE) -- Set a free camera mode SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then if (IsMouseButtonPressed(MOUSE.LEFT_BUTTON)) then
-- NOTE: This function is NOT WORKING properly! -- NOTE: This function is NOT WORKING properly!

View file

@ -23,7 +23,7 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
int count = 0; int count = 0;
char **droppedFiles; char **droppedFiles = { 0 };
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -19,8 +19,8 @@ local screenHeight = 450
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input") InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input")
local ballPosition = Vector2(screenWidth/2, screenHeight/2) local texPs3Pad = LoadTexture("resources/ps3.png")
local gamepadMovement = Vector2(0, 0) local texXboxPad = LoadTexture("resources/xbox.png")
SetTargetFPS(60) -- Set target frames-per-second SetTargetFPS(60) -- Set target frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
@ -29,18 +29,7 @@ SetTargetFPS(60) -- Set target frames-per-second
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then -- ...
gamepadMovement.x = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)
gamepadMovement.y = GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)
ballPosition.x = ballPosition.x + gamepadMovement.x
ballPosition.y = ballPosition.y - gamepadMovement.y
if (IsGamepadButtonPressed(GAMEPAD.PLAYER1, GAMEPAD.BUTTON_A)) then
ballPosition.x = screenWidth/2
ballPosition.y = screenHeight/2
end
end
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw
@ -49,9 +38,117 @@ while not WindowShouldClose() do -- Detect window close button or ESC key
ClearBackground(RAYWHITE) ClearBackground(RAYWHITE)
DrawText("move the ball with gamepad", 10, 10, 20, DARKGRAY) if (IsGamepadAvailable(GAMEPAD.PLAYER1)) then
DrawText(string.format("GP1: %s", GetGamepadName(GAMEPAD.PLAYER1)), 10, 10, 10, BLACK)
DrawCircleV(ballPosition, 50, MAROON) if (IsGamepadName(GAMEPAD.PLAYER1, "Xbox 360 Controller")) then
DrawTexture(texXboxPad, 0, 0, DARKGRAY)
-- Draw buttons: xbox home
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_HOME)) then DrawCircle(394, 89, 19, RED) end
-- Draw buttons: basic
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_START)) then DrawCircle(436, 150, 9, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_SELECT)) then DrawCircle(352, 150, 9, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_X)) then DrawCircle(501, 151, 15, BLUE) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_A)) then DrawCircle(536, 187, 15, LIME) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_B)) then DrawCircle(572, 151, 15, MAROON) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_Y)) then DrawCircle(536, 115, 15, GOLD) end
-- Draw buttons: d-pad
DrawRectangle(317, 202, 19, 71, BLACK)
DrawRectangle(293, 228, 69, 19, BLACK)
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_UP)) then DrawRectangle(317, 202, 19, 26, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_DOWN)) then DrawRectangle(317, 202 + 45, 19, 26, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LEFT)) then DrawRectangle(292, 228, 25, 19, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RIGHT)) then DrawRectangle(292 + 44, 228, 26, 19, RED) end
-- Draw buttons: left-right back
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_LB)) then DrawCircle(259, 61, 20, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.XBOX_BUTTON_RB)) then DrawCircle(536, 61, 20, RED) end
-- Draw axis: left joystick
DrawCircle(259, 152, 39, BLACK)
DrawCircle(259, 152, 34, LIGHTGRAY)
DrawCircle(259 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_X)*20),
152 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LEFT_Y)*20), 25, BLACK)
-- Draw axis: right joystick
DrawCircle(461, 237, 38, BLACK)
DrawCircle(461, 237, 33, LIGHTGRAY)
DrawCircle(461 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_X)*20),
237 - (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RIGHT_Y)*20), 25, BLACK)
-- Draw axis: left-right triggers
DrawRectangle(170, 30, 15, 70, GRAY)
DrawRectangle(604, 30, 15, 70, GRAY)
DrawRectangle(170, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT))/2.0)*70), RED)
DrawRectangle(604, 30, 15, (((1.0 + GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT))/2.0)*70), RED)
--DrawText(FormatText("Xbox axis LT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_LT)), 10, 40, 10, BLACK)
--DrawText(FormatText("Xbox axis RT: %02.02f", GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.XBOX_AXIS_RT)), 10, 60, 10, BLACK)
elseif (IsGamepadName(GAMEPAD.PLAYER1, "PLAYSTATION(R)3 Controller")) then
DrawTexture(texPs3Pad, 0, 0, DARKGRAY)
-- Draw buttons: ps
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_PS)) then DrawCircle(396, 222, 13, RED) end
-- Draw buttons: basic
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SELECT)) then DrawRectangle(328, 170, 32, 13, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_START)) then DrawTriangle((Vector2){ 436, 168 }, (Vector2){ 436, 185 }, (Vector2){ 464, 177 }, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_TRIANGLE)) then DrawCircle(557, 144, 13, LIME) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CIRCLE)) then DrawCircle(586, 173, 13, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_CROSS)) then DrawCircle(557, 203, 13, VIOLET) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_SQUARE)) then DrawCircle(527, 173, 13, PINK) end
-- Draw buttons: d-pad
DrawRectangle(225, 132, 24, 84, BLACK)
DrawRectangle(195, 161, 84, 25, BLACK)
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_UP)) then DrawRectangle(225, 132, 24, 29, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_DOWN)) then DrawRectangle(225, 132 + 54, 24, 30, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_LEFT)) then DrawRectangle(195, 161, 30, 25, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_RIGHT)) then DrawRectangle(195 + 54, 161, 30, 25, RED) end
-- Draw buttons: left-right back buttons
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_L1)) then DrawCircle(239, 82, 20, RED) end
if (IsGamepadButtonDown(GAMEPAD.PLAYER1, GAMEPAD.PS3_BUTTON_R1)) then DrawCircle(557, 82, 20, RED) end
-- Draw axis: left joystick
DrawCircle(319, 255, 35, BLACK)
DrawCircle(319, 255, 31, LIGHTGRAY)
DrawCircle(319 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_X)*20),
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_LEFT_Y)*20), 25, BLACK)
-- Draw axis: right joystick
DrawCircle(475, 255, 35, BLACK)
DrawCircle(475, 255, 31, LIGHTGRAY)
DrawCircle(475 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_X)*20),
255 + (GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_RIGHT_Y)*20), 25, BLACK)
-- Draw axis: left-right triggers
DrawRectangle(169, 48, 15, 70, GRAY)
DrawRectangle(611, 48, 15, 70, GRAY)
DrawRectangle(169, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_L2))/2.0)*70), RED)
DrawRectangle(611, 48, 15, (((1.0 - GetGamepadAxisMovement(GAMEPAD.PLAYER1, GAMEPAD.PS3_AXIS_R2))/2.0)*70), RED)
else
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, GRAY)
-- TODO: Draw generic gamepad
end
DrawText(string.format("DETECTED AXIS [%i]:", GetGamepadAxisCount(GAMEPAD.PLAYER1)), 10, 50, 10, MAROON)
for i = 1, GetGamepadAxisCount(GAMEPAD.PLAYER1) do -- Iterate along all the rectangles
DrawText(string.format("AXIS %i: %.02f", i, GetGamepadAxisMovement(GAMEPAD.PLAYER1, i)), 20, 70 + 20*i, 10, DARKGRAY)
end
if (GetGamepadButtonPressed() ~= -1) then DrawText(string.format("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED)
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY) end
else
DrawText("GP1: NOT DETECTED", 10, 10, 10, GRAY)
DrawTexture(texXboxPad, 0, 0, LIGHTGRAY)
end
EndDrawing() EndDrawing()
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
@ -59,5 +156,8 @@ end
-- De-Initialization -- De-Initialization
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
CloseWindow() -- Close window and OpenGL context UnloadTexture(texPs3Pad) -- Unload gamepad texture
UnloadTexture(texXboxPad) -- Unload gamepad texture
CloseWindow() -- Close window and OpenGL context
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Before After
Before After

View file

@ -47,10 +47,10 @@ int main()
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode)
else UpdateVrTracking(&camera); // Update camera with device tracking data 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

View file

@ -23,10 +23,7 @@ local cubePosition = Vector3(0.0, 0.0, 0.0)
local cubeScreenPosition = Vector2(0, 0) local cubeScreenPosition = Vector2(0, 0)
SetCameraMode(CameraMode.FREE) -- Set a free camera mode SetCameraMode(camera, CameraMode.FREE) -- Set a free camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
@ -35,7 +32,7 @@ SetTargetFPS(60) -- Set our game to run at 60 frames-per-
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
-- Calculate cube screen space position (with a little offset to be in top) -- Calculate cube screen space position (with a little offset to be in top)
cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera) cubeScreenPosition = GetWorldToScreen(Vector3(cubePosition.x, cubePosition.y + 2.5, cubePosition.z), camera)

View file

@ -22,19 +22,16 @@ local camera = Camera(Vector3(5.0, 4.0, 5.0), Vector3(0.0, 2.0, 0.0), Vector3(0.
local bill = LoadTexture("resources/billboard.png") -- Our texture billboard local bill = LoadTexture("resources/billboard.png") -- Our texture billboard
local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard local billPosition = Vector3(0.0, 2.0, 0.0) -- Position where draw billboard
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our camera position
SetCameraTarget(camera.target) -- Set internal camera target to match our camera target
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View file

@ -31,18 +31,16 @@ local mapPosition = Vector3(-16.0, 0.0, -8.0) -- Set model position
UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM UnloadImage(image) -- Unload cubesmap image from RAM, already uploaded to VRAM
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
SetCameraFovy(camera.fovy) -- Set internal camera field-of-view Y
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View file

@ -27,17 +27,16 @@ local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (d
UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode SetCameraMode(camera, CameraMode.ORBITAL) -- Set an orbital camera mode
SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
SetTargetFPS(60) -- Set our game to run at 60 frames-per-second SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
-- Main game loop -- Main game loop
while not WindowShouldClose() do -- Detect window close button or ESC key while not WindowShouldClose() do -- Detect window close button or ESC key
-- Update -- Update
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
camera = UpdateCamera(camera) -- Update internal camera and our camera camera = UpdateCamera(camera) -- Update camera
--------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------
-- Draw -- Draw

View file

@ -1,135 +0,0 @@
/*******************************************************************************************
*
* raylib [physac] example - Basic rigidbody
*
* 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)
*
* NOTE:
* Physac requires multi-threading, when InitPhysics() a second thread is created to manage
* physics calculations. To accomplish that, physac uses pthread Win32 library that can be
* found inside raylib/src/external/pthread directory.
*
* Add pthread library when compiling physac example:
* gcc -o $(NAME_PART).exe $(FILE_NAME) $(RAYLIB_DIR)\raylib_icon -L../src/external/pthread/lib \
* -I../src -I../src/external/pthread/include -lraylib -lglfw3 -lopengl32 -lgdi32 -lpthreadGC2 -std=c99 -Wall
*
* Note that pthreadGC2.dll must be also copied to project directory!
*
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
#include "physac.h"
#define MOVE_VELOCITY 5
#define JUMP_VELOCITY 30
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [physac] example - basic rigidbody");
InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module
// Debug variables
bool isDebug = false;
// Create rectangle physic object
PhysicBody rectangle = CreatePhysicBody((Vector2){ screenWidth*0.25f, screenHeight/2 }, 0.0f, (Vector2){ 75, 50 });
rectangle->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
rectangle->rigidbody.applyGravity = true;
rectangle->rigidbody.friction = 0.1f;
rectangle->rigidbody.bounciness = 6.0f;
// Create square physic object
PhysicBody square = CreatePhysicBody((Vector2){ screenWidth*0.75f, screenHeight/2 }, 0.0f, (Vector2){ 50, 50 });
square->rigidbody.enabled = true; // Enable physic object rigidbody behaviour
square->rigidbody.applyGravity = true;
square->rigidbody.friction = 0.1f;
// Create walls physic objects
PhysicBody floor = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.95f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
PhysicBody leftWall = CreatePhysicBody((Vector2){ 0.0f, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
PhysicBody roof = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.05f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
// Create pplatform physic object
PhysicBody platform = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.7f }, 0.0f, (Vector2){ screenWidth*0.25f, 20 });
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// Check rectangle movement inputs
if (IsKeyPressed('W')) rectangle->rigidbody.velocity.y = JUMP_VELOCITY;
if (IsKeyDown('A')) rectangle->rigidbody.velocity.x = -MOVE_VELOCITY;
else if (IsKeyDown('D')) rectangle->rigidbody.velocity.x = MOVE_VELOCITY;
// Check square movement inputs
if (IsKeyDown(KEY_UP) && square->rigidbody.isGrounded) square->rigidbody.velocity.y = JUMP_VELOCITY;
if (IsKeyDown(KEY_LEFT)) square->rigidbody.velocity.x = -MOVE_VELOCITY;
else if (IsKeyDown(KEY_RIGHT)) square->rigidbody.velocity.x = MOVE_VELOCITY;
// Check debug switch input
if (IsKeyPressed('P')) isDebug = !isDebug;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw floor, roof and walls rectangles
DrawRectangleRec(TransformToRectangle(floor->transform), DARKGRAY); // Convert transform values to rectangle data type variable
DrawRectangleRec(TransformToRectangle(leftWall->transform), DARKGRAY);
DrawRectangleRec(TransformToRectangle(rightWall->transform), DARKGRAY);
DrawRectangleRec(TransformToRectangle(roof->transform), DARKGRAY);
// Draw middle platform rectangle
DrawRectangleRec(TransformToRectangle(platform->transform), DARKGRAY);
// Draw physic objects
DrawRectangleRec(TransformToRectangle(rectangle->transform), RED);
DrawRectangleRec(TransformToRectangle(square->transform), BLUE);
// Draw collider lines if debug is enabled
if (isDebug)
{
DrawRectangleLines(floor->collider.bounds.x, floor->collider.bounds.y, floor->collider.bounds.width, floor->collider.bounds.height, GREEN);
DrawRectangleLines(leftWall->collider.bounds.x, leftWall->collider.bounds.y, leftWall->collider.bounds.width, leftWall->collider.bounds.height, GREEN);
DrawRectangleLines(rightWall->collider.bounds.x, rightWall->collider.bounds.y, rightWall->collider.bounds.width, rightWall->collider.bounds.height, GREEN);
DrawRectangleLines(roof->collider.bounds.x, roof->collider.bounds.y, roof->collider.bounds.width, roof->collider.bounds.height, GREEN);
DrawRectangleLines(platform->collider.bounds.x, platform->collider.bounds.y, platform->collider.bounds.width, platform->collider.bounds.height, GREEN);
DrawRectangleLines(rectangle->collider.bounds.x, rectangle->collider.bounds.y, rectangle->collider.bounds.width, rectangle->collider.bounds.height, GREEN);
DrawRectangleLines(square->collider.bounds.x, square->collider.bounds.y, square->collider.bounds.width, square->collider.bounds.height, GREEN);
}
// Draw help message
DrawText("Use WASD to move rectangle and ARROWS to move square", screenWidth/2 - MeasureText("Use WASD to move rectangle and ARROWS to move square", 20)/2, screenHeight*0.075f, 20, LIGHTGRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
ClosePhysics(); // Unitialize physics (including all loaded objects)
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Some files were not shown because too many files have changed in this diff Show more