8个不稳定版本 (3个破坏性版本)
0.4.0 | 2020年6月20日 |
---|---|
0.3.0 | 2020年6月6日 |
0.2.1 | 2020年5月29日 |
0.1.3 | 2020年5月10日 |
在 #crystal 中排名 9
140KB
3K SLoC
这是一个原型游戏引擎,专注于抽象渲染逻辑,纯粹关注游戏逻辑。
示例
use cgmath::{Deg, Euler, Matrix4, Point3, Rad, Vector3};
use crystal_engine::{
event::VirtualKeyCode, DirectionalLight, GameState, LightColor, ModelHandle, Window,
};
fn main() {
let window = Window::<Game>::new(800., 600.);
window.run();
}
pub struct Game {
rust_logo: ModelHandle,
fbx_model: ModelHandle,
obj_model: ModelHandle,
}
impl crystal_engine::Game for Game {
fn init(state: &mut GameState) -> Self {
state.window().set_title("crystal-engine demo");
let rust_logo = state
.new_rectangle_model()
.with_texture_from_file("assets/rust_logo.png")
.with_position((0.0, 1.5, 0.0))
.with_rotation(Euler::new(Rad(0.0), Deg(180.0).into(), Rad(0.0)))
.with_scale(1.0)
.build();
let fbx_model = state
.new_fbx_model("assets/some_model.fbx")
.build();
let obj_model = state
.new_obj_model("assets/some_model.obj")
.build();
state.camera = Matrix4::look_at(
Point3::new(0.0, 0.0, 2.0),
Point3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 1.0, 0.0),
);
state.light.directional.push(DirectionalLight {
direction: Vector3::new(1.0, -1.0, 0.0),
color: LightColor {
ambient: Vector3::new(1.0, 1.0, 1.0),
diffuse: Vector3::new(1.0, 1.0, 1.0),
specular: Vector3::new(1.0, 1.0, 1.0),
},
});
Self {
rust_logo,
fbx_model,
obj_model,
}
}
fn keydown(&mut self, state: &mut GameState, key: VirtualKeyCode) {
if key == VirtualKeyCode::Escape {
state.terminate_game();
}
}
fn update(&mut self, _state: &mut GameState) {
self.rust_logo.modify(|data| {
data.rotation.y += Rad(0.02);
});
}
}
特性
目前有以下特性可用
- format-obj: 允许加载.obj文件,默认启用。
- format-fbx: 允许加载.fbx二进制文件,默认启用。
反馈
请随时向我提出任何反馈。您可以在本仓库中打开问题,或在twitter @victorkoenders 或 discord @Trangar#5901 上给我发消息。
依赖
~62MB
~1M SLoC