diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-01 16:02:59 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-05-01 16:02:59 -0400 |
| commit | b14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0 (patch) | |
| tree | 68d47ea946136025890265cc2185a728e4593b96 /src/tacmap | |
| parent | 961f8c6d405c9c6fcf9aaf4fb6f199b0e5c60d88 (diff) | |
| download | systemic4x-b14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0.tar.gz systemic4x-b14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0.tar.bz2 systemic4x-b14dd1c1f3e198137fa8b9e0c4f5e56949b11cd0.zip | |
i don't know how to get the line segments to render right
Diffstat (limited to 'src/tacmap')
| -rw-r--r-- | src/tacmap/camera.rs | 2 | ||||
| -rw-r--r-- | src/tacmap/render.rs | 81 |
2 files changed, 49 insertions, 34 deletions
diff --git a/src/tacmap/camera.rs b/src/tacmap/camera.rs index ae9bcfa..ada36ee 100644 --- a/src/tacmap/camera.rs +++ b/src/tacmap/camera.rs @@ -285,7 +285,7 @@ impl CameraController let (az_sin, az_cos) = camera.yaw.0.sin_cos(); let (p_sin, p_cos) = camera.pitch.0.sin_cos(); - let radius = f32::max(target_radius * camera.scale, current_radius + dist_diff).max(0.1); + let radius = 1.0; camera.rel_position = Vector3::new( radius * p_cos * az_cos, radius * p_sin, diff --git a/src/tacmap/render.rs b/src/tacmap/render.rs index c2bd354..48823e2 100644 --- a/src/tacmap/render.rs +++ b/src/tacmap/render.rs @@ -1,28 +1,16 @@ use std::{fmt::Display, num::NonZero}; use std::error::Error; +use cgmath::InnerSpace; use wgpu::RenderPass; use crate::canvas::Canvas; use crate::solar_system::Kilometers; use crate::tacmap::camera::Camera; +use crate::timeman::DAY; use crate::wgpuctx::{RenderPassBuilder, SceneCtx}; use crate::{solar_system::{SolarSystem, SystemId}, timeman::Second, vertex::{self, Vertex}, wgpuctx::{WgpuCtx, pipeline::RenderPipelineBuilder}}; -struct BodyInstance -{ - position: cgmath::Vector3<Kilometers>, - radius: f32 -} - -#[repr(C)] -#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] -struct BodyInstanceRaw -{ - position: [f32;3], - radius: f32 -} - #[derive(Debug, Clone)] pub struct NeedsRebuildError; @@ -129,9 +117,17 @@ impl BodyRenderer let bodies = solar_system.bodies(); let body_instances = bodies.iter().map(|body| { - let position = solar_system.body_position(body); + let position = body.position(); + let origin = match body.get_orbits() { + Some(origin_id) => { + let origin_body = &bodies[origin_id]; + origin_body.position() + }, + None => cgmath::Vector3::new(0.0, 0.0, 0.0) + }; BodyInstance { position: position, + origin: origin, radius: body.radius() }.raw() }).collect::<Vec<_>>(); @@ -160,6 +156,22 @@ impl BodyRenderer } } // impl RenderState +struct BodyInstance +{ + position: cgmath::Vector3<Kilometers>, + origin: cgmath::Vector3<Kilometers>, + radius: f32 +} + +#[repr(C)] +#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +struct BodyInstanceRaw +{ + position: [f32;3], + origin: [f32;3], + radius: f32 +} + impl BodyInstance { fn raw(&self) -> BodyInstanceRaw @@ -169,6 +181,10 @@ impl BodyInstance self.position.x as f32, self.position.y as f32, self.position.z as f32 ], + origin: [ + self.origin.x as f32, + self.origin.y as f32, + self.origin.z as f32 ], radius: self.radius } } @@ -176,23 +192,17 @@ impl BodyInstance impl BodyInstanceRaw { - fn descr() -> wgpu::VertexBufferLayout<'static> { + const ATTRIBS: [wgpu::VertexAttribute;3] = + wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Float32]; + + pub fn descr() + -> wgpu::VertexBufferLayout<'static> { use std::mem; + wgpu::VertexBufferLayout { - array_stride: mem::size_of::<BodyInstanceRaw>() as wgpu::BufferAddress, + array_stride: mem::size_of::<Self>() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Instance, - attributes: &[ - wgpu::VertexAttribute { - offset: 0, - shader_location: 0, - format: wgpu::VertexFormat::Float32x3 - }, - wgpu::VertexAttribute { - offset: mem::size_of::<[f32;3]>() as wgpu::BufferAddress, - shader_location: 1, - format: wgpu::VertexFormat::Float32 - } - ] + attributes: &Self::ATTRIBS } } } @@ -360,11 +370,12 @@ impl OrbitRenderer if !body.does_orbit() { return (0, None); } let period = body.orbital_period(); - let period_interval = period as f64 / 360.0; + let num_points = ((period / (5 * DAY)) as usize).max(360); + let period_interval = period as f64 / num_points as f64; let mut points = vec![ - OrbitVertex::default();361*2]; - for i in 0..361 { + OrbitVertex::default();(num_points+1)*2]; + for i in 0..num_points { let position = body.calculate_orbit_at( (i as f64 * period_interval) as u64); @@ -374,8 +385,12 @@ impl OrbitRenderer position.y as f32, position.z as f32 ]; + points[(i*2)+1] = points[i*2].clone(); } + points[num_points*2] = points[0].clone(); + points[num_points*2+1] = points[1].clone(); + let buffer = wgpuctx.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: None, @@ -383,7 +398,7 @@ impl OrbitRenderer contents: bytemuck::cast_slice(&points) } ); - (361*2, Some(buffer)) + ((num_points+1)*2, Some(buffer)) }).collect::<Vec<_>>()); } |
