Hi

I have a height map which is being plotted from -1 to + 1 in the X direction, -1 to + 1 in Y and -1 to +1 in Z.

The height map is composed of many triangles. I want to zoom in the X direction so that I zoom into the details of the height map. I have no problems doing so as well as “panning” the map across the screen using the model matrix.

However, once I zoom in, then the surface becomes much wider than -1 to 1. How do I restrict the drawing to this limit? I would still need to rotate everything.

Thanks

Can you elaborate a bit please ?

Hi

The surface is a 3d graph. The depth is time, y is signal strength and x is frequency. There are about 400, 000 triangles updated in real time. I want to zoom in the x axis only. To zoom I use a scale matrix and to pan once zoomed in I use a translation matrix. All of this works fine. However once I zoom the graph extendsp beyond the boundaries of the graph I. Even. -1 and +1.

I tried a couple of things such as sizzles but they do not work in 3d. I must be able to rotate the object .

Tom

have you thought about zooming in via the “projection” matrix ??

```
float FieldOfView = glm::radians(45.0f);
float AspectRatio = 4.0f / 3.0f;
float ZNear = 0.1f, ZFar = 100.0f;
glm::mat4 projection = glm::perspective(FieldOfView, AspectRatio, ZNear, ZFar);
```

if you modify the “FieldOfView”, you can zoom in/out, too

[QUOTE=tomb18;1285640]Hi

However, once I zoom in, then the surface becomes much wider than -1 to 1. How do I restrict the drawing to this limit? I would still need to rotate everything.

Thanks[/QUOTE]

you are scaling up of course it became wider… scale mean multiply the current size by a scalar number. to zoom use the filed of view or just translate the camera in the direction of the mouse

I think I now understand what you mean.

Few things you can try:

Use clip-planes to simply cut what is out of your boundaries

Use a geometry shader and don’t produce any vertices if they are out of boundaries (or truncate them so that they align with the boundaries)

I would go for the first one personally

Hi,

I just tried that. This is my vertex shader now ( the GL enable on the clipping is done):

```
public static string VertexShader = @"
#version 130
in vec3 vertexPosition;
out vec2 textureCoordinate;
uniform mat4 projection_matrix;
uniform mat4 view_matrix;
uniform mat4 model_matrix;
uniform vec4 u_plane0 = vec4(1,0,0,1.2);
uniform vec4 u_plane1 = vec4(-1,0,0,1.2);
void main(void)
{
textureCoordinate = vertexPosition.xy;
gl_ClipDistance[0] = dot(u_plane0, vec4(vertexPosition,1));
gl_ClipDistance[1] = dot(u_plane1, vec4(vertexPosition,1));
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(vertexPosition, 1);
}
";
```

Now, this works if the scale is 1. The minute I zoom by applying scaling, the u_pane0 and u_plane1 both get scaled as well. So they do clip but no longer as written. Everything gets scaled. I tried GL.Enable(normalize) to and it does nothing.

Thanks

However once I zoom the graph extendsp beyond the boundaries of the graph I.

??? Don’t know what this means ???

… such as sizzles, …

Do you mean glScissor?

It would help if you posted a picture pointing out what you don’t like and what you want.

Have a feeling it’s pretty easy to do what you want.

Go to postimg.org to post a picture.

Hi, there’s a link to a picture above in post number 6.

glSizzor will not work. I need to rotate the model. In the above picture I do not want the graph to extend beyond the axis you see there. As I apply a scale the data in the x axis expands and contracts.

Tom

Hi,

I solved it. Using the glClip_Distance in the shader and a defined clip_distance as above is not the way to do it. The issue is if you use a scale transformation it scales the clip_distance as well. Thus is does clip but not where you want it. So the solution is to pass in the clip distance from the CPU but prior to doing this you scale it first.

So in your C program you define a vector4 which is your clipping distance

```
Vector4 clip1 = new Vector4(-1, 0, 0, 1.0f / scale);
Vector4 clip2 = new Vector4(1, 0, 0, 1.0f / scale);
plottingProgram["model_matrix"].SetValue(Matrix4.CreateScaling(new Vector3(scale, 1, 1)) * Matrix4.CreateTranslation(new Vector3(0,0,0)) *Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
plottingProgram["u_plane0"].SetValue(clip1);
plottingProgram["u_plane1"].SetValue(clip2);
```

and then in the shader you have the following

```
public static string VertexShader = @"
#version 130
in vec3 vertexPosition;
out vec2 textureCoordinate;
uniform mat4 projection_matrix;
uniform mat4 view_matrix;
uniform mat4 model_matrix;
uniform vec4 u_plane0;
uniform vec4 u_plane1;
void main(void)
{
textureCoordinate = vertexPosition.xy;
gl_ClipDistance[0] = dot(vec4(vertexPosition,1), u_plane0);
gl_ClipDistance[1] = dot(vec4(vertexPosition,1), u_plane1);
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(vertexPosition, 1);
}
";
```

… there’s a link to a picture above in post number 6.

Sorry. Didn’t see that.

I think I understand what you want. It can be done easily using arbitrary clipping planes.

See the documentation on glClipPlane. To me it’s unintuitive, but it works.

In the example below, the ellipsoid is clipped at x = 1 and x = -1.

When I rotate the view, the clipping planes rotate with the objects.

This is because of where they are defined in the code.

Note that I explicitly enable and disable the clipping planes just before and after the ellipsoid is drawn.

This is done so that the clipping planes don’t affect anything else in the scene, such as the axes.

Try getting one clipping plane to work. Play with the numbers in the clip vectors to get a feel for it.

[ATTACH=CONFIG]1434[/ATTACH]

```
void Carmine_Spheres (void)
{
static int first = 1;
static double xneg[4] = {1.0, 0.0, 0.0, 1.0}, xpos[4] = {-1.0, 0.0, 0.0, 1.0};
static GLUquadricObj *ORN;
if (first) {
first = 0;
ORN = gluNewQuadric();
}
glEnable (GL_LIGHTING);
glEnable (GL_CLIP_PLANE0);
glEnable (GL_CLIP_PLANE1);
glClipPlane (GL_CLIP_PLANE0, xneg);
glClipPlane (GL_CLIP_PLANE1, xpos);
glColor3f (0.80, 0.40, 0.20);
glPushMatrix ();
glScalef (3.0, 0.5, 1.0);
gluSphere (ORN, 0.7, 36, 18);
glPopMatrix ();
glDisable (GL_CLIP_PLANE0);
glDisable (GL_CLIP_PLANE1);
}
```

Hi I think you missed the other answer too lol. It was on the next page so easy to do.

I gave the solution as you did but in modern opengl.

The only thing that kept me puzzled was that it didn’t seem to work but in fact it did. I was scaling and transforming the vertices but the vertex shader automatically also scales and transforms the clipping distance too. So the solution is simple…once you know.

Clipping Plane0 =Vector3 (-1,0,0,(distance-transform)/scale))

That solves that issue.

Tom

Hi You missed my message above.

The clipping distance scales with any scaling transformation so you need to do the inverse I. E.

Clipping distance = Vector4 ( 1,0,0,(distance-transform)/scale))

That solves it.

Tom