mirror of https://github.com/Leinnan/doppler.git
Code cleanup
This commit is contained in:
parent
6462867440
commit
bfeee3dce4
|
|
@ -1,12 +1,11 @@
|
|||
|
||||
use crate::gaia::camera::*;
|
||||
use crate::gaia::{consts};
|
||||
use crate::gaia::*;
|
||||
use imgui_glfw_rs::glfw;
|
||||
use crate::gaia::components::{Transform,ModelComponent};
|
||||
use crate::gaia::engine::Engine;
|
||||
use crate::gaia::client::Client;
|
||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||
use crate::gaia::components::{ModelComponent, Transform};
|
||||
use crate::gaia::consts;
|
||||
use crate::gaia::engine::Engine;
|
||||
use crate::gaia::*;
|
||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3};
|
||||
use imgui_glfw_rs::glfw;
|
||||
|
||||
pub struct ExampleClient {
|
||||
model: ModelComponent,
|
||||
|
|
@ -18,7 +17,7 @@ impl ExampleClient {
|
|||
pub fn create() -> ExampleClient {
|
||||
let mut t = Transform::default();
|
||||
t.position = vec3(3.0, -1.75, -1.25);
|
||||
t.scale = vec3(0.2,0.1,0.2);
|
||||
t.scale = vec3(0.2, 0.1, 0.2);
|
||||
let model = ModelComponent {
|
||||
transform: t,
|
||||
model: model::Model::new("resources/objects/nanosuit/nanosuit.obj"),
|
||||
|
|
@ -39,51 +38,44 @@ impl ExampleClient {
|
|||
|
||||
impl Client for ExampleClient {
|
||||
unsafe fn draw(&mut self) {
|
||||
self.shader.useProgram();
|
||||
self.shader.use_program();
|
||||
|
||||
// view/projection transformations
|
||||
let projection: Matrix4<f32> = perspective(
|
||||
Deg(self.camera.Zoom),
|
||||
Deg(self.camera.zoom),
|
||||
consts::SCR_WIDTH as f32 / consts::SCR_HEIGHT as f32,
|
||||
0.1,
|
||||
100.0,
|
||||
);
|
||||
let view = self.camera.get_view_matrix();
|
||||
self.shader.setMat4(c_str!("projection"), &projection);
|
||||
self.shader.setMat4(c_str!("view"), &view);
|
||||
self.shader.set_mat4(c_str!("projection"), &projection);
|
||||
self.shader.set_mat4(c_str!("view"), &view);
|
||||
|
||||
self.model.draw(&self.shader);
|
||||
}
|
||||
fn update(&mut self, engine: &mut Engine) {
|
||||
|
||||
}
|
||||
|
||||
fn update(&mut self, _engine: &mut Engine) {}
|
||||
|
||||
fn process_input(&mut self, window: &glfw::Window, delta: f32) {
|
||||
use imgui_glfw_rs::glfw::{Action, Key};
|
||||
if window.get_key(Key::W) == Action::Press {
|
||||
self.camera
|
||||
.process_keyboard(Camera_Movement::FORWARD, delta);
|
||||
self.camera.process_keyboard(CameraMovement::FORWARD, delta);
|
||||
}
|
||||
if window.get_key(Key::S) == Action::Press {
|
||||
self.camera
|
||||
.process_keyboard(Camera_Movement::BACKWARD, delta);
|
||||
.process_keyboard(CameraMovement::BACKWARD, delta);
|
||||
}
|
||||
if window.get_key(Key::A) == Action::Press {
|
||||
self.camera
|
||||
.process_keyboard(Camera_Movement::LEFT, delta);
|
||||
self.camera.process_keyboard(CameraMovement::LEFT, delta);
|
||||
}
|
||||
if window.get_key(Key::D) == Action::Press {
|
||||
self.camera
|
||||
.process_keyboard(Camera_Movement::RIGHT, delta);
|
||||
self.camera.process_keyboard(CameraMovement::RIGHT, delta);
|
||||
}
|
||||
self.camera
|
||||
.enable_mouse_movement(window.get_key(Key::LeftControl) != Action::Press);
|
||||
}
|
||||
|
||||
fn debug_draw(&mut self, ui: &imgui_glfw_rs::imgui::Ui) {
|
||||
use imgui_glfw_rs::imgui;
|
||||
use imgui::*;
|
||||
use imgui_glfw_rs::imgui::*;
|
||||
use imgui_inspect::InspectArgsStruct;
|
||||
Window::new(im_str!("Object info"))
|
||||
.size([250.0, 250.0], Condition::FirstUseEver)
|
||||
|
|
@ -98,10 +90,10 @@ impl Client for ExampleClient {
|
|||
});
|
||||
}
|
||||
|
||||
fn on_mouse_scroll(&mut self, yoffset: f32){
|
||||
fn on_mouse_scroll(&mut self, yoffset: f32) {
|
||||
self.camera.process_mouse_scroll(yoffset as f32);
|
||||
}
|
||||
fn on_mouse_move(&mut self, x: f32, y: f32){
|
||||
fn on_mouse_move(&mut self, x: f32, y: f32) {
|
||||
self.camera.process_mouse_movement(x, y, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use cgmath;
|
||||
|
|
@ -12,13 +10,13 @@ type Matrix4 = cgmath::Matrix4<f32>;
|
|||
|
||||
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum Camera_Movement {
|
||||
pub enum CameraMovement {
|
||||
FORWARD,
|
||||
BACKWARD,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
}
|
||||
use self::Camera_Movement::*;
|
||||
use self::CameraMovement::*;
|
||||
|
||||
// Default camera values
|
||||
const YAW: f32 = -90.0;
|
||||
|
|
@ -30,32 +28,32 @@ const ZOOM: f32 = 45.0;
|
|||
pub struct Camera {
|
||||
// Camera Attributes
|
||||
pub position: Point3,
|
||||
pub Front: Vector3,
|
||||
pub Up: Vector3,
|
||||
pub Right: Vector3,
|
||||
pub WorldUp: Vector3,
|
||||
pub front: Vector3,
|
||||
pub up: Vector3,
|
||||
pub right: Vector3,
|
||||
pub worldup: Vector3,
|
||||
// Euler Angles
|
||||
pub Yaw: f32,
|
||||
pub Pitch: f32,
|
||||
pub yaw: f32,
|
||||
pub pitch: f32,
|
||||
// Camera options
|
||||
pub MovementSpeed: f32,
|
||||
pub MouseSensitivity: f32,
|
||||
pub Zoom: f32,
|
||||
pub movement_speed: f32,
|
||||
pub mouse_sensivity: f32,
|
||||
pub zoom: f32,
|
||||
}
|
||||
|
||||
impl Default for Camera {
|
||||
fn default() -> Camera {
|
||||
let mut camera = Camera {
|
||||
position: Point3::new(0.0, 0.0, 0.0),
|
||||
Front: vec3(0.0, 0.0, -1.0),
|
||||
Up: Vector3::zero(), // initialized later
|
||||
Right: Vector3::zero(), // initialized later
|
||||
WorldUp: Vector3::unit_y(),
|
||||
Yaw: YAW,
|
||||
Pitch: PITCH,
|
||||
MovementSpeed: SPEED,
|
||||
MouseSensitivity: SENSITIVTY,
|
||||
Zoom: ZOOM,
|
||||
front: vec3(0.0, 0.0, -1.0),
|
||||
up: Vector3::zero(), // initialized later
|
||||
right: Vector3::zero(), // initialized later
|
||||
worldup: Vector3::unit_y(),
|
||||
yaw: YAW,
|
||||
pitch: PITCH,
|
||||
movement_speed: SPEED,
|
||||
mouse_sensivity: SENSITIVTY,
|
||||
zoom: ZOOM,
|
||||
};
|
||||
camera.update_camera_vectors();
|
||||
camera
|
||||
|
|
@ -65,23 +63,23 @@ impl Default for Camera {
|
|||
impl Camera {
|
||||
/// Returns the view matrix calculated using Eular Angles and the LookAt Matrix
|
||||
pub fn get_view_matrix(&self) -> Matrix4 {
|
||||
Matrix4::look_at(self.position, self.position + self.Front, self.Up)
|
||||
Matrix4::look_at(self.position, self.position + self.front, self.up)
|
||||
}
|
||||
|
||||
/// Processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
|
||||
pub fn process_keyboard(&mut self, direction: Camera_Movement, deltaTime: f32) {
|
||||
let velocity = self.MovementSpeed * deltaTime;
|
||||
pub fn process_keyboard(&mut self, direction: CameraMovement, delta_time: f32) {
|
||||
let velocity = self.movement_speed * delta_time;
|
||||
if direction == FORWARD {
|
||||
self.position += self.Front * velocity;
|
||||
self.position += self.front * velocity;
|
||||
}
|
||||
if direction == BACKWARD {
|
||||
self.position += -(self.Front * velocity);
|
||||
self.position += -(self.front * velocity);
|
||||
}
|
||||
if direction == LEFT {
|
||||
self.position += -(self.Right * velocity);
|
||||
self.position += -(self.right * velocity);
|
||||
}
|
||||
if direction == RIGHT {
|
||||
self.position += self.Right * velocity;
|
||||
self.position += self.right * velocity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,56 +88,56 @@ impl Camera {
|
|||
&mut self,
|
||||
mut xoffset: f32,
|
||||
mut yoffset: f32,
|
||||
constrainPitch: bool,
|
||||
constrainpitch: bool,
|
||||
) {
|
||||
xoffset *= self.MouseSensitivity;
|
||||
yoffset *= self.MouseSensitivity;
|
||||
xoffset *= self.mouse_sensivity;
|
||||
yoffset *= self.mouse_sensivity;
|
||||
|
||||
self.Yaw += xoffset;
|
||||
self.Pitch += yoffset;
|
||||
self.yaw += xoffset;
|
||||
self.pitch += yoffset;
|
||||
|
||||
// Make sure that when pitch is out of bounds, screen doesn't get flipped
|
||||
if constrainPitch {
|
||||
if self.Pitch > 89.0 {
|
||||
self.Pitch = 89.0;
|
||||
if constrainpitch {
|
||||
if self.pitch > 89.0 {
|
||||
self.pitch = 89.0;
|
||||
}
|
||||
if self.Pitch < -89.0 {
|
||||
self.Pitch = -89.0;
|
||||
if self.pitch < -89.0 {
|
||||
self.pitch = -89.0;
|
||||
}
|
||||
}
|
||||
|
||||
// Update Front, Right and Up Vectors using the updated Eular angles
|
||||
// update front, right and up Vectors using the updated Eular angles
|
||||
self.update_camera_vectors();
|
||||
}
|
||||
|
||||
// Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
|
||||
pub fn process_mouse_scroll(&mut self, yoffset: f32) {
|
||||
if self.Zoom >= 1.0 && self.Zoom <= 45.0 {
|
||||
self.Zoom -= yoffset;
|
||||
if self.zoom >= 1.0 && self.zoom <= 45.0 {
|
||||
self.zoom -= yoffset;
|
||||
}
|
||||
if self.Zoom <= 1.0 {
|
||||
self.Zoom = 1.0;
|
||||
if self.zoom <= 1.0 {
|
||||
self.zoom = 1.0;
|
||||
}
|
||||
if self.Zoom >= 45.0 {
|
||||
self.Zoom = 45.0;
|
||||
if self.zoom >= 45.0 {
|
||||
self.zoom = 45.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the front vector from the Camera's (updated) Eular Angles
|
||||
fn update_camera_vectors(&mut self) {
|
||||
// Calculate the new Front vector
|
||||
// Calculate the new front vector
|
||||
let front = Vector3 {
|
||||
x: self.Yaw.to_radians().cos() * self.Pitch.to_radians().cos(),
|
||||
y: self.Pitch.to_radians().sin(),
|
||||
z: self.Yaw.to_radians().sin() * self.Pitch.to_radians().cos(),
|
||||
x: self.yaw.to_radians().cos() * self.pitch.to_radians().cos(),
|
||||
y: self.pitch.to_radians().sin(),
|
||||
z: self.yaw.to_radians().sin() * self.pitch.to_radians().cos(),
|
||||
};
|
||||
self.Front = front.normalize();
|
||||
// Also re-calculate the Right and Up vector
|
||||
self.Right = self.Front.cross(self.WorldUp).normalize(); // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
|
||||
self.Up = self.Right.cross(self.Front).normalize();
|
||||
self.front = front.normalize();
|
||||
// Also re-calculate the right and up vector
|
||||
self.right = self.front.cross(self.worldup).normalize(); // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
|
||||
self.up = self.right.cross(self.front).normalize();
|
||||
}
|
||||
|
||||
pub fn enable_mouse_movement(&mut self, enable: bool) {
|
||||
self.MouseSensitivity = if enable { SENSITIVTY } else { 0.0 };
|
||||
self.mouse_sensivity = if enable { SENSITIVTY } else { 0.0 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,48 @@
|
|||
use imgui_inspect::InspectArgsDefault;
|
||||
use imgui_inspect::InspectRenderDefault;
|
||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||
use crate::gaia::model::Model;
|
||||
use crate::gaia::shader::Shader;
|
||||
use cgmath::{vec3, Matrix4, Vector3};
|
||||
use imgui_glfw_rs::imgui;
|
||||
use imgui_inspect::*;
|
||||
use imgui_inspect::InspectArgsDefault;
|
||||
use imgui_inspect::InspectRenderDefault;
|
||||
use imgui_inspect_derive::Inspect;
|
||||
use imgui_inspect::InspectArgsStruct;
|
||||
|
||||
struct cgmathVec3f32;
|
||||
impl InspectRenderDefault<Vector3<f32>> for cgmathVec3f32 {
|
||||
fn render(data: &[&Vector3<f32>], label: &'static str, ui: &imgui::Ui, args: &InspectArgsDefault) {
|
||||
struct CgmathVec3f32;
|
||||
impl InspectRenderDefault<Vector3<f32>> for CgmathVec3f32 {
|
||||
fn render(
|
||||
data: &[&Vector3<f32>],
|
||||
label: &'static str,
|
||||
ui: &imgui::Ui,
|
||||
_args: &InspectArgsDefault,
|
||||
) {
|
||||
ui.text(label);
|
||||
ui.text(format!("{:?}", data));
|
||||
}
|
||||
|
||||
fn render_mut(data: &mut [&mut Vector3<f32>], label: &'static str, ui: &imgui::Ui, args: &InspectArgsDefault) -> bool {
|
||||
fn render_mut(
|
||||
data: &mut [&mut Vector3<f32>],
|
||||
label: &'static str,
|
||||
ui: &imgui::Ui,
|
||||
_args: &InspectArgsDefault,
|
||||
) -> bool {
|
||||
use imgui::*;
|
||||
ui.text(label);
|
||||
let mut change = false;
|
||||
for el in data.iter_mut() {
|
||||
change |= ui.input_float(im_str!("x"), &mut el.x)
|
||||
change |= ui
|
||||
.input_float(im_str!("x"), &mut el.x)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
change |= ui
|
||||
.input_float(im_str!("y"), &mut el.y)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
change |= ui
|
||||
.input_float(im_str!("z"), &mut el.z)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
change |= ui.input_float(im_str!("y"), &mut el.y)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
change |= ui.input_float(im_str!("z"), &mut el.z)
|
||||
.step(0.01)
|
||||
.step_fast(1.0)
|
||||
.build();
|
||||
}
|
||||
change
|
||||
}
|
||||
|
|
@ -39,20 +50,20 @@ impl InspectRenderDefault<Vector3<f32>> for cgmathVec3f32 {
|
|||
|
||||
#[derive(Inspect, Clone)]
|
||||
pub struct Transform {
|
||||
#[inspect(proxy_type = "cgmathVec3f32")]
|
||||
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||
pub position: Vector3<f32>,
|
||||
#[inspect(proxy_type = "cgmathVec3f32")]
|
||||
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||
pub scale: Vector3<f32>,
|
||||
#[inspect(proxy_type = "cgmathVec3f32")]
|
||||
#[inspect(proxy_type = "CgmathVec3f32")]
|
||||
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),
|
||||
position: vec3(0.0, 0.0, 0.0),
|
||||
scale: vec3(1.0, 1.0, 1.0),
|
||||
rotation: vec3(0.0, 0.0, 0.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +71,7 @@ impl Default for Transform {
|
|||
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 = m * Matrix4::from_nonuniform_scale(self.scale.x, self.scale.y, self.scale.z);
|
||||
|
||||
m
|
||||
}
|
||||
|
|
@ -72,10 +83,10 @@ pub struct ModelComponent {
|
|||
}
|
||||
|
||||
impl ModelComponent {
|
||||
pub unsafe fn draw(&mut self, shader: &Shader ) {
|
||||
pub unsafe fn draw(&mut self, shader: &Shader) {
|
||||
let matrix = self.transform.get_matrix();
|
||||
|
||||
shader.setMat4(c_str!("model"), &matrix);
|
||||
shader.set_mat4(c_str!("model"), &matrix);
|
||||
self.model.Draw(&shader);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
// settings
|
||||
pub const SCR_WIDTH: u32 = 1280;
|
||||
pub const SCR_HEIGHT: u32 = 720;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use crate::example_client::ExampleClient;
|
||||
use crate::gaia::bg_info::BgInfo;
|
||||
use crate::gaia::camera::*;
|
||||
use crate::gaia::consts;
|
||||
use crate::gaia::*;
|
||||
use crate::example_client::ExampleClient;
|
||||
use crate::gaia::client::Client;
|
||||
use cgmath::{perspective, vec3, Deg, Matrix4, Point3, Rad, Vector3};
|
||||
use crate::gaia::consts;
|
||||
use cgmath::Point3;
|
||||
use imgui_glfw_rs::glfw;
|
||||
use imgui_glfw_rs::glfw::{Action, Context, Key};
|
||||
use imgui_glfw_rs::imgui;
|
||||
|
|
@ -66,7 +65,7 @@ impl Engine {
|
|||
{
|
||||
self.client.debug_draw(&ui);
|
||||
use imgui::*;
|
||||
let fps = 1.0 / delta_time;
|
||||
let fps = 1.0 / delta_time;
|
||||
let mut info = self.bg_info;
|
||||
Window::new(im_str!("Hello world"))
|
||||
.size([300.0, 110.0], Condition::FirstUseEver)
|
||||
|
|
@ -107,7 +106,7 @@ impl Engine {
|
|||
if self.window.get_key(Key::Escape) == Action::Press {
|
||||
self.window.set_should_close(true)
|
||||
}
|
||||
self.client.process_input(&self.window,delta_time);
|
||||
self.client.process_input(&self.window, delta_time);
|
||||
}
|
||||
|
||||
pub fn process_events(
|
||||
|
|
@ -194,60 +193,60 @@ impl Default for Engine {
|
|||
|
||||
let mut imgui = imgui::Context::create();
|
||||
{
|
||||
use imgui_glfw_rs::imgui::StyleColor;
|
||||
use imgui_glfw_rs::imgui::FontSource;
|
||||
use imgui_glfw_rs::imgui::StyleColor;
|
||||
let mut style = imgui.style_mut();
|
||||
style.scale_all_sizes(1.5);
|
||||
style[StyleColor::Text] = [1.0, 1.0, 1.0, 1.0];
|
||||
style[StyleColor::TextDisabled] = [0.5,0.5,0.5, 1.0];
|
||||
style[StyleColor::TextDisabled] = [0.5, 0.5, 0.5, 1.0];
|
||||
style[StyleColor::WindowBg] = [0.13, 0.14, 0.15, 1.0];
|
||||
style[StyleColor::ChildBg] = [0.13, 0.14, 0.15, 1.0];
|
||||
style[StyleColor::PopupBg] = [0.13, 0.14, 0.15, 1.0];
|
||||
style[StyleColor::Border] = [0.43, 0.43, 0.50, 0.50];
|
||||
style[StyleColor::BorderShadow] = [0.00, 0.00, 0.00, 0.00];
|
||||
style[StyleColor::FrameBg] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::FrameBgHovered] = [0.38, 0.38, 0.38, 1.00];
|
||||
style[StyleColor::FrameBgActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::TitleBg] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TitleBgActive] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TitleBgCollapsed] = [0.00, 0.00, 0.00, 0.51];
|
||||
style[StyleColor::MenuBarBg] = [0.14, 0.14, 0.14, 1.00];
|
||||
style[StyleColor::ScrollbarBg] = [0.02, 0.02, 0.02, 0.53];
|
||||
style[StyleColor::ScrollbarGrab] = [0.31, 0.31, 0.31, 1.00];
|
||||
style[StyleColor::ScrollbarGrabHovered] = [0.41, 0.41, 0.41, 1.00];
|
||||
style[StyleColor::ScrollbarGrabActive] = [0.51, 0.51, 0.51, 1.00];
|
||||
style[StyleColor::CheckMark] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::SliderGrab] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::SliderGrabActive] = [0.08, 0.50, 0.72, 1.00];
|
||||
style[StyleColor::Button] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::ButtonHovered] = [0.38, 0.38, 0.38, 1.00];
|
||||
style[StyleColor::ButtonActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::Header] = [0.22, 0.22, 0.22, 1.00];
|
||||
style[StyleColor::HeaderHovered] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::HeaderActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::Separator] = style[StyleColor::Border];
|
||||
style[StyleColor::SeparatorHovered] = [0.41, 0.42, 0.44, 1.00];
|
||||
style[StyleColor::SeparatorActive] = [0.26, 0.59, 0.98, 0.95];
|
||||
style[StyleColor::ResizeGrip] = [0.00, 0.00, 0.00, 0.00];
|
||||
style[StyleColor::ResizeGripHovered] = [0.29, 0.30, 0.31, 0.67];
|
||||
style[StyleColor::ResizeGripActive] = [0.26, 0.59, 0.98, 0.95];
|
||||
style[StyleColor::Tab] = [0.08, 0.08, 0.09, 0.83];
|
||||
style[StyleColor::TabHovered] = [0.33, 0.34, 0.36, 0.83];
|
||||
style[StyleColor::TabActive] = [0.23, 0.23, 0.24, 1.00];
|
||||
style[StyleColor::TabUnfocused] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TabUnfocusedActive] = [0.13, 0.14, 0.15, 1.00];
|
||||
style[StyleColor::BorderShadow] = [0.00, 0.00, 0.00, 0.00];
|
||||
style[StyleColor::FrameBg] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::FrameBgHovered] = [0.38, 0.38, 0.38, 1.00];
|
||||
style[StyleColor::FrameBgActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::TitleBg] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TitleBgActive] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TitleBgCollapsed] = [0.00, 0.00, 0.00, 0.51];
|
||||
style[StyleColor::MenuBarBg] = [0.14, 0.14, 0.14, 1.00];
|
||||
style[StyleColor::ScrollbarBg] = [0.02, 0.02, 0.02, 0.53];
|
||||
style[StyleColor::ScrollbarGrab] = [0.31, 0.31, 0.31, 1.00];
|
||||
style[StyleColor::ScrollbarGrabHovered] = [0.41, 0.41, 0.41, 1.00];
|
||||
style[StyleColor::ScrollbarGrabActive] = [0.51, 0.51, 0.51, 1.00];
|
||||
style[StyleColor::CheckMark] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::SliderGrab] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::SliderGrabActive] = [0.08, 0.50, 0.72, 1.00];
|
||||
style[StyleColor::Button] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::ButtonHovered] = [0.38, 0.38, 0.38, 1.00];
|
||||
style[StyleColor::ButtonActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::Header] = [0.22, 0.22, 0.22, 1.00];
|
||||
style[StyleColor::HeaderHovered] = [0.25, 0.25, 0.25, 1.00];
|
||||
style[StyleColor::HeaderActive] = [0.67, 0.67, 0.67, 0.39];
|
||||
style[StyleColor::Separator] = style[StyleColor::Border];
|
||||
style[StyleColor::SeparatorHovered] = [0.41, 0.42, 0.44, 1.00];
|
||||
style[StyleColor::SeparatorActive] = [0.26, 0.59, 0.98, 0.95];
|
||||
style[StyleColor::ResizeGrip] = [0.00, 0.00, 0.00, 0.00];
|
||||
style[StyleColor::ResizeGripHovered] = [0.29, 0.30, 0.31, 0.67];
|
||||
style[StyleColor::ResizeGripActive] = [0.26, 0.59, 0.98, 0.95];
|
||||
style[StyleColor::Tab] = [0.08, 0.08, 0.09, 0.83];
|
||||
style[StyleColor::TabHovered] = [0.33, 0.34, 0.36, 0.83];
|
||||
style[StyleColor::TabActive] = [0.23, 0.23, 0.24, 1.00];
|
||||
style[StyleColor::TabUnfocused] = [0.08, 0.08, 0.09, 1.00];
|
||||
style[StyleColor::TabUnfocusedActive] = [0.13, 0.14, 0.15, 1.00];
|
||||
// style[StyleColor::DockingPreview] = [0.26, 0.59, 0.98, 0.70];
|
||||
// style[StyleColor::DockingEmptyBg] = [0.20, 0.20, 0.20, 1.00];
|
||||
style[StyleColor::PlotLines] = [0.61, 0.61, 0.61, 1.00];
|
||||
style[StyleColor::PlotLinesHovered] = [1.00, 0.43, 0.35, 1.00];
|
||||
style[StyleColor::PlotHistogram] = [0.90, 0.70, 0.00, 1.00];
|
||||
style[StyleColor::PlotHistogramHovered] = [1.00, 0.60, 0.00, 1.00];
|
||||
style[StyleColor::TextSelectedBg] = [0.26, 0.59, 0.98, 0.35];
|
||||
style[StyleColor::DragDropTarget] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::NavHighlight] = [0.26, 0.59, 0.98, 1.00];
|
||||
style[StyleColor::PlotLines] = [0.61, 0.61, 0.61, 1.00];
|
||||
style[StyleColor::PlotLinesHovered] = [1.00, 0.43, 0.35, 1.00];
|
||||
style[StyleColor::PlotHistogram] = [0.90, 0.70, 0.00, 1.00];
|
||||
style[StyleColor::PlotHistogramHovered] = [1.00, 0.60, 0.00, 1.00];
|
||||
style[StyleColor::TextSelectedBg] = [0.26, 0.59, 0.98, 0.35];
|
||||
style[StyleColor::DragDropTarget] = [0.11, 0.64, 0.92, 1.00];
|
||||
style[StyleColor::NavHighlight] = [0.26, 0.59, 0.98, 1.00];
|
||||
style[StyleColor::NavWindowingHighlight] = [1.00, 1.00, 1.00, 0.70];
|
||||
style[StyleColor::NavWindowingDimBg] = [0.80, 0.80, 0.80, 0.20];
|
||||
style[StyleColor::ModalWindowDimBg] = [0.80, 0.80, 0.80, 0.35];
|
||||
style[StyleColor::NavWindowingDimBg] = [0.80, 0.80, 0.80, 0.20];
|
||||
style[StyleColor::ModalWindowDimBg] = [0.80, 0.80, 0.80, 0.35];
|
||||
style.grab_rounding = 2.3;
|
||||
style.frame_rounding = style.grab_rounding;
|
||||
imgui.fonts().clear();
|
||||
|
|
@ -257,10 +256,12 @@ impl Default for Engine {
|
|||
config: None,
|
||||
}]);
|
||||
}
|
||||
let mut imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window);
|
||||
let imgui_glfw = ImguiGLFW::new(&mut imgui, &mut window);
|
||||
// configure global opengl state
|
||||
// -----------------------------
|
||||
unsafe{gl::Enable(gl::DEPTH_TEST);}
|
||||
unsafe {
|
||||
gl::Enable(gl::DEPTH_TEST);
|
||||
}
|
||||
|
||||
Engine {
|
||||
bg_info: BgInfo::default(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::mem::size_of;
|
||||
|
|
@ -20,23 +20,23 @@ pub struct Vertex {
|
|||
// position
|
||||
pub position: Vector3<f32>,
|
||||
// normal
|
||||
pub Normal: Vector3<f32>,
|
||||
pub normal: Vector3<f32>,
|
||||
// texCoords
|
||||
pub TexCoords: Vector2<f32>,
|
||||
pub text_coords: Vector2<f32>,
|
||||
// tangent
|
||||
pub Tangent: Vector3<f32>,
|
||||
pub tangent: Vector3<f32>,
|
||||
// bitangent
|
||||
pub Bitangent: Vector3<f32>,
|
||||
pub bitangent: Vector3<f32>,
|
||||
}
|
||||
|
||||
impl Default for Vertex {
|
||||
fn default() -> Self {
|
||||
Vertex {
|
||||
position: Vector3::zero(),
|
||||
Normal: Vector3::zero(),
|
||||
TexCoords: Vector2::zero(),
|
||||
Tangent: Vector3::zero(),
|
||||
Bitangent: Vector3::zero(),
|
||||
normal: Vector3::zero(),
|
||||
text_coords: Vector2::zero(),
|
||||
tangent: Vector3::zero(),
|
||||
bitangent: Vector3::zero(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ impl Mesh {
|
|||
gl::FLOAT,
|
||||
gl::FALSE,
|
||||
size,
|
||||
offset_of!(Vertex, Normal) as *const c_void,
|
||||
offset_of!(Vertex, normal) as *const c_void,
|
||||
);
|
||||
// vertex texture coords
|
||||
gl::EnableVertexAttribArray(2);
|
||||
|
|
@ -181,7 +181,7 @@ impl Mesh {
|
|||
gl::FLOAT,
|
||||
gl::FALSE,
|
||||
size,
|
||||
offset_of!(Vertex, TexCoords) as *const c_void,
|
||||
offset_of!(Vertex, text_coords) as *const c_void,
|
||||
);
|
||||
// vertex tangent
|
||||
gl::EnableVertexAttribArray(3);
|
||||
|
|
@ -191,7 +191,7 @@ impl Mesh {
|
|||
gl::FLOAT,
|
||||
gl::FALSE,
|
||||
size,
|
||||
offset_of!(Vertex, Tangent) as *const c_void,
|
||||
offset_of!(Vertex, tangent) as *const c_void,
|
||||
);
|
||||
// vertex bitangent
|
||||
gl::EnableVertexAttribArray(4);
|
||||
|
|
@ -201,7 +201,7 @@ impl Mesh {
|
|||
gl::FLOAT,
|
||||
gl::FALSE,
|
||||
size,
|
||||
offset_of!(Vertex, Bitangent) as *const c_void,
|
||||
offset_of!(Vertex, bitangent) as *const c_void,
|
||||
);
|
||||
|
||||
gl::BindVertexArray(0);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
pub mod macros;
|
||||
pub mod camera;
|
||||
pub mod components;
|
||||
pub mod client;
|
||||
pub mod consts;
|
||||
pub mod utils;
|
||||
|
||||
pub mod bg_info;
|
||||
pub mod camera;
|
||||
pub mod client;
|
||||
pub mod components;
|
||||
pub mod consts;
|
||||
pub mod engine;
|
||||
pub mod mesh;
|
||||
pub mod model;
|
||||
pub mod shader;
|
||||
pub mod utils;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::os::raw::c_void;
|
||||
use std::path::Path;
|
||||
|
||||
use cgmath::{vec2, vec3};
|
||||
use gl;
|
||||
use image;
|
||||
use image::DynamicImage::*;
|
||||
use image::GenericImage;
|
||||
use tobj;
|
||||
|
||||
use crate::gaia::mesh::{Mesh, Texture, Vertex};
|
||||
use crate::gaia::shader::Shader;
|
||||
use crate::gaia::utils::*;
|
||||
use cgmath::{vec2, vec3};
|
||||
use std::path::Path;
|
||||
use tobj;
|
||||
|
||||
// #[derive(Default)]
|
||||
pub struct Model {
|
||||
|
|
@ -37,7 +30,7 @@ impl Model {
|
|||
.unwrap()
|
||||
.into(),
|
||||
};
|
||||
model.loadModel(path);
|
||||
model.load_model(path);
|
||||
model
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +43,7 @@ impl Model {
|
|||
}
|
||||
|
||||
// loads a model from file and stores the resulting meshes in the meshes vector.
|
||||
fn loadModel(&mut self, path: &str) {
|
||||
fn load_model(&mut self, path: &str) {
|
||||
let path = Path::new(path);
|
||||
println!("Started loading model from path: {}", path.display());
|
||||
|
||||
|
|
@ -76,8 +69,8 @@ impl Model {
|
|||
for i in 0..num_vertices {
|
||||
vertices.push(Vertex {
|
||||
position: vec3(p[i * 3], p[i * 3 + 1], p[i * 3 + 2]),
|
||||
Normal: vec3(n[i * 3], n[i * 3 + 1], n[i * 3 + 2]),
|
||||
TexCoords: vec2(t[i * 2], t[i * 2 + 1]),
|
||||
normal: vec3(n[i * 3], n[i * 3 + 1], n[i * 3 + 2]),
|
||||
text_coords: vec2(t[i * 2], t[i * 2 + 1]),
|
||||
..Vertex::default()
|
||||
})
|
||||
}
|
||||
|
|
@ -90,19 +83,19 @@ impl Model {
|
|||
// 1. diffuse map
|
||||
if !material.diffuse_texture.is_empty() {
|
||||
let texture =
|
||||
self.loadMaterialTexture(&material.diffuse_texture, "texture_diffuse");
|
||||
self.load_material_texture(&material.diffuse_texture, "texture_diffuse");
|
||||
textures.push(texture);
|
||||
}
|
||||
// 2. specular map
|
||||
if !material.specular_texture.is_empty() {
|
||||
let texture =
|
||||
self.loadMaterialTexture(&material.specular_texture, "texture_specular");
|
||||
self.load_material_texture(&material.specular_texture, "texture_specular");
|
||||
textures.push(texture);
|
||||
}
|
||||
// 3. normal map
|
||||
if !material.normal_texture.is_empty() {
|
||||
let texture =
|
||||
self.loadMaterialTexture(&material.normal_texture, "texture_normal");
|
||||
self.load_material_texture(&material.normal_texture, "texture_normal");
|
||||
textures.push(texture);
|
||||
}
|
||||
// NOTE: no height maps
|
||||
|
|
@ -113,7 +106,7 @@ impl Model {
|
|||
println!("Finished loading model from path: {}", path.display());
|
||||
}
|
||||
|
||||
fn loadMaterialTexture(&mut self, path: &str, typeName: &str) -> Texture {
|
||||
fn load_material_texture(&mut self, path: &str, typeName: &str) -> Texture {
|
||||
{
|
||||
let texture = self.textures_loaded.iter().find(|t| t.path == path);
|
||||
if let Some(texture) = texture {
|
||||
|
|
|
|||
|
|
@ -38,18 +38,18 @@ impl Shader {
|
|||
let vertex = gl::CreateShader(gl::VERTEX_SHADER);
|
||||
gl::ShaderSource(vertex, 1, &vShaderCode.as_ptr(), ptr::null());
|
||||
gl::CompileShader(vertex);
|
||||
shader.checkCompileErrors(vertex, "VERTEX");
|
||||
shader.check_compile_errors(vertex, "VERTEX");
|
||||
// fragment Shader
|
||||
let fragment = gl::CreateShader(gl::FRAGMENT_SHADER);
|
||||
gl::ShaderSource(fragment, 1, &fShaderCode.as_ptr(), ptr::null());
|
||||
gl::CompileShader(fragment);
|
||||
shader.checkCompileErrors(fragment, "FRAGMENT");
|
||||
shader.check_compile_errors(fragment, "FRAGMENT");
|
||||
// shader Program
|
||||
let ID = gl::CreateProgram();
|
||||
gl::AttachShader(ID, vertex);
|
||||
gl::AttachShader(ID, fragment);
|
||||
gl::LinkProgram(ID);
|
||||
shader.checkCompileErrors(ID, "PROGRAM");
|
||||
shader.check_compile_errors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and no longer necessary
|
||||
gl::DeleteShader(vertex);
|
||||
gl::DeleteShader(fragment);
|
||||
|
|
@ -82,7 +82,7 @@ impl Shader {
|
|||
|
||||
/// activate the shader
|
||||
/// ------------------------------------------------------------------------
|
||||
pub unsafe fn useProgram(&self) {
|
||||
pub unsafe fn use_program(&self) {
|
||||
gl::UseProgram(self.ID)
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ impl Shader {
|
|||
gl::Uniform1f(gl::GetUniformLocation(self.ID, name.as_ptr()), value);
|
||||
}
|
||||
/// ------------------------------------------------------------------------
|
||||
pub unsafe fn setVector3(&self, name: &CStr, value: &Vector3<f32>) {
|
||||
pub unsafe fn set_vector3(&self, name: &CStr, value: &Vector3<f32>) {
|
||||
gl::Uniform3fv(
|
||||
gl::GetUniformLocation(self.ID, name.as_ptr()),
|
||||
1,
|
||||
|
|
@ -108,11 +108,11 @@ impl Shader {
|
|||
);
|
||||
}
|
||||
/// ------------------------------------------------------------------------
|
||||
pub unsafe fn setVec3(&self, name: &CStr, x: f32, y: f32, z: f32) {
|
||||
pub unsafe fn set_vec3(&self, name: &CStr, x: f32, y: f32, z: f32) {
|
||||
gl::Uniform3f(gl::GetUniformLocation(self.ID, name.as_ptr()), x, y, z);
|
||||
}
|
||||
/// ------------------------------------------------------------------------
|
||||
pub unsafe fn setMat4(&self, name: &CStr, mat: &Matrix4<f32>) {
|
||||
pub unsafe fn set_mat4(&self, name: &CStr, mat: &Matrix4<f32>) {
|
||||
gl::UniformMatrix4fv(
|
||||
gl::GetUniformLocation(self.ID, name.as_ptr()),
|
||||
1,
|
||||
|
|
@ -123,7 +123,7 @@ impl Shader {
|
|||
|
||||
/// utility function for checking shader compilation/linking errors.
|
||||
/// ------------------------------------------------------------------------
|
||||
unsafe fn checkCompileErrors(&self, shader: u32, type_: &str) {
|
||||
unsafe fn check_compile_errors(&self, shader: u32, type_: &str) {
|
||||
let mut is_success = gl::FALSE as GLint;
|
||||
let mut infoLog = Vec::with_capacity(1024);
|
||||
infoLog.set_len(1024 - 1); // subtract 1 to skip the trailing null character
|
||||
|
|
@ -195,17 +195,17 @@ impl Shader {
|
|||
let vertex = gl::CreateShader(gl::VERTEX_SHADER);
|
||||
gl::ShaderSource(vertex, 1, &vShaderCode.as_ptr(), ptr::null());
|
||||
gl::CompileShader(vertex);
|
||||
shader.checkCompileErrors(vertex, "VERTEX");
|
||||
shader.check_compile_errors(vertex, "VERTEX");
|
||||
// fragment Shader
|
||||
let fragment = gl::CreateShader(gl::FRAGMENT_SHADER);
|
||||
gl::ShaderSource(fragment, 1, &fShaderCode.as_ptr(), ptr::null());
|
||||
gl::CompileShader(fragment);
|
||||
shader.checkCompileErrors(fragment, "FRAGMENT");
|
||||
shader.check_compile_errors(fragment, "FRAGMENT");
|
||||
// geometry shader
|
||||
let geometry = gl::CreateShader(gl::GEOMETRY_SHADER);
|
||||
gl::ShaderSource(geometry, 1, &gShaderCode.as_ptr(), ptr::null());
|
||||
gl::CompileShader(geometry);
|
||||
shader.checkCompileErrors(geometry, "GEOMETRY");
|
||||
shader.check_compile_errors(geometry, "GEOMETRY");
|
||||
|
||||
// shader Program
|
||||
let ID = gl::CreateProgram();
|
||||
|
|
@ -213,7 +213,7 @@ impl Shader {
|
|||
gl::AttachShader(ID, fragment);
|
||||
gl::AttachShader(ID, geometry);
|
||||
gl::LinkProgram(ID);
|
||||
shader.checkCompileErrors(ID, "PROGRAM");
|
||||
shader.check_compile_errors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and no longer necessary
|
||||
gl::DeleteShader(vertex);
|
||||
gl::DeleteShader(fragment);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use std::os::raw::c_void;
|
||||
use std::path::Path;
|
||||
use gl;
|
||||
use image;
|
||||
use image::DynamicImage::*;
|
||||
use image::GenericImage;
|
||||
use image::*;
|
||||
use std::os::raw::c_void;
|
||||
use std::path::Path;
|
||||
|
||||
pub unsafe fn load_texture(path: &str) -> u32 {
|
||||
println!("Loading texture from path: {}", path);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use human_panic::setup_panic;
|
|||
mod gaia;
|
||||
mod example_client;
|
||||
use crate::gaia::engine::Engine;
|
||||
use crate::example_client::ExampleClient;
|
||||
|
||||
pub fn main() {
|
||||
setup_panic!();
|
||||
|
|
|
|||
Loading…
Reference in New Issue