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?
Since shaders can work with 4 dimensional vectors and 4×4 matrix, we can be smart and use only one vertex shader to do the trick. This shader will take three inputs:
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 matrixSandPthe projection matrix. The output of the vertex shader will be:P * S * vBy setting correctly the coefficients of
S, you will be able to select which component invshould appear in the result. For example, if you want to displayYxB, thenSwill be:So we have:
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:
Notes:
glUniformMatrix4fvis the function to use to defineSandP.