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

- 141K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 92 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 744 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 210 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 628 Off topic board
- 216 Mobile & Wireless
- 88 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 942 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 269 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 5 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 308 WEB Servers
- 151 WEB-Services / SOAP

JamesFos
Member Posts: **240**

in 3D Graphics

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?

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?

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

642: 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?

:

2402. 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?

642: 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.

240When/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?

5Both 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!