#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Constraints in 3D

Member Posts: 240
I have a hundred or more points and i need the camera to see them all.

I assume I need a way to find out the constraints of several points in space and then use the front face as the screen for the camera, ie...

[code]
struct typBox
{
double top;
double right;
double front;
double height;
double width;
double depth;
}

#typedef struct typBox glBox

glBox getContraints()
{
double xMax = point[0].x, xMin = point[0].x;
double yMax = point[0].y, yMin = point[0].y;
double zMax = point[0].z, zMin = point[0].z;
for(int i = 1; i < NUM_OF_POINTS; i++)
{
if( xMax < point[i].x ) xMax = point[i].x;
if( xMin > point[i].x ) xMin = point[i].x;
if( yMax < point[i].y ) yMax = point[i].y;
if( yMin > point[i].y ) yMin = point[i].y;
if( zMax < point[i].z ) zMax = point[i].z;
if( zMin > point[i].z ) zMin = point[i].z;
}
glBox b;
b.top = yMax;
b.right = xMax;
b.front = zMax;
b.height = yMax - yMin;
b.width = xMax - xMin;
b.depth = zMax - zMin;

return b;
}
[/code]

But you get the idea...

What i need, however, it to specify 2 vectors, up and forward.

(this is not a very good description but here goes)
The box returned will have 4 edges parallel with forward 4 edges parallel with up and 4 edges perpendicular to the plane (up, forward).

I hope you understand.

This changes the defenition of a box and the simple ...

if( xMax < point[i].x )

... much more complicated.

[question]
I'm using OpenGL and i need a fast method of doing this. Can anyone suggest something?
[/question]

TIA

James

----------------

What does God need with a starship?

## Comments

• Member Posts: 642
Well if you have a lot of vertices and need a fast method of drawing, you could try using vertex arrays or display lists. The rest of the part - not really sure what exactly you want to do. Do you want to move a box based on some constraints - something on terms of constraint based modelling or just want to speed up the drawing of the box ??

: I have a hundred or more points and i need the camera to see them all.
:
: I assume I need a way to find out the constraints of several points in space and then use the front face as the screen for the camera, ie...
:
: [code]
: struct typBox
: {
: double top;
: double right;
: double front;
: double height;
: double width;
: double depth;
: }
:
: #typedef struct typBox glBox
:
: glBox getContraints()
: {
: double xMax = point[0].x, xMin = point[0].x;
: double yMax = point[0].y, yMin = point[0].y;
: double zMax = point[0].z, zMin = point[0].z;
: for(int i = 1; i < NUM_OF_POINTS; i++)
: {
: if( xMax < point[i].x ) xMax = point[i].x;
: if( xMin > point[i].x ) xMin = point[i].x;
: if( yMax < point[i].y ) yMax = point[i].y;
: if( yMin > point[i].y ) yMin = point[i].y;
: if( zMax < point[i].z ) zMax = point[i].z;
: if( zMin > point[i].z ) zMin = point[i].z;
: }
: glBox b;
: b.top = yMax;
: b.right = xMax;
: b.front = zMax;
: b.height = yMax - yMin;
: b.width = xMax - xMin;
: b.depth = zMax - zMin;
:
: return b;
: }
: [/code]
:
: But you get the idea...
:
: What i need, however, it to specify 2 vectors, up and forward.
:
: (this is not a very good description but here goes)
: The box returned will have 4 edges parallel with forward 4 edges parallel with up and 4 edges perpendicular to the plane (up, forward).
:
: I hope you understand.
:
: This changes the defenition of a box and the simple ...
:
: if( xMax < point[i].x )
:
: ... much more complicated.
:
: [question]
: I'm using OpenGL and i need a fast method of doing this. Can anyone suggest something?
: [/question]
:
: TIA
:
: James
:
:
:
: ----------------
:
: What does God need with a starship?
:

• Member Posts: 240
1. I have a large array of points.

2. The camera is in an arbirary position looking at the center of all the points.

3. The camera can either be too close or too far away.

Primary Objective: I need to find out the distance away from the LookAt point that the camera needs to be to have all the points within the view.

I first thought that it would be easy determine the left-, right-, top-, bottom-, front-, and back-most points using the coordinate system relative to the camera. And then use this information to workout where to place the camera to fit everything on the viewing plane.

The only problem is I don't know how to get the (x, y, z) of the points from the true coordinate system into the cameras coordinate system.

I tried to redefine the problem as before to make it more mathematical. But this is what i need to acomplish.

Any help is apreciated.

James

----------------

What does God need with a starship?

• Member Posts: 642
[b][red]This message was edited by the gautam at 2002-4-19 10:53:33[/red][/b][hr]

: 1. I have a large array of points.
:
: 2. The camera is in an arbirary position looking at the center of all the points.
:
: 3. The camera can either be too close or too far away.

This method probably looks easier - from the book - Considering we are in perspective mode calculate the center of frustum based on camera position and orientation and then find the distance between this point and the model. This is what he does for eliminating the models to be rendered on scene. I suppose we could modify this a little and move the models into the scene if the model falls outside the view.

I don't do a lot of 3d except for trying to figure out some effects and trying to code simple 2d games in perspective mode so I might not be able to answer a lot of these questions. However I'll see what I can dig up on these.

• Member Posts: 240
much apreciated.

When/If you find the information, the source would be useful (book name/isbn, web address... ).

Thanks for your time.

James

----------------

What does God need with a starship?

• Member Posts: 5
unfortunately, i am not familiar enough with OpenGL to answer your question very specifically. However, knowing that OpenGL and DirectX have some stuff in common, i will try to give you an idea of how you might be able to deal with your problem.
Both APIs use a coordinate system that has X as the horizontal axis, Y as the vertical one and Z as the axis that is perpendicular to the screen plane (XY).
I assume that you know the coordinates of your points. In this case, it's easy to draw (on paper, or even your brain!) a bounding box that is the smallest possible one to contain all your points. At this point, it might be useful (i do that a lot, although it IS amateurish) to translate your points so that the center of the bounding box will lie to point (0,0,0) - this makes life easier in a number of ways.
So now all you need is to make sure the (imaginary) bounding box is visible on the screen. If it is, then all your points are visible too.
Here you need to do the work, as i can't guide you with OpenGL. With directX though, when setting the camera you do a couple of things: you define the camera point, the lookAt point, and some other parameters such as the up-direction vector, the viewing field angle, and the horizontal/vertical aspect ratio. The viewing angle field is really important, as it will basically do the job for you- it's just basic trig!
Let's say you did the aforementioned translation, so it makes sense that the lookAt point is (0,0,0), the center of the bounding box. So you're looking for the camera point really. Actually, you might even be looking for just a distance: if you want to look at the "center" of your points from the front, then it doesn't hurt that you keep the X and Z coordinates of the camera point to 0 and 0 respectively too! So all you need is to define the Z coordinate of the camera point (distance). That's where trig & viewing angle field comes in. Say that you define a viewing angle field of a1 rad. So, if the "front side" of your bounding rect. is, let's say, x1 units, and its depth is z1 units, and d1 is the distance (Z coord.) you're looking for, then all you need is to make sure that tan(a1/2)>=((x1/2)/(d1-z1/2)). The same check goes for height y1 of the bounding box ( tan(a1/2)>=((y1/2)/(d1-z1/2)). I'm sure that if you put it to paper it will make sense. At least, it worked for me. Good luck!
• Member Posts: 0

_________ \ http://forcoder.org \ free video tutorials and ebooks about { Java, Objective-C, R, Assembly, C, C++, Visual Basic .NET, PHP, Swift, C#, PL/SQL, Delphi, Scratch, Python, JavaScript, Visual Basic, Perl, Ruby, MATLAB, Go Rust, Bash, Prolog, ABAP, ML, Hack, Julia, F#, LabVIEW, Apex, Scala, Transact-SQL, FoxPro, Logo, Lua, Awk, COBOL, Dart, Kotlin, Alice, VBScript, D, Fortran, SAS, Erlang, Scheme, Clojure, Lisp, Ada, Crystal } __

Sign In or Register to comment.