Skip to content

Commit

Permalink
fix: normalize quad basis before computing verts
Browse files Browse the repository at this point in the history
  • Loading branch information
cbgbt committed Nov 23, 2024
1 parent 34141e8 commit 0582a1a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
31 changes: 16 additions & 15 deletions pyraydeon/examples/py_rhombohedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ def __init__(self, origin, basis, dims):
self.basis = basis
self.dims = dims

self.faces = [
[0, 1, 3, 2],
[4, 5, 7, 6],
[0, 1, 5, 4],
[2, 3, 7, 6],
[0, 2, 6, 4],
[1, 3, 7, 5],
]

combinations = np.array(np.meshgrid([0, 1], [0, 1], [0, 1])).T.reshape(-1, 3)
scaled_combinations = combinations * dims

Expand All @@ -37,14 +46,6 @@ def __init__(self, origin, basis, dims):
move_vectors = unit_move_dirs * 0.0015
self.path_vertices = self.vertices + move_vectors

self.faces = [
[0, 1, 3, 2], # Bottom face
[4, 5, 7, 6], # Top face
[0, 1, 5, 4], # Front face
[2, 3, 7, 6], # Back face
[0, 2, 6, 4], # Left face
[1, 3, 7, 5], # Right face
]
self.quads = self.compute_quads()

def __repr__(self):
Expand Down Expand Up @@ -87,31 +88,31 @@ def paths(self, cam):
scene = Scene(
[
Rhombohedron(
origin=np.array([0.0, 0.0, 0.0]),
origin=np.array([0.0, 0.0, 0.2]),
basis=np.array(
[
[0.9, 0.5, 0.0],
[0.45, 0.2, -0.3],
[-0.3, 1.0, 0.0],
[-0.5, 0.25, -0.7],
[-0.5, 0.0, -0.2],
]
),
dims=np.array([1.0, 1.0, 1.0]),
dims=np.array([2.0, 0.5, 1.0]),
),
Rhombohedron(
origin=np.array([2.0, 0.0, -2.0]),
origin=np.array([1.0, 0.0, -2.0]),
basis=np.array(
[
[-0.9, 0.5, 0.0],
[0.3, 1.0, 0.5],
[1.5, 0.25, -0.7],
]
),
dims=np.array([1.0, 1.0, 1.0]),
dims=np.array([1.0, 1.0, 0.8]),
),
]
)

eye = np.array([0, 0.4, 5])
eye = np.array([0, -0.5, 5])
focus = np.array([0, 0.4, 0])
up = np.array([0, 1, 0])

Expand Down
2 changes: 1 addition & 1 deletion pyraydeon/examples/py_rhombohedron_expected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions raydeon/src/shapes/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ impl Quad {
}

pub fn tagged(origin: WPoint3, mut basis: [WVec3; 2], dims: [f64; 2], tag: usize) -> Quad {
basis[0] = basis[0].normalize();
basis[1] = basis[1].normalize();
let verts = [
origin,
origin + basis[0] * dims[0],
origin + basis[0] * dims[0] + basis[1] * dims[1],
origin + basis[1] * dims[1],
];
basis[0] = basis[0].normalize();
basis[1] = basis[1].normalize();
Quad {
origin,
basis,
Expand All @@ -42,7 +42,7 @@ impl Shape<WorldSpace> for Quad {
fn collision_geometry(&self) -> Option<Vec<std::sync::Arc<dyn CollisionGeometry<WorldSpace>>>> {
Some(vec![
Arc::new(Triangle::new(self.verts[0], self.verts[1], self.verts[3])),
Arc::new(Triangle::new(self.verts[2], self.verts[3], self.verts[1])),
Arc::new(Triangle::new(self.verts[1], self.verts[2], self.verts[3])),
])
}

Expand Down

0 comments on commit 0582a1a

Please sign in to comment.