private double[] putInComponentSpace(ReflectionPoint rp, Component2 component) { // TODO : debug!! MathTransform invertMainBodyXForm = component.Transform2.Inverse(); return(rp.location.IMultiplyTransform(invertMainBodyXForm).ArrayData); }
private void createMirrorExtrusion(ReflectionPoint reflectionPoint) { RayTracer.startSketch(); RayTracer.visualizePoint(reflectionPoint.location); /*swDoc.SketchManager.CreateCenterRectangle(reflectionPoint.xyz[0], reflectionPoint.xyz[1], reflectionPoint.xyz[2], * reflectionPoint.xyz[0] + (inchesToMeters(1) * (1 - reflectionPoint.nxnynz[0])), * reflectionPoint.xyz[1] + (inchesToMeters(1) * (1 - reflectionPoint.nxnynz[1])), * reflectionPoint.xyz[2] + (inchesToMeters(1) * (1 - reflectionPoint.nxnynz[2])));*/ RayTracer.finishSketch("place mirror for " + reflectionPoint.component.Name2); return; /* * double mirrorWidth = inchesToMeters(1); * double[] pointLocation = putInMainBodySpace(reflectionPoint); * * double[] surfaceNormal = reflectionPoint.nxnynz; * * // select the main body, because that is what we want to draw on * mainBody.Select(false); * int status = 0; * swAssembly.EditPart2(true, false, ref status); * swSelectionMgr.SetSelectionPoint2(1, -1, pointLocation[0], pointLocation[1], pointLocation[2]); * swSketchMgr.AddToDB = true; * swSketchMgr.InsertSketch(true); * * swSketchMgr.CreateCenterRectangle(pointLocation[0], pointLocation[1], pointLocation[2], * pointLocation[0] + .5 * mirrorWidth * (1 - surfaceNormal[0]), * pointLocation[1] + .5 * mirrorWidth * (1 - surfaceNormal[1]), * pointLocation[2] + .5 * mirrorWidth * (1 - surfaceNormal[2])); * * swSketchMgr.AddToDB = false; * * swFeatureMgr.FeatureExtrusion2(true, false, false, * 0, 0, 0.00254, 0.00254, * false, false, false, false, * 0, 0, * false, false, false, false, true, true, true, * 0, 0, * false); * * * if(generatedMirrorExtrusions == null) { * generatedMirrorExtrusions = new List<IFeature>(); * } * generatedMirrorExtrusions.Add(swSelectionMgr.GetSelectedObject6(1, -1) as IFeature); * * swDoc.ClearSelection2(true); * swAssembly.EditAssembly();*/ }
private bool placeMirror(Component2 swComponent) { // intutively, what we want to do: // look to see if any camera rays hit the object as-is, then no worries // if not, look to see if any camera rays reflecting off the main body hit the object // if yes, put a mirror in that spot // if no, we fail and cry if (!Simulator.reflectRaysOverRangeOfMotion(swComponent)) { return(false); } // TODO : ideally we would collect all the points that we reflect // from and make a mirror that shows all of them ReflectionPoint rp = RayTracer.reflectedRayCanSeeComponent(swComponent); createMirrorExtrusion(rp); return(true); }
public static ReflectionPoint reflectedRayCanSeeComponent(Component2 component) { List <IBody2> bodies = new List <IBody2>(); object vBodyInfo; object[] componentBodies = (object[])mainBody.GetBodies3((int)swBodyType_e.swSolidBody, out vBodyInfo); for (int i = 0; i < componentBodies.Length; i++) { IBody2 tempBody = ((Body2)componentBodies[i]).ICopy(); tempBody.ApplyTransform(mainBody.Transform2); bodies.Add(tempBody); } double[] rayOrigins = camera.rayVectorOrigins(); double[] rayDirections = camera.rayVectorDirections(); int numIntersectionsFound = (int)swDoc.RayIntersections((object)bodies.ToArray(), (object)rayOrigins, (object)rayDirections, (int)(swRayPtsOpts_e.swRayPtsOptsTOPOLS | swRayPtsOpts_e.swRayPtsOptsNORMALS | swRayPtsOpts_e.swRayPtsOptsENTRY_EXIT), (double).0000001, (double).0000001); double[] horrifyingReturn = (double[])swDoc.GetRayIntersectionsPoints(); if (numIntersectionsFound == 0) { return(null); } int lengthOfOneReturn = 9; ReflectionPoint reflectionWorksAt = null; if (visualize) { startSketch(); } for (int i = 0; i < numIntersectionsFound; i++) { byte intersectionType = (byte)horrifyingReturn[i * lengthOfOneReturn + 2]; if ((intersectionType & (byte)swRayPtsResults_e.swRayPtsResultsENTER) == 0) { // we need it to be just entry rays continue; } int rayIndex = (int)horrifyingReturn[i * lengthOfOneReturn + 1]; double x = horrifyingReturn[i * lengthOfOneReturn + 3]; double y = horrifyingReturn[i * lengthOfOneReturn + 4]; double z = horrifyingReturn[i * lengthOfOneReturn + 5]; double nx = horrifyingReturn[i * lengthOfOneReturn + 6]; double ny = horrifyingReturn[i * lengthOfOneReturn + 7]; double nz = horrifyingReturn[i * lengthOfOneReturn + 8]; ReflectionPoint rp = new ReflectionPoint(mathUtils, new double[] { x, y, z }, new double[] { nx, ny, nz }, component); double[] reflectionDir = camera.calculateReflectionDir(camera.rayVectors().ElementAt(rayIndex).ArrayData, rp.nxnynz); MathVector reflectedRay = mathUtils.CreateVector(reflectionDir); if (rayHitsComponent(component, rp.location, reflectedRay)) { swDoc.SketchManager.CreatePoint(x, y, z); if (visualize) { visualizeRay(camera.centreOfVision, mathUtils.CreateVector(new double[] { rayDirections[rayIndex * 3], rayDirections[rayIndex * 3 + 1], rayDirections[rayIndex * 3 + 2] })); visualizeRay(rp.location, reflectedRay); } reflectionWorksAt = rp; } } if (visualize) { finishSketch("reflections for " + component.Name2); } return(reflectionWorksAt); }