Jump to content
  • Advertisement
Sign in to follow this  
zoner7

Creating a a graph and a camera in OpenGL

This topic is 2897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a fairly simple assignment. I have a program that runs a long sequence of calculations, and I ultimately end up with a vector of a vector class that contains 3 coordinates.

I want to plot these points on a graph and then design a camera that is able to rotate the points in various directions. Nothing too complex.

I have simply curious how difficult this will be and if anyone can offer some guidance as to how I can begin to solve the problem. Note that I have VERY little experience with OpenGL.

Share this post


Link to post
Share on other sites
Advertisement
By 'assignment', do you mean a homework assignment?

Also, what constraints or requirements are you working with? What language(s) can you use? Does it have to be rendered using raw OpenGL, or can you use some other graphics API or engine?

Basically, some more info would probably be helpful.

Share this post


Link to post
Share on other sites
I am doing a research project this summer; in essence, I can solve the problem anyway I see fit.

The program is currently written in c++, and I've used SFML as well.

Share this post


Link to post
Share on other sites
That should be quite do-able, but it's hard to give specific advice without knowing more about the background of the project.

I think what I'd suggest is just to dive in, and then post here on the forums with any specific questions you might have. As is, we don't know whether you're stuck on creating an OpenGL window and rendering your first triangle, or if you're stuck on making an interactive 'arcball' camera that allows you to rotate the graph around in real time. So, some additional info would probably be useful.

As for the general difficulty, I would say 'low to medium-low' relative to the 'average' interactive graphical application. Assuming you settled for OpenGL immediate mode, something like this could easily fit into a single source file (e.g. main() and just a few other functions).

Share this post


Link to post
Share on other sites
If you just want to graph stuff, it might be a lot simpler to write all your data to a file, then build a Java or C# app that graphs it. It seems like it would be less work to write the code for a simple graph in not-OpenGL.

if you were doing a game or simulation or something, OpenGl seems like it would present more of a benefit, but as you are just graphing I feel you might do a lot of work for something relatively simple.

Share this post


Link to post
Share on other sites
Quote:
Original post by way2lazy2care
If you just want to graph stuff, it might be a lot simpler to write all your data to a file, then build a Java or C# app that graphs it. It seems like it would be less work to write the code for a simple graph in not-OpenGL.

if you were doing a game or simulation or something, OpenGl seems like it would present more of a benefit, but as you are just graphing I feel you might do a lot of work for something relatively simple.


Copying to a texture and rendering it takes like 10 lines of code in C++ using OpenGL...

Share this post


Link to post
Share on other sites
This shouldn't be overly difficult. You want to plot a set of data on a 3D graph right? And all you're interested in is the points, you don't want to create a curve?

A simple render function would be:

void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(<mode>); //One of the OpenGL primitive types (terminology?), GL_POINTS would treat each vertex as a point, GL_TRIANGLES would draw triangles from each set of three points.

for(int i = 0; i < dataPoints.size(); ++i)
{
glVertex3f(dataPoints.x, dataPoints.y, dataPoints.z);
}
glEnd();
}


The camera code is a bit more involved. If you want perspective correction, you will probably want to look up the glFrustrum() function or the gluPerspective() (I think, I don't use it myself), otherwise just use glOrtho(). Each of these functions should be applied to the Projection matrix stack, not the model/view matrix stack.

As for actually positioning a camera, glu makes this easy with the gluLookAt() function.

I've tried not to tell you exactly how you need to do everything, so I hope this is ok. As soon as I fix my camera class I'll quite happily share it with you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!