mirror of https://github.com/Leinnan/doppler.git
Transform
This commit is contained in:
parent
23aae0fa52
commit
d778df90c3
|
|
@ -1,29 +1,30 @@
|
||||||
|
|
||||||
use crate::gaia::camera::*;
|
use crate::gaia::camera::*;
|
||||||
use crate::gaia::consts;
|
use crate::gaia::{consts,macros};
|
||||||
use crate::gaia::*;
|
use crate::gaia::*;
|
||||||
#[macro_use]
|
|
||||||
use imgui_glfw_rs::glfw;
|
use imgui_glfw_rs::glfw;
|
||||||
use crate::gaia::macros;
|
use crate::gaia::components::{Transform,ModelComponent};
|
||||||
use crate::gaia::engine::Engine;
|
use crate::gaia::engine::Engine;
|
||||||
use crate::gaia::client::Client;
|
use crate::gaia::client::Client;
|
||||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||||
macro_rules! c_str {
|
|
||||||
($literal:expr) => {
|
|
||||||
std::ffi::CStr::from_bytes_with_nul_unchecked(concat!($literal, "\0").as_bytes())
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ExampleClient {
|
pub struct ExampleClient {
|
||||||
model: model::Model,
|
model: ModelComponent,
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
shader: shader::Shader,
|
shader: shader::Shader,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExampleClient {
|
impl ExampleClient {
|
||||||
pub fn create() -> ExampleClient {
|
pub fn create() -> ExampleClient {
|
||||||
ExampleClient {
|
let mut t = Transform::default();
|
||||||
|
t.position = vec3(3.0, -1.75, -1.25);
|
||||||
|
t.scale = vec3(0.2,0.1,0.2);
|
||||||
|
let model = ModelComponent {
|
||||||
|
transform: t,
|
||||||
model: model::Model::new("resources/objects/nanosuit/nanosuit.obj"),
|
model: model::Model::new("resources/objects/nanosuit/nanosuit.obj"),
|
||||||
|
};
|
||||||
|
ExampleClient {
|
||||||
|
model: model,
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
position: Point3::new(0.0, 0.0, 3.0),
|
position: Point3::new(0.0, 0.0, 3.0),
|
||||||
..Camera::default()
|
..Camera::default()
|
||||||
|
|
@ -50,11 +51,8 @@ impl Client for ExampleClient {
|
||||||
let view = self.camera.get_view_matrix();
|
let view = self.camera.get_view_matrix();
|
||||||
self.shader.setMat4(c_str!("projection"), &projection);
|
self.shader.setMat4(c_str!("projection"), &projection);
|
||||||
self.shader.setMat4(c_str!("view"), &view);
|
self.shader.setMat4(c_str!("view"), &view);
|
||||||
|
|
||||||
let mut m = Matrix4::<f32>::from_translation(vec3(3.0, -1.75, -1.25)); // translate it down so it's at the center of the scene
|
self.model.draw(&self.shader);
|
||||||
m = m * Matrix4::from_scale(0.2); // it's a bit too big for our scene, so scale it down
|
|
||||||
self.shader.setMat4(c_str!("model"), &m);
|
|
||||||
self.model.Draw(&self.shader);
|
|
||||||
}
|
}
|
||||||
fn update(&mut self, engine: &mut Engine) {
|
fn update(&mut self, engine: &mut Engine) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
use crate::gaia::*;
|
||||||
|
use crate::gaia::macros;
|
||||||
|
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||||
|
use crate::gaia::model::Model;
|
||||||
|
use crate::gaia::shader::Shader;
|
||||||
|
|
||||||
|
pub struct Transform {
|
||||||
|
pub position: Vector3<f32>,
|
||||||
|
pub scale: Vector3<f32>,
|
||||||
|
pub rotation: Vector3<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Transform {
|
||||||
|
fn default() -> Transform {
|
||||||
|
Transform {
|
||||||
|
position: vec3(0.0,0.0,0.0),
|
||||||
|
scale: vec3(1.0,1.0,1.0),
|
||||||
|
rotation: vec3(0.0,0.0,0.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transform {
|
||||||
|
pub fn get_matrix(&self) -> Matrix4<f32> {
|
||||||
|
let mut m = Matrix4::<f32>::from_translation(self.position);
|
||||||
|
m = m * Matrix4::from_nonuniform_scale(self.scale.x,self.scale.y,self.scale.z);
|
||||||
|
|
||||||
|
m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ModelComponent {
|
||||||
|
pub model: Model,
|
||||||
|
pub transform: Transform,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ModelComponent {
|
||||||
|
pub unsafe fn draw(&mut self, shader: &Shader ) {
|
||||||
|
let matrix = self.transform.get_matrix();
|
||||||
|
|
||||||
|
shader.setMat4(c_str!("model"), &matrix);
|
||||||
|
self.model.Draw(&shader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -65,12 +65,13 @@ impl Engine {
|
||||||
|
|
||||||
{
|
{
|
||||||
use imgui::*;
|
use imgui::*;
|
||||||
|
let fps = 1.0 / delta_time;
|
||||||
let mut info = self.bg_info;
|
let mut info = self.bg_info;
|
||||||
Window::new(im_str!("Hello world"))
|
Window::new(im_str!("Hello world"))
|
||||||
.size([300.0, 110.0], Condition::FirstUseEver)
|
.size([300.0, 110.0], Condition::FirstUseEver)
|
||||||
.build(&ui, || {
|
.build(&ui, || {
|
||||||
ui.text(im_str!("Hello world!"));
|
ui.text(im_str!("Hello world!"));
|
||||||
ui.text(im_str!("こんにちは世界!"));
|
ui.text(format!("{:.0}", fps));
|
||||||
ui.text(im_str!("This...is...imgui-rs!"));
|
ui.text(im_str!("This...is...imgui-rs!"));
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.text(format!("Mouse position: ({:.1},{:.1})", last_x, last_y));
|
ui.text(format!("Mouse position: ({:.1},{:.1})", last_x, last_y));
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#![macro_use]
|
||||||
|
|
||||||
/// Macro to get c strings from literals without runtime overhead
|
/// Macro to get c strings from literals without runtime overhead
|
||||||
/// Literal must not contain any interior nul bytes!
|
/// Literal must not contain any interior nul bytes!
|
||||||
macro_rules! c_str {
|
macro_rules! c_str {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
pub mod macros;
|
||||||
pub mod camera;
|
pub mod camera;
|
||||||
|
pub mod components;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod consts;
|
pub mod consts;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
#[macro_use]
|
|
||||||
pub mod macros;
|
|
||||||
pub mod bg_info;
|
pub mod bg_info;
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
pub mod mesh;
|
pub mod mesh;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ extern crate gl;
|
||||||
extern crate image;
|
extern crate image;
|
||||||
extern crate imgui_glfw_rs;
|
extern crate imgui_glfw_rs;
|
||||||
use human_panic::setup_panic;
|
use human_panic::setup_panic;
|
||||||
|
#[macro_use]
|
||||||
mod gaia;
|
mod gaia;
|
||||||
mod example_client;
|
mod example_client;
|
||||||
use crate::gaia::engine::Engine;
|
use crate::gaia::engine::Engine;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue