- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there!
I'm trying to create and setup some 3D camera views but can't seem to solve one part of the code. I've created the perspective view and setup the proper direction.
Now I need to resize the view's cropbox to properly fit an element. I've tried a LOT of ways of achieving this, the closest I got looks like this:
//
//view has been already created and adjusted the direction before
//
XYZ cropBoxMin = new XYZ();
XYZ cropBoxMax = new XYZ();
//calculate the opposite angle of the triangle to help generate the 'cone' like view
double horizCO = 1 * Math.Tan(horizAngle);
double vertCO = 1 * Math.Tan(vertAngle);
//set initial point
cropBoxMax = pStartOffseted;
cropBoxMin = pStartOffseted;
//offset points to know directions and distance using 3d view coordinate
cropBoxMax += horizCO * XYZ.BasisX;
cropBoxMax += vertCO * XYZ.BasisY;
cropBoxMax += 1 * XYZ.BasisZ;
cropBoxMin -= horizCO * XYZ.BasisX;
cropBoxMin -= vertCO * XYZ.BasisY;
cropBoxMin -= 2 * XYZ.BasisZ;
//create bounding box and apply max and min
BoundingBoxXYZ bb = new BoundingBoxXYZ();
bb.Max = cropBoxMax;
bb.Min = cropBoxMin;
//create transform from view and apply inverse to bb min and max
Transform tInv = view3d.CropBox.Transform.Inverse;
bb.Max = tInv.OfPoint(bb.Max);
bb.Min = tInv.OfPoint(bb.Min);
//apply transformed bb to view.cropbox
view3d.CropBox = bb;
The view either gets weird, looking somewhere random, or an exception gets thrown in saying "box is empty".
I'd reaaally appreciate any thoughts and advises!
Thanks!
Solved! Go to Solution.