-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,070 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asd | ||
Check failure on line 1 in examples/aa.rs GitHub Actions / cargo fmt
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use macroquad::{ | ||
camera::{Camera, Environment, Projection}, | ||
color::*, | ||
math::{vec2, vec3}, | ||
shapes::{DrawParams, Sprite, Text}, | ||
}; | ||
use miniquad::KeyCode; | ||
|
||
use macroquad::compat::*; | ||
|
||
async fn game(ctx: macroquad::Context) { | ||
let mut scene = ctx.new_scene(); | ||
|
||
let texture = ctx | ||
.resources | ||
.load_texture("examples/ferris2.png") | ||
.await | ||
.unwrap(); | ||
let sprite = Sprite::new(&texture); | ||
let bunny = scene.into_model(sprite, DrawParams::default()); | ||
let bunny = scene.add_model(&bunny); | ||
scene.set_scale(&bunny, vec3(0.01, 1.0, 0.01)); | ||
let mut camera = Camera { | ||
environment: Environment::SolidColor(WHITE), | ||
depth_enabled: false, | ||
projection: Projection::Orthographic, | ||
position: vec3(0., 10.0, 0.), | ||
up: vec3(0., 1., 0.), | ||
target: vec3(0.0, 0., 1.), | ||
z_near: 0.1, | ||
z_far: 15.0, | ||
..Default::default() | ||
}; | ||
|
||
let mut canvas = ctx.new_canvas(); | ||
let mut bunnies = vec![]; | ||
let mut bunnies_dir = vec![]; | ||
|
||
for _ in 0..1 { | ||
bunnies.push(vec3( | ||
quad_rand::gen_range(-20.0, 20.0), | ||
0.0, | ||
quad_rand::gen_range(-20.0, 20.0), | ||
)); | ||
bunnies_dir.push(vec3( | ||
quad_rand::gen_range(-1.0, 1.0), | ||
0., | ||
quad_rand::gen_range(-1.0, 1.0), | ||
)); | ||
} | ||
scene.update_multi_positions(&bunny, &bunnies); | ||
|
||
loop { | ||
if ctx.is_key_down(KeyCode::Space) { | ||
for _ in 0..1 { | ||
bunnies.push(vec3( | ||
quad_rand::gen_range(-20.0, 20.0), | ||
0.0, | ||
quad_rand::gen_range(-20.0, 20.0), | ||
)); | ||
bunnies_dir.push(vec3( | ||
quad_rand::gen_range(-1.0, 1.0), | ||
0., | ||
quad_rand::gen_range(-1.0, 1.0), | ||
)); | ||
} | ||
scene.update_multi_positions(&bunny, &bunnies); | ||
} | ||
|
||
ctx.clear_screen(WHITE); | ||
|
||
for (bunny, dir) in bunnies.iter_mut().zip(bunnies_dir.iter_mut()) { | ||
*bunny += *dir; | ||
if bunny.x >= 20.0 || bunny.x <= -20.0 { | ||
dir.x *= -1.0; | ||
} | ||
if bunny.z >= 20.0 || bunny.z <= -20.0 { | ||
dir.z *= -1.0; | ||
} | ||
} | ||
|
||
scene.update_multi_positions(&bunny, &bunnies); | ||
|
||
scene.draw(&mut camera); | ||
|
||
canvas.clear(); | ||
canvas.draw( | ||
Text::new(&format!("fps: {:0.1}", 1.0 / ctx.frame_time()), 16), | ||
vec2(0.0, 16.0), | ||
BLACK, | ||
); | ||
canvas.draw( | ||
Text::new(&format!("bunnies: {}", bunnies.len()), 16), | ||
vec2(0.0, 32.0), | ||
BLACK, | ||
); | ||
canvas.draw( | ||
Text::new(&format!("Press any key"), 16), | ||
vec2(0.0, 48.0), | ||
BLACK, | ||
); | ||
canvas.blit(); | ||
|
||
next_frame().await; | ||
} | ||
} | ||
|
||
fn main() { | ||
macroquad::start(Default::default(), |ctx| game(ctx)); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
use macroquad::{ | ||
file::load_file, | ||
gizmos::{draw_gizmos, gizmos_add_line, init_gizmos}, | ||
math::{vec2, vec3, Vec2, Vec3}, | ||
quad_gl::{color, scene::Shader}, | ||
time::get_time, | ||
Check failure on line 6 in examples/mmmesh.rs GitHub Actions / Cross-compile (windows-latest, x86_64-pc-windows-msvc)
|
||
window::next_frame, | ||
}; | ||
|
||
mod orbit_camera; | ||
|
||
const vertices: &[Vec3] = &[ | ||
vec3(-0.5, 0.5, 0.8), | ||
vec3(-0.5, 0.5, -0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(-0.5, 0.5, -0.8), | ||
vec3(-0.5, -0.5, -0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(-0.5, 0.5, -0.8), | ||
vec3(0.5, 0.5, -0.8), | ||
vec3(-0.5, -0.5, -0.8), | ||
vec3(0.5, 0.5, -0.8), | ||
vec3(0.5, -0.5, -0.8), | ||
vec3(-0.5, -0.5, -0.8), | ||
vec3(0.5, 0.5, -0.8), | ||
vec3(0.5, 0.5, 0.8), | ||
vec3(0.5, -0.5, 0.8), | ||
vec3(0.5, -0.5, -0.8), | ||
vec3(0.5, 0.5, -0.8), | ||
vec3(0.5, -0.5, 0.8), | ||
vec3(0.5, 0.5, 0.8), | ||
vec3(-0.5, 0.5, 0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(0.5, -0.5, 0.8), | ||
vec3(0.5, 0.5, 0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(-0.5, -0.5, -0.8), | ||
vec3(0.5, -0.5, -0.8), | ||
vec3(0.5, -0.5, 0.8), | ||
vec3(-0.5, -0.5, 0.8), | ||
vec3(0.5, -0.5, -0.8), | ||
vec3(0.5, 0.5, 0.8), | ||
vec3(0.5, 0.5, -0.8), | ||
vec3(-0.5, 0.5, -0.8), | ||
vec3(-0.5, 0.5, 0.8), | ||
vec3(0.5, 0.5, 0.8), | ||
vec3(-0.5, 0.5, -0.8), | ||
]; | ||
const uvs: &[Vec2] = &[ | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
vec2(0.0, 0.0), | ||
]; | ||
const normals: &[Vec3] = &[ | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(-1.0, 0.0, 0.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(0.0, 0.0, -1.0), | ||
vec3(1.0, -0.0, 0.0), | ||
vec3(1.0, -0.0, 0.0), | ||
vec3(1.0, -0.0, 0.0), | ||
vec3(1.0, 0.0, 0.0), | ||
vec3(1.0, 0.0, 0.0), | ||
vec3(1.0, 0.0, 0.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, 0.0, 1.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, -1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
]; | ||
const indices: &[u16] = &[ | ||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, | ||
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, | ||
]; | ||
|
||
async fn game(ctx: macroquad::Context) { | ||
unsafe { | ||
macroquad::miniquad::gl::glEnable(macroquad::miniquad::gl::GL_TEXTURE_CUBE_MAP_SEAMLESS) | ||
}; | ||
|
||
init_gizmos(&ctx); | ||
|
||
let mut scene = ctx.new_scene(); | ||
|
||
let texture = load_file("examples/ferris.png").await.unwrap(); | ||
let texture = quad_gl::image::decode(&texture).unwrap(); | ||
|
||
let mesh = quad_gl::models::CpuMesh( | ||
vertices.to_vec(), | ||
uvs.to_vec(), | ||
normals.to_vec(), | ||
indices.to_vec(), | ||
); | ||
let mut mesh = ctx.mesh(mesh, None); | ||
mesh.nodes[0].materials[0].shader = Shader::new( | ||
ctx.quad_ctx.lock().unwrap().as_mut(), | ||
vec![], | ||
Some(FRAGMENT), | ||
None, | ||
); | ||
|
||
let _mesh = scene.add_model(&mesh); | ||
let mut orbit = orbit_camera::OrbitCamera::new(); | ||
|
||
loop { | ||
let t = get_time(); | ||
let p = vec3(t.sin() as f32, 0.0, t.cos() as f32); | ||
|
||
gizmos_add_line(true, p, p * 1.2); | ||
gizmos_add_line(false, vec3(0.0, 0.0, 0.0), p); | ||
|
||
ctx.clear_screen(color::BLACK); | ||
orbit.orbit(&ctx); | ||
scene.draw(&orbit.camera); | ||
//draw_gizmos(&orbit.camera); | ||
next_frame().await | ||
} | ||
} | ||
|
||
fn main() { | ||
macroquad::start(Default::default(), |ctx| game(ctx)); | ||
} | ||
|
||
const VERTEX: &str = r#" | ||
#include "common_vertex.glsl" | ||
void vertex() { | ||
} | ||
"#; | ||
|
||
const FRAGMENT: &str = r#" | ||
varying vec3 out_normal; | ||
void main() { | ||
vec3 norm = normalize(out_normal); | ||
vec3 lightDir = normalize(vec3(1.0, -1.0, 0.5)); | ||
float diff = max(dot(norm, lightDir), 0.0); | ||
vec3 diffuse = diff * vec3(1.0) + vec3(0.3); | ||
gl_FragColor = vec4(diffuse,1.0); | ||
} | ||
"#; |
Oops, something went wrong.