Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to raylib 4.2 #163

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# version doesn't seem to pick correct version
#find_package(raylib 4.0 QUIET EXACT)
#find_package(raylib 4.2 QUIET EXACT)
if (NOT raylib_FOUND)
include(FetchContent)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 4.0.0
GIT_TAG 4.2.0
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(raylib)
Expand Down
3,492 changes: 2,965 additions & 527 deletions docs/API.md

Large diffs are not rendered by default.

125 changes: 68 additions & 57 deletions examples/models/models_rlgl_solar_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,21 @@
*
* raylib [models] example - rlgl module usage with push/pop matrix transformations
*
* This example uses [rlgl] module funtionality (pseudo-OpenGL 1.1 style coding)
* NOTE: This example uses [rlgl] module functionality (pseudo-OpenGL 1.1 style coding)
*
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* Example originally created with raylib 2.5, last time updated with raylib 4.0
*
* Copyright (c) 2018 Ramon Santamaria (@raysan5)
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2018-2022 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

const r = require('raylib')

// ------------------------------------------------------------------------------------
// Module Functions Declaration
// ------------------------------------------------------------------------------------
function DrawSphereBasic (color) {
const rings = 16
const slices = 16

r.rlBegin(r.RL_TRIANGLES)
r.rlColor4ub(color.r, color.g, color.b, color.a)

for (let i = 0; i < (rings + 2); i++) {
for (let j = 0; j < slices; j++) {
r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * Math.sin(r.DEG2RAD * (j * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * Math.cos(r.DEG2RAD * (j * 360 / slices)))
r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.sin(r.DEG2RAD * ((j + 1) * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.cos(r.DEG2RAD * ((j + 1) * 360 / slices)))
r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.sin(r.DEG2RAD * (j * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.cos(r.DEG2RAD * (j * 360 / slices)))

r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * Math.sin(r.DEG2RAD * (j * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * Math.cos(r.DEG2RAD * (j * 360 / slices)))
r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))) * Math.sin(r.DEG2RAD * ((j + 1) * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))) * Math.cos(r.DEG2RAD * ((j + 1) * 360 / slices)))
r.rlVertex3f(Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.sin(r.DEG2RAD * ((j + 1) * 360 / slices)),
Math.sin(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
Math.cos(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * Math.cos(r.DEG2RAD * ((j + 1) * 360 / slices)))
}
}
r.rlEnd()
}

// ------------------------------------------------------------------------------------
// Program main entry point
Expand All @@ -64,39 +33,38 @@ const earthOrbitRadius = 8.0
const moonRadius = 0.16
const moonOrbitRadius = 1.5

r.InitWindow(screenWidth, screenHeight, 'raylib [models] example - rlgl module usage with push/pop matrix transformations')
r.InitWindow(screenWidth, screenHeight, 'node raylib [models] example - rlgl module usage with push/pop matrix transformations')

// Define the camera to look into our 3d world
const camera = r.Camera()
camera.position = r.Vector3(16, 16, 16)
camera.target = r.Vector3(0, 0, 0)
camera.up = r.Vector3(0, 1, 0)
camera.fovy = 45
camera.type = r.CAMERA_PERSPECTIVE
camera.projection = r.CAMERA_PERSPECTIVE
const camera = {
position: { x: 16, y: 16, z: 16 },
target: { x: 0, y: 0, z: 0 },
up: { x: 0, y: 1, z: 0 },
fovy: 45,
projection: r.CAMERA_PERSPECTIVE
}

r.SetCameraMode(camera, r.CAMERA_FREE)

const rotationSpeed = 0.2 // General system rotation speed

let earthRotation = 0 // Rotation of earth around itself (days) in degrees
let earthOrbitRotation = 0 // Rotation of earth around the Sun (years) in degrees
let earthRotation = 0.0 // Rotation of earth around itself (days) in degrees
let earthOrbitRotation = 0.0 // Rotation of earth around the Sun (years) in degrees
let moonRotation = 0.0 // Rotation of moon around itself
let moonOrbitRotation = 0 // Rotation of moon around earth in degrees
let moonOrbitRotation = 0.0 // Rotation of moon around earth in degrees

r.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
// --------------------------------------------------------------------------------------

// Main game loop
while (!r.WindowShouldClose()) { // Detect window close button or ESC key
while (!r.WindowShouldClose()) {
// Update
// ----------------------------------------------------------------------------------
r.UpdateCamera(camera)

earthRotation += (5 * rotationSpeed)
earthOrbitRotation += (365 / 360 * (5 * rotationSpeed) * rotationSpeed)
moonRotation += (2 * rotationSpeed)
moonOrbitRotation += (8 * rotationSpeed)
earthRotation += (5.0 * rotationSpeed)
earthOrbitRotation += (365 / 360.0 * (5.0 * rotationSpeed) * rotationSpeed)
moonRotation += (2.0 * rotationSpeed)
moonOrbitRotation += (8.0 * rotationSpeed)
// ----------------------------------------------------------------------------------

// Draw
Expand All @@ -115,7 +83,6 @@ while (!r.WindowShouldClose()) { // Detect window close button or ESC key
r.rlPushMatrix()
r.rlRotatef(earthOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Earth orbit around Sun
r.rlTranslatef(earthOrbitRadius, 0.0, 0.0) // Translation for Earth orbit
r.rlRotatef(-earthOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Earth orbit around Sun inverted

r.rlPushMatrix()
r.rlRotatef(earthRotation, 0.25, 1.0, 0.0) // Rotation for Earth itself
Expand All @@ -126,15 +93,14 @@ while (!r.WindowShouldClose()) { // Detect window close button or ESC key

r.rlRotatef(moonOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Moon orbit around Earth
r.rlTranslatef(moonOrbitRadius, 0.0, 0.0) // Translation for Moon orbit
r.rlRotatef(-moonOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Moon orbit around Earth inverted
r.rlRotatef(moonRotation, 0.0, 1.0, 0.0) // Rotation for Moon itself
r.rlScalef(moonRadius, moonRadius, moonRadius) // Scale Moon

DrawSphereBasic(r.LIGHTGRAY) // Draw the Moon
r.rlPopMatrix()

// Some reference elements (not affected by previous matrix transformations)
r.DrawCircle3D(r.Vector3(0.0, 0.0, 0.0), earthOrbitRadius, r.Vector3(1, 0, 0), 90.0, r.Fade(r.RED, 0.5))
r.DrawCircle3D({ x: 0, y: 0, z: 0 }, earthOrbitRadius, { x: 1, y: 0, z: 0 }, 90.0, r.Fade(r.RED, 0.5))
r.DrawGrid(20, 1.0)

r.EndMode3D()
Expand All @@ -150,3 +116,48 @@ while (!r.WindowShouldClose()) { // Detect window close button or ESC key
// --------------------------------------------------------------------------------------
r.CloseWindow() // Close window and OpenGL context
// --------------------------------------------------------------------------------------

// --------------------------------------------------------------------------------------------
// Module Functions Definitions (local)
// --------------------------------------------------------------------------------------------

// Draw sphere without any matrix transformation
// NOTE: Sphere is drawn in world position ( 0, 0, 0 ) with radius 1.0f
function DrawSphereBasic (color) {
const rings = 16
const slices = 16

// Make sure there is enough space in the internal render batch
// buffer to store all required vertex, batch is reseted if required
r.rlCheckRenderBatchLimit((rings + 2) * slices * 6)

r.rlBegin(r.RL_TRIANGLES)
r.rlColor4ub(color.r, color.g, color.b, color.a)
const cosf = Math.cos
const sinf = Math.sin
r.DEG2RAD = Math.PI / 180
for (let i = 0; i < (rings + 2); i++) {
for (let j = 0; j < slices; j++) {
r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * sinf(r.DEG2RAD * (j * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * cosf(r.DEG2RAD * (j * 360 / slices)))
r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * sinf(r.DEG2RAD * ((j + 1) * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * cosf(r.DEG2RAD * ((j + 1) * 360 / slices)))
r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * sinf(r.DEG2RAD * (j * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * cosf(r.DEG2RAD * (j * 360 / slices)))

r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * sinf(r.DEG2RAD * (j * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * i)) * cosf(r.DEG2RAD * (j * 360 / slices)))
r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))) * sinf(r.DEG2RAD * ((j + 1) * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i))) * cosf(r.DEG2RAD * ((j + 1) * 360 / slices)))
r.rlVertex3f(cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * sinf(r.DEG2RAD * ((j + 1) * 360 / slices)),
sinf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))),
cosf(r.DEG2RAD * (270 + (180 / (rings + 1)) * (i + 1))) * cosf(r.DEG2RAD * ((j + 1) * 360 / slices)))
}
}
r.rlEnd()
}
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ raylib.MAX_GAMEPAD_AXIS = 8
raylib.MAX_GAMEPAD_BUTTONS = 32
raylib.MAX_TOUCH_POINTS = 10
raylib.MAX_KEY_PRESSED_QUEUE = 16

raylib.DEG2RAD = Math.PI / 180
// Wrapped Functions

/**
* Text formatting with variables (sprintf style)
*/
raylib.TextFormat = format

/**
* Define one vertex (color) - 4 byte
* @param {number} r
* @param {number} g
* @param {number} b
* @param {number} a
*/
raylib.rlColor4ub = (r, g, b, a) => {
// workaround as the C addon version isn't compiling?
raylib.rlColor4f(r / 255, g / 255, b / 255, a / 255)
}
// Export the bindings for the module.
module.exports = raylib
Loading