Near & far parameter in glfrustum-glperspective c++

Hello,
I develop an application of computer graphics based on OpenGL and Glut. He then asked to develop the application in order to comply with the following request:

“The student is required to make a general application that is able to accommodate the size of the dataset to be displayed appropriately parameterizing the volume of view.”

I tried using the commands glFrustum AND gluPerspective but without being able to parameterize the values ​​near and far to these commands. How do I set the zoom so that it filled the entire window?

If anyone can 'give me some advice (even with some additional information on the project) would be very grateful to him.

The best advice is to read Chapter 3 - OpenGL Programming Guide

1 Like

Thank You for the answer.
I read more documents but i don’t understand what is the method for resolve my problem.can you help me?

could help me the function:

"
The Transformed Depth Coordinate

The depth (z) coordinate is encoded during the viewport transformation (and later stored in the depth buffer). You can scale z values to lie within a desired range with the glDepthRange() command. (Chapter 10 discusses the depth buffer and the corresponding uses for the depth coordinate.) Unlike x and y window coordinates, z window coordinates are treated by OpenGL as though they always range from 0.0 to 1.0.

void glDepthRange(GLclampd near, GLclampd far);
Defines an encoding for z coordinates that’s performed during the viewport transformation. The near and far values represent adjustments to the minimum and maximum values that can be stored in the depth buffer. By default, they’re 0.0 and 1.0, respectively, which work for most applications. These parameters are clamped to lie within [0,1].

In perspective projection, the transformed depth coordinate (like the x and y coordinates) is subject to perspective division by the w coordinate. As the transformed depth coordinate moves farther away from the near clipping plane, its location becomes increasingly less precise. (See Figure 3-18.) "

?

the problem that i have is how fix the values of near & far in GLFRUSTUM

You haven’t really told us what you’re specific question is. You just said you have this homework problem and you don’t know what to do. It sounds like the point of the exercise is for you to learn how the planes comprising the view frustum are calculated, and then use your math skills to figure out how to fit those planes to the objects in your scene.

Beside Chapter 3, see this for a summary:

[QUOTE=Dark Photon;1241398]You haven’t really told us what you’re specific question is. You just said you have this homework problem and you don’t know what to do. It sounds like the point of the exercise is for you to learn how the planes comprising the view frustum are calculated, and then use your math skills to figure out how to fit those planes to the objects in your scene.

Beside Chapter 3, see this for a summary:

i don’t know what is the method for automatically parametrize the parameter near e far.
my project must be available with all the dataset that i pass to the project…
the dataset could be 10x10x10, 100x100x100 etc…
the project must automatically adapt the visualization to the dataset

[QUOTE=Agata_;1241443]i don’t know what is the method for automatically parametrize the parameter near e far.
my project must be available with all the dataset that i pass to the project…
the dataset could be 10x10x10, 100x100x100 etc…
the project must automatically adapt the visualization to the dataset[/QUOTE]

Anyone help me please…i’m blocked

Picture what you’re trying to do, and then it becomes much simpler.

Where can the object be in EYE-SPACE? How big is it in EYE-SPACE? That tells you the volume of space you need to make sure you have in your view frustum, right?

Think about how you can use the makeFrustum() function on the Song Ho Ann page I mentioned (this is essentially gluPerspective). How can you compute those parameters? Write a formula in terms of the size of the object.

[QUOTE=Dark Photon;1241542]Picture what you’re trying to do, and then it becomes much simpler.

Where can the object be in EYE-SPACE? How big is it in EYE-SPACE? That tells you the volume of space you need to make sure you have in your view frustum, right?

Think about how you can use the makeFrustum() function on the Song Ho Ann page I mentioned (this is essentially gluPerspective). How can you compute those parameters? Write a formula in terms of the size of the object.[/QUOTE]

I have a project that must set the cam automatically for adapting to only dataset that i fix.
I think that the problem was how define the parameter of glPerspective or glFrustum, in particular the parameter “near” and “far”. Is it right?
I have searched on the web, on forum and on books but i haven’t find a solution for my problem.
I also read * OpenGL Transformation (Song Ho Ahn)…could you help me to resolve my problem?if i don’t resolve that, i can’t go to next request of the project.
If you want, i could send you information and documentation by mail.

the function MAKEFRUSTUM is

void makeFrustum(double fovY, double aspectRatio, double front, double back)
{
const double DEG2RAD = 3.14159265 / 180;

double tangent = tan(fovY/2 * DEG2RAD);   // tangent of half fovY
double height = front * tangent;          // half height of near plane
double width = height * aspectRatio;      // half width of near plane

// params: left, right, bottom, top, near, far
glFrustum(-width, width, -height, height, front, back);

}

the parameter FRONT & BACK are the same of NEAR & FAR? I use glFrustum and i center my object with these parameters:

glFrustum(heightMap->minX-heightMap->xcenter, heightMap->maxX-heightMap->xcenter, heightMap->minY-heightMap->ycenter, heightMap->maxY-heightMap->ycenter, heightMap->near, heightMap->far);

minX=0.0;
maxX=nrowscellsize;
minY=0.0;
maxY=ncols
cellsize;
far = 500;
near = 100;
xcenter = (minX + maxX)/2;
ycenter = (minY + maxY)/2;
zcenter = (far+near)/2;

as you could watch, i fix the parameter near & far manually…but the project expressly ask that the camera’sparameters must set automatically.
Help me please.
Thanks

[QUOTE=Agata_;1241548]…


void makeFrustum(double fovY, double aspectRatio, double front, double back)
{
...
glFrustum(-width, width, -height, height, front, back);
}

the parameter FRONT & BACK are the same of NEAR & FAR?[/QUOTE]

Yes, you can see that from the code. glFrustum’s 5th and 6th parms are near and far (click for man page). The man page also describes clearly what region on the near clip plane the glFrustum parameters correspond to.

as you could watch, i fix the parameter near & far manually…but the project expressly ask that the camera’sparameters must set automatically. Help me please.

Since this is a homework problem, I shouldn’t get into the details of helping you solve it. I’d talk to your instructor and get some guidance.

BTW, does the assignment require you to use perspective? If not, consider orthographic. It’s a little simpler to think about. In fact, since you’re having trouble, I’d just use glOrtho first regardless. Then think about what (if anything) you need to change for perspective.

BTW, does the assignment require you to use perspective? If not, consider orthographic. It’s a little simpler to think about. In fact, since you’re having trouble, I’d just use glOrtho first regardless. Then think about what (if anything) you need to change for perspective.

I ask to the instructor information about the parameterization of the camera and he told me that i must automatically fix the parameter of gluPerspective for adapting the project to all the dataset that i pass to the project.

Since this is a homework problem, I shouldn’t get into the details of helping you solve it. I’d talk to your instructor and get some guidance.

Yes this is an homework problem but i cannot resolve it. The material that the instructor gave us don’t resolve the problem.

My question is the follow: how can i parametrize near and far?i’m working to this problem from 15 days but i don’t resolve it and i cannot go to next step. Please help me. can i send you the project and the project requests for mail?can we speak on skype?
Please help me, i’m working all the summer for this project

See questions 5 and 7 in the Forum Posting Guidelines.

And on 5, you need to give it the old college try. You need to do most of the work. Post the details describing what you have tried and why you think those don’t work.

The problem isn’t hard – you want to enclose your dataset with 6 planes (the planes defining the view frustum). And you need to become intimately familiar with how those planes are defined. Again, see the projection documentation mentioned. It’s very clear about this. And again, use ortho first – it’s easy!

[QUOTE=Dark Photon;1241662]See questions 5 and 7 in the Forum Posting Guidelines.

And on 5, you need to give it the old college try. You need to do most of the work. Post the details describing what you have tried and why you think those don’t work.

The problem isn’t hard – you want to enclose your dataset with 6 planes (the planes defining the view frustum). And you need to become intimately familiar with how those planes are defined. Again, see the projection documentation mentioned. It’s very clear about this. And again, use ortho first – it’s easy![/QUOTE]

ok, i describe my problems…
the request of the teacher is the follows:

“The student is required to achieve a general application that is able to adapt to the size of the dataset to be displayed appropriately parameterizing the volume of view.”
the teacher told me to use gluPerspective and NOT glOrtho and glFrustum.
my gluPerspective is this:

gluPerspective(60.0,                  //The camera angle
                   (double)width / (double)height, //The width-to-height ratio
                   200.0,                   //The near z clipping coordinate
                   500.0);                //The far z clipping coordinate

in main.cpp i fix the follow parameter:


float xpos = heightMap->xcenter;
float ypos = heightMap->ycenter;
float zpos = heightMap->zcenter;

and my display function is this:


void display (void)
{

	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	 glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
	 glLoadIdentity();
	 light();
	 glTranslatef(-(xpos), (ypos), -(zpos)) ;
	 glRotatef(-cameraAngle, 1.0f, 0.0f, 0.0f); //Rotate the camera
	 glColor4f(0, 1, 0, 1);
	 //renderPrimitive(); // Render the primitive
	 //glCallList(DLid);
	 //glRotatef(angle, 1.0f, 0.0f, 0.0f); //togliere i commenti se si vuole far ruotare l'immagine in automatico
	 heightMap->Render();
	 glutSwapBuffers();
	 glFlush(); // Flush the OpenGL buffers to the window

}


for adapting to the size of the dataset i think that i can’t fix manually parameter near & far of gluPerspective but these parameters must be calculated automatically, isn’t right?if this is correct, i would know how automatically calculate near & far.

Thanks for your answer

[QUOTE=Agata_;1241685]…the request of the teacher is the follows:

…near & far of gluPerspective but these parameters must be calculated automatically, isn’t right?if this is correct, i would know how automatically calculate near & far.[/QUOTE]
Yes, per your instructor, that’s explicitly what you are supposed to figure out. That along with the other gluPerspective parameters.

ok but can you help me for this problem?