Tessalator Posted May 23, 2021 Share Posted May 23, 2021 I'm having problems figuring this out. I have a "scanner" node that sweeps an arc for intersections, returns to its start, and repeats. I'm attaching it to a rotating node. It seems to not act in local space. I've attached another node that works. Code: Spoiler public class Rotator : NodeDummy { private float scan = 30; private float turnSpeed = 30f; private float range = 10; private int mask = 1; private readonly ObjectMeshDynamic center = Primitives.CreateBox(vec3.ONE * .6f); private readonly ObjectMeshDynamic outer = Primitives.CreateBox(vec3.ONE * .4f); public readonly Node beam = new NodeDummy(); public Rotator() { AddChild(center); // Object for self outer.Translate(0, .5f, 0); //To Show Front AddChild(outer); beam.Translate(0, 0, .1f); // Off Ground AddChild(beam); } public void Update() { TurnSelf(); TurnBeam(); if(!Ping(out var detect)) { return; } Console.WriteLine($"Detected: {detect!.Name}"); /* ********** Locals ********** */ void TurnSelf() { Rotate(0, 0, 10 * IFps); } void TurnBeam() { beam.Rotate(0.0f, 0.0f, turnSpeed * IFps); var bang = beam.GetRotation().GetAngle(vec3.UP); if(bang > scan / 2) { beam.Rotate(new quat(vec3.UP, -scan)); } } bool Ping(out Unigine.Object? detected) { vec3 firstPoint = beam.Position; vec3 secondPoint = firstPoint + beam.GetDirection(AXIS.Y) * range; detected = World.GetIntersection(firstPoint, secondPoint, mask); Visualizer.RenderLine3D(firstPoint, secondPoint, vec4.BLUE); return detected is not null; } } } I'm attaching both in the same way and I think I'm doing the "scan" movement all in local space, but the "outer" node turns with the parent and the "beam" doesn't. Link to comment
cash-metall Posted May 24, 2021 Share Posted May 24, 2021 intersection and visualizer work in world coordinates if beam is a child node, then the error is somewhere here vec3 firstPoint = beam.WorldPosition; //beam.Position; vec3 secondPoint = firstPoint + beam.GetWorldDirection(AXIS.Y) * range; //beam.GetDirection(AXIS.Y) * range; detected = World.GetIntersection(firstPoint, secondPoint, mask); Visualizer.RenderLine3D(firstPoint, secondPoint, vec4.BLUE); the result will also be in world coordinates. to convert world to beam local vec3 local_point = beam.GetIWorldTransform() * world_point; 1 Link to comment
Tessalator Posted May 24, 2021 Author Share Posted May 24, 2021 (edited) That was it cash-metall. Thanks. I used `ToWorld`. //Local (Object?, vec3) PingWorld() { var start = ToWorld(firstPoint); var end = ToWorld(secondPoint); Object? intersection = World.GetIntersection(start, end, mask); vec3 position = intersection is null ? : vec3.ZERO : ToLocal(intersection.Position); } Visualizer.RenderLine3D(start, end, vec4.BLUE); return (intersection, position); } Edited May 24, 2021 by Tessalator Link to comment
Recommended Posts