-
Notifications
You must be signed in to change notification settings - Fork 37
One vertex buffer to rule them all #190
Changes from 13 commits
3f2414c
e3fd5e6
d44443d
6cf6c97
b172b5e
b5e0665
4b93016
228156b
b807c1f
1cb6fdc
2181d98
679180d
de70091
65b370d
40ce2fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,34 +31,37 @@ impl AxialPoint { | |
/// system using `world::{HEX_INNER_RADIUS, HEX_OUTER_RADIUS}`. | ||
pub fn to_real(&self) -> Point2f { | ||
Point2f { | ||
x: ((2 * self.q + self.r) as DefaultFloat) * HEX_INNER_RADIUS, | ||
x: ((2 * self.q - self.r) as DefaultFloat) * HEX_INNER_RADIUS, | ||
y: (self.r as DefaultFloat) * (3.0 / 2.0) * HEX_OUTER_RADIUS, | ||
} | ||
} | ||
|
||
/// Return the `AxialPoint` from a `Point2f` | ||
pub fn from_real(real: Point2f) -> Self { | ||
let q: f32 = (real.x * ::math::SQRT_3 / 3.0 - real.y / 3.0) / HEX_OUTER_RADIUS; | ||
let r: f32 = (real.y * 2.0 / 3.0) / HEX_OUTER_RADIUS; | ||
let q = (real.x * ::math::SQRT_3 / 3.0 - real.y / 3.0) / HEX_OUTER_RADIUS; | ||
let r = (real.y * 2.0 / 3.0) / HEX_OUTER_RADIUS; | ||
|
||
let y: f32 = -q - r; | ||
let s = -q - r; | ||
|
||
// Rounding | ||
let mut rx: i32 = q.round() as i32; | ||
let ry: i32 = y.round() as i32; | ||
let mut rz: i32 = r.round() as i32; | ||
let rq = q.round(); | ||
let mut rr = r.round(); | ||
let mut rs = s.round(); | ||
|
||
// To test the right rounding | ||
let x_diff = (rx as f32 - q).abs(); | ||
let y_diff = (ry as f32 - y).abs(); | ||
let z_diff = (rz as f32 - r).abs(); | ||
if x_diff > y_diff && x_diff > z_diff { | ||
rx = -ry - rz; | ||
} else if y_diff <= z_diff { | ||
rz = -rx - ry; | ||
let q_diff = (rq - q).abs(); | ||
let r_diff = (rr - r).abs(); | ||
let s_diff = (rs - s).abs(); | ||
|
||
if q_diff > r_diff && q_diff > s_diff { | ||
// rq = -rr - rs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this stay or should this go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I actually want this to stay, since it then represents the algorithm from redblobgames.com more closely. But I can add a comment. Will do it tomorrow when fixing the other stuff. |
||
} else if s_diff > r_diff { | ||
rr = -rq - rs; | ||
} else { | ||
rs = -rq - rr; | ||
} | ||
|
||
AxialPoint { q: rx, r: rz } | ||
AxialPoint { q: -rs as AxialType, r: rr as AxialType} | ||
} | ||
|
||
/// Returns the `s` component of corresponding cube coordinates. In cube | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,14 @@ | |
in vec3 position; | ||
in vec3 normal; | ||
|
||
// Per-instance attributes: | ||
// Height in units, not world coordinates, since the "pillar prototype" has a | ||
// height of one unit. | ||
in float height; | ||
in vec3 offset; | ||
//in vec3 material_color; | ||
|
||
uniform mat4 proj_matrix; | ||
uniform mat4 view_matrix; | ||
uniform vec2 offset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks unused too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm... what about ... |
||
|
||
void main() { | ||
vec4 world_coords = vec4( | ||
position.xy + offset.xy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nevermind 😆 |
||
position.z * height + offset.z, | ||
position.z, | ||
1); | ||
gl_Position = proj_matrix * view_matrix * world_coords; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,6 @@ in vec3 position; | |
in vec3 normal; | ||
in float radius; | ||
in vec2 tex_coords; | ||
|
||
// Per-instance attributes: | ||
// Height in units, not world coordinates, since the "pillar prototype" has a | ||
// height of one unit. | ||
in float height; | ||
in vec3 offset; | ||
in vec3 material_color; | ||
in int ground; | ||
|
||
|
@@ -32,12 +26,13 @@ out vec3 pos; | |
uniform mat4 proj_matrix; | ||
uniform mat4 view_matrix; | ||
uniform mat4 depth_view_proj; | ||
uniform vec2 offset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
uniform vec3 cam_pos; | ||
|
||
void main() { | ||
vec4 world_coords = vec4( | ||
position.xy + offset.xy, | ||
position.z * height + offset.z, | ||
position.z, | ||
1); | ||
|
||
gl_Position = proj_matrix * view_matrix * world_coords; | ||
|
@@ -48,15 +43,10 @@ void main() { | |
x_radius = radius; | ||
x_tex_coords = tex_coords; | ||
|
||
// adjusting the height for the sides of each hexagon | ||
if(tex_coords.y > 1.5){ | ||
x_tex_coords.y = height; | ||
} | ||
|
||
x_position = position; | ||
x_ground = ground; | ||
|
||
// position in relation to player ignoring hight, needed for fog | ||
pos = vec3(offset - cam_pos); | ||
// pos = vec3(offset - cam_pos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the line below read |
||
pos = vec3(pos.x, pos.y, 0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, not even this was correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... there are many "correct" versions. In the version of the axial coordinate system that I chose this was wrong, yes.