View Full Version : How to limit display of an object in one dimension?

tomb18

01-23-2017, 04:31 PM

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

Silence

01-23-2017, 11:08 PM

once I zoom in, then the surface becomes much wider than -1 to 1. How do I restrict the drawing to this limit?

Can you elaborate a bit please ?

tomb18

01-24-2017, 07:53 AM

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

john_connor

01-24-2017, 08:10 AM

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.

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

Hellice

01-24-2017, 08:30 AM

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

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

tomb18

01-24-2017, 08:31 AM

I don't think that would work. Here is a picture. The graph must be restricted to the -1 to +1

http://va2fsq.com/wp-content/uploads/graph.jpg

Silence

01-24-2017, 10:30 AM

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

tomb18

01-24-2017, 11:14 AM

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

Carmine

01-24-2017, 12:39 PM

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.

tomb18

01-24-2017, 12:47 PM

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

tomb18

01-24-2017, 02:21 PM

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);

}

";

Carmine

01-25-2017, 03:35 PM

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

2329

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);

}

tomb18

01-25-2017, 07:25 PM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.