Compare commits

..

No commits in common. "f5253f16e8f7a6cb5ec2c38122ec039f5e085202" and "df9c5f387f029a96177035dfa14e229335ce6454" have entirely different histories.

5 changed files with 11 additions and 53 deletions

View File

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

View File

@ -18,5 +18,7 @@ void main()
gl_Position = projection * view * model * vec4(position, 1.0);
// Calculate the texture coordinate offset based on the camera position
v_texcoord = texcoord;
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;
}

View File

@ -13,8 +13,6 @@ 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 {
@ -31,45 +29,11 @@ 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() {
// run all meshes as normal
if !range.contains(&(i as i32))
{
unsafe {mesh.Draw(shader); }
}
pub fn Draw(&self, shader: &shader) {
for mesh in &self.meshes {
}
// 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); }
}
}
unsafe { mesh.Draw(shader); }
}
}

View File

@ -11,7 +11,6 @@ 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,8 +15,6 @@ pub struct Input {
pub Right: bool
}
// TODO make a struct to pass info
impl Default for Input {
fn default() -> Input {
Input {
@ -105,7 +103,6 @@ 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);
@ -118,14 +115,7 @@ impl Player {
shader.setMat4("model", &model);
let turned = Transform {
Scale: 1.0,
..Transform::default()
};
self.Model.Draw(shader, Some((1..3, turned, camera, model)));
self.Model.Draw(shader);
}
}
@ -194,6 +184,7 @@ 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();