2

Possible Duplicate:
Visualising 4D objects in OpenGL

I have a set of 4 dimensional data points (lets call the dimensions X,Y,A, and B) that I'd like to plot in 6 different 2d plots (plot XxY, XxA, XxB, YxA, etc...).

In a previous question I asked about the proper way to store and plot this data. The solution was to use a VBO that stored the 4 dimensional vertices. Then using different vertex shaders I could select which dimensions are plotted in each of the 2d plots.

I've spent a few weeks looking around for openGL tutorials on how to do this but I haven't yet found something that makes sense.

My question is this: In c++, how can I define a shader that would allow me to plot only 2 dimensions of a 4 dimensional point in a VBO, and do I need to define a single shader for all 6 2d plots or do I need a shader for each of 6 different plots?

Finally how do I incorporate the shader into the plotting code so it gets used by openGL?

Community
  • 1
  • 1
slayton
  • 20,123
  • 10
  • 60
  • 89
  • maybe, but I'm asking specifically how to do this with shaders whereas the other link is asking for a library. – slayton Sep 28 '11 at 17:19
  • 2
    The algebra is the same either way. You might as well ask "how do I plot a point using OpenGL shaders" – spraff Sep 28 '11 at 17:38
  • Points have 3 dimensions - not 4. So, what is your question? – BЈовић Sep 28 '11 at 18:04
  • @VJo: Three-dimensional points have three dimensions, sure. Four-dimensional points will have four. – GManNickG Sep 28 '11 at 18:35
  • Write down the vector equations without referring to the number of dimensions: it works in equally for any dimensionality. – spraff Oct 04 '11 at 08:15

2 Answers2

3

Since shaders can work with 4 dimensional vectors and 4x4 matrix, we can be smart and use only one vertex shader to do the trick. This shader will take three inputs:

  • the point data (a 4 floating vector),
  • a selection 4x4 matrix,
  • a projection 4x4 matrix.

All the magic is done by the selection matrix, which will map you 4 coordinates vector to planar coordinates. Let's call the point data v, the selection matrix S and P the projection matrix. The output of the vertex shader will be:

P * S * v

By setting correctly the coefficients of S, you will be able to select which component in v should appear in the result. For example, if you want to display YxB, then S will be:

S matrix

So we have:

enter image description here

P is a standard projection matrix, which will help you to place your graph correctly (offsets and scale).

Following is an example of vertex shader implementation (not tested, may contain mistakes) for OpenGl3:

#version 130

in vec4 vin;
uniform mat4 s;
uniform mat4 p;

out vec4 vout;

void main()
{
    vec4 tmp = s * vin;

    // Depending on your projection matrix,
    // you may force the 4th component to 1.
    tmp[3] = 1;

    vout = p * tmp;
}

Notes: glUniformMatrix4fv is the function to use to define S and P.

neodelphi
  • 2,706
  • 1
  • 15
  • 22
0

You have this input:

in vec4 Points;

You can access to vec4 components by indexing them:

Point[0]; // Equals Point.x

You can supply the following uniforms to specify which components to use for plotting:

uniform int XCoordIndex;
uniform int YCoordIndex;

gl_Position = vec4(Point[XCoordIndex], Point[YCoordIndex], 0.0, 1.0)
Luca
  • 11,646
  • 11
  • 70
  • 125