-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new transform3d partial updates snippet for all languages
- Loading branch information
Showing
6 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
docs/snippets/all/archetypes/transform3d_partial_updates.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Log different transforms with visualized coordinates axes. | ||
|
||
#include <cmath> | ||
#include <rerun.hpp> | ||
|
||
float truncated_radians(float deg) { | ||
return static_cast<float>(static_cast<int>(deg * M_PI / 180.0f * 1000.0f)) / 1000.0f; | ||
} | ||
|
||
int main() { | ||
const auto rec = rerun::RecordingStream("rerun_example_transform3d_axes"); | ||
rec.spawn().exit_on_failure(); | ||
|
||
auto step = 0; | ||
|
||
rec.set_time_sequence("step", step); | ||
rec.log( | ||
"box", | ||
rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid), | ||
rerun::Transform3D().with_axis_length(10.0) | ||
); | ||
|
||
for (int deg = 0; deg <= 45; deg++) { | ||
step++; | ||
rec.set_time_sequence("step", step); | ||
|
||
auto rad = truncated_radians(deg * 4); | ||
// TODO(cmc): update_fields | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_rotation_axis_angle( | ||
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad)) | ||
) | ||
); | ||
} | ||
|
||
for (int t = 0; t <= 45; t++) { | ||
step++; | ||
rec.set_time_sequence("step", step); | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f}) | ||
); | ||
} | ||
|
||
for (int deg = 0; deg <= 45; deg++) { | ||
step++; | ||
rec.set_time_sequence("step", step); | ||
|
||
auto rad = truncated_radians((deg + 45) * 4); | ||
// TODO(cmc): update_fields | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_rotation_axis_angle( | ||
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad)) | ||
) | ||
); | ||
} | ||
|
||
step++; | ||
rec.set_time_sequence("step", step); | ||
// TODO(cmc): clear_fields | ||
rec.log("box", rerun::Transform3D().with_axis_length(15.0)); | ||
} |
66 changes: 66 additions & 0 deletions
66
docs/snippets/all/archetypes/transform3d_partial_updates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Log different transforms with visualized coordinates axes.""" | ||
|
||
import math | ||
|
||
import rerun as rr | ||
|
||
|
||
def truncated_radians(deg: float) -> float: | ||
return float(int(math.radians(deg) * 1000.0)) / 1000.0 | ||
|
||
|
||
rr.init("rerun_example_transform3d_axes", spawn=True) | ||
|
||
step = 0 | ||
rr.set_time_sequence("step", step) | ||
|
||
rr.log( | ||
"box", | ||
rr.Boxes3D(half_sizes=[4.0, 2.0, 1.0], fill_mode=rr.components.FillMode.Solid), | ||
rr.Transform3D(axis_length=10), | ||
) | ||
|
||
for deg in range(46): | ||
step += 1 | ||
rr.set_time_sequence("step", step) | ||
|
||
rad = truncated_radians(deg * 4) | ||
# TODO(cmc): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D( | ||
# TODO(cmc): we should have access to all the fields of the extended constructor too. | ||
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad), | ||
), | ||
) | ||
|
||
for t in range(51): | ||
step += 1 | ||
rr.set_time_sequence("step", step) | ||
# TODO(cmc): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D(translation=[0, 0, t / 10.0]), | ||
) | ||
|
||
for deg in range(46): | ||
step += 1 | ||
rr.set_time_sequence("step", step) | ||
|
||
rad = truncated_radians((deg + 45) * 4) | ||
# TODO(cmc): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D( | ||
# TODO(cmc): we should have access to all the fields of the extended constructor too. | ||
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad), | ||
), | ||
) | ||
|
||
step += 1 | ||
rr.set_time_sequence("step", step) | ||
# TODO(cmc): update_fields(clear=True) | ||
rr.log( | ||
"box", | ||
rr.Transform3D(axis_length=15), | ||
) |
67 changes: 67 additions & 0 deletions
67
docs/snippets/all/archetypes/transform3d_partial_updates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! Log different transforms with visualized coordinates axes. | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let rec = rerun::RecordingStreamBuilder::new("rerun_example_transform3d_axes").spawn()?; | ||
|
||
let mut step = 0; | ||
|
||
rec.set_time_sequence("step", step); | ||
rec.log( | ||
"box", | ||
&[ | ||
&rerun::Boxes3D::from_half_sizes([(4.0, 2.0, 1.0)]) | ||
.with_fill_mode(rerun::FillMode::Solid) as &dyn rerun::AsComponents, | ||
&rerun::Transform3D::default().with_axis_length(10.0), | ||
], | ||
)?; | ||
|
||
for deg in 0..=45 { | ||
step += 1; | ||
rec.set_time_sequence("step", step); | ||
|
||
let rad = truncated_radians((deg * 4) as f32); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new( | ||
[0.0, 1.0, 0.0], | ||
rerun::Angle::from_radians(rad), | ||
)), | ||
)?; | ||
} | ||
|
||
for t in 0..=50 { | ||
step += 1; | ||
rec.set_time_sequence("step", step); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_translation([0.0, 0.0, t as f32 / 10.0]), | ||
)?; | ||
} | ||
|
||
for deg in 0..=45 { | ||
step += 1; | ||
rec.set_time_sequence("step", step); | ||
|
||
let rad = truncated_radians(((deg + 45) * 4) as f32); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new( | ||
[0.0, 1.0, 0.0], | ||
rerun::Angle::from_radians(rad), | ||
)), | ||
)?; | ||
} | ||
|
||
step += 1; | ||
rec.set_time_sequence("step", step); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::clear_fields().with_axis_length(15.0), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn truncated_radians(deg: f32) -> f32 { | ||
((deg.to_radians() * 1000.0) as i32) as f32 / 1000.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters