Compare commits

...

2 Commits

Author SHA1 Message Date
Milk.H f5253f16e8
runs, however i do not have the correct formula for calculating the
finalmodel
2023-04-01 18:41:26 +02:00
Milk.H 7eb4ece49f
it pans properly now 2023-03-31 23:59:59 +02:00
5 changed files with 53 additions and 11 deletions

View File

@ -8,9 +8,7 @@ uniform sampler2D tex;
void main()
{
// Sample the texture using the texture coordinates
vec4 tex_color = texture(tex, v_texcoord);
vec4 tex_color = texture(tex, v_texcoord*60);
// Output the final color
frag_color = tex_color;
}

View File

@ -18,7 +18,5 @@ void main()
gl_Position = projection * view * model * vec4(position, 1.0);
// Calculate the texture coordinate offset based on the camera position
vec2 offset = (camera_position.xz - position.xz) / tile_size;
offset += scroll_speed * vec2(0, 1) * -(gl_Position.w / projection[1][1]);
v_texcoord = texcoord + offset;
v_texcoord = texcoord;
}

View File

@ -13,6 +13,8 @@ use tobj;
mod mesh;
use mesh::{ Mesh, Texture, Vertex };
use crate::shader::shader;
use crate::scene::objects::Transform;
use crate::camera::Camera;
#[derive(Default)]
pub struct Model {
@ -29,11 +31,45 @@ impl Model {
model.loadModel(path, Arc::clone(&gl));
model
}
/// NOTE problem with this implementation is that only one range and transform could be specified
pub fn Draw(&self, shader: &shader, opt: Option<(std::ops::Range<i32>,Transform, &Camera, cgmath::Matrix4<f32> )>) {
if opt.is_some()
{
let (range, transform, camera, model) = opt.unwrap();
for (i, mesh) in self.meshes.iter().enumerate() {
pub fn Draw(&self, shader: &shader) {
for mesh in &self.meshes {
// run all meshes as normal
if !range.contains(&(i as i32))
{
unsafe {mesh.Draw(shader); }
}
unsafe { mesh.Draw(shader); }
}
// run the special Transforms for the meshes specified
let translation = cgmath::Matrix4::from_translation(transform.Position);
let rotation = cgmath::Matrix4::from(transform.Rotation);
let scale = cgmath::Matrix4::from_scale(transform.Scale);
let finalmod = model * (translation * rotation * scale);
let projection = cgmath::perspective(cgmath::Deg(camera.Zoom), 1600.0 /900.0, 0.1, 100.0);
let view = camera.GetViewMatrix();
shader.Use();
shader.setMat4("projection", &projection);
shader.setMat4("view", &view);
shader.setMat4("model", &finalmod);
for i in range
{
unsafe {self.meshes[i as usize].Draw(shader)}
}
} else {
{
for (i, mesh) in self.meshes.iter().enumerate() {
unsafe { mesh.Draw(shader); }
}
}
}
}

View File

@ -11,6 +11,7 @@ use cgmath::prelude::*;
use glow::*;
use field_offset::offset_of;
use crate::scene::objects;
use crate::shader::shader;
// NOTE: without repr(C) the compiler may reorder the fields or use different padding/alignment than C.
// Depending on how you pass the data to OpenGL, this may be bad. In this case it's not strictly

View File

@ -15,6 +15,8 @@ pub struct Input {
pub Right: bool
}
// TODO make a struct to pass info
impl Default for Input {
fn default() -> Input {
Input {
@ -103,6 +105,7 @@ impl Player {
{
shader.Use();
let translation = cgmath::Matrix4::from_translation(self.Transform.Position);
let rotation = cgmath::Matrix4::from(self.Transform.Rotation);
let scale = cgmath::Matrix4::from_scale(self.Transform.Scale);
@ -115,7 +118,14 @@ impl Player {
shader.setMat4("model", &model);
self.Model.Draw(shader);
let turned = Transform {
Scale: 1.0,
..Transform::default()
};
self.Model.Draw(shader, Some((1..3, turned, camera, model)));
}
}
@ -184,7 +194,6 @@ impl plane {
unsafe {
shader.Use();
let model = cgmath::Matrix4::from_angle_x(cgmath::Deg(-90.0));
let projection = cgmath::perspective(cgmath::Deg(camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0);
let view = camera.GetViewMatrix();