View3D cropbox

View3D cropbox

tiago_marafigo
Enthusiast Enthusiast
1,272 Views
2 Replies
Message 1 of 3

View3D cropbox

tiago_marafigo
Enthusiast
Enthusiast

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!

 

0 Likes
Accepted solutions (2)
1,273 Views
2 Replies
Replies (2)
Message 2 of 3

matthew_taylor
Advisor
Advisor
Accepted solution

Hi @tiago_marafigo,

You look to be adjusting the points each time instead of just using a component (x, y, or z) of that point if it is greater or lesser.

There is a good example of how to do it here:

http://thebuildingcoder.typepad.com/blog/2009/12/crop-3d-view-to-room.html


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 3

tiago_marafigo
Enthusiast
Enthusiast
Accepted solution

@matthew_taylor wrote:

Hi @tiago_marafigo,

You look to be adjusting the points each time instead of just using a component (x, y, or z) of that point if it is greater or lesser.

There is a good example of how to do it here:

http://thebuildingcoder.typepad.com/blog/2009/12/crop-3d-view-to-room.html


Hi @matthew_taylor, thank you for your input.

I had seen that link before, but decided to look at it again. It turns out that its logic is exactly what I need, just with some adjustments.

 

I used the same method to retrieve the element geometry and the corner points. I modified from there eliminating duplicated values and also a certain range of values that I knew I didn't need :

 

 

//create new list to add all X values
List<double> pX = new List<double>();
foreach (XYZ p in vertices)
{
double dd = p.X;
pX.Add(dd);
}

//remove duplicated values

List<double> uniqueX = pX.Distinct().ToList();
uniqueX.Sort();

//create new list to add values within known range

List<double> xInRange = new List<double>();
foreach (double d in uniqueX)
{
if (d > -1 && d < 1)
xInRange.Add(d);
}

//do something with it

 

It might be a bit of an abomination in terms of organization and efficiency, but it works. Thanks!

0 Likes