Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
So I am writing an application that needs to be able to draw spheres and lines. I have written the UI using GLUT and GLUI. So what I need the program to be able to do is allow the user to be able to click on a sphere in the graphics window, click somewhere else on the graphics window and have it draw another sphere at the position of the second click and then draw a line (or small cylinder) connecting the two spheres. My question is, how do I draw a sphere at a certain position on the window? I know about glutWireSphere() and glutSolidSphere(), but I cant find a way to change to position of where the sphere is displayed (as the default is at the origin). Can somebody help me with this? Thanks
 

laprej

macrumors regular
Oct 14, 2005
108
2
Troy, NY
Look up glTranslate. This may be a bit of a steep learning curve if you're not really all that familiar with OpenGL...
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
Look up glTranslate. This may be a bit of a steep learning curve if you're not really all that familiar with OpenGL...

yea im not familiar with OpenGL at all. I was hoping that there would be a drawsphere function that could input x, y, and z coordinates for the origin. is that too much to ask for? I guess if I had to, that translate function should work. but itll make me work alot harder. :(
 

psingh01

macrumors 68000
Apr 19, 2004
1,586
629
yea im not familiar with OpenGL at all. I was hoping that there would be a drawsphere function that could input x, y, and z coordinates for the origin. is that too much to ask for? I guess if I had to, that translate function should work. but itll make me work alot harder. :(

It really isn't a lot of work. You are just calling one extra function :) If you imagine the glut method as drawing sphere at the origin, then glTranslate just moves it to some other part on the screen.
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
It really isn't a lot of work. You are just calling one extra function :) If you imagine the glut method as drawing sphere at the origin, then glTranslate just moves it to some other part on the screen.

but the problem is i will need to move individual spheres, and gltranslate(), from what i can understand, moves the whole screen. thus it would move all the spheres on the screen. not just the one i want to move.
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
For some odd reason, now when I click on build and go, the application doesnt open? it still says "Skeleton modeler Launched" at the bottom of the xcode project window, but the application is not open. It never did this before, and I dont think I changed anything. Any reason why its not opening now? I can still double click on the .app file and open the application, but i dont get the output to the console that way. Any help?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
but the problem is i will need to move individual spheres, and gltranslate(), from what i can understand, moves the whole screen. thus it would move all the spheres on the screen. not just the one i want to move.

This is why you use glMatrixPush() and glMatrixPop().
 

Gelfin

macrumors 68020
Sep 18, 2001
2,165
5
Denver, CO
i see. I dont really understand what those do. but I guess ill try and look it up on google.

It's been years since I did any OpenGL, but one thing I do remember is this: Matrix operations are annoyingly counterintuitive to begin with, but you won't fully comprehend what you're doing in OpenGL until you grok them. Focus in that area until it makes sense, and you'll feel a lot less pain doing everything else.
 

Animalk

macrumors 6502
May 27, 2007
471
19
Montreal Canada
When i first started learning opengl, the hardest concept by far for me to understand was the pushing and popping of the 3 or 4 (don't remember them all) matrix types. Once that was grasped, the code just kept flowing.

It's not as complicated as it first looks and it is important to always go back to basics. What is a stack, how does it work, what can i do with it, etc.

Learning opengl is some of the most fun I have ever had coding though it is often quite frustrating. Good Luck :)
 

psingh01

macrumors 68000
Apr 19, 2004
1,586
629
Here are great OpenGL tutorials: http://nehe.gamedev.net/

You will have to learn the basics of OpenGL, it is not so simple of finding the right function that does what you want. OpenGL is a state machine, each function changes the state of the machine. So you have to have a better overall understanding on how the whole machine works instead of just picking things up function by function.

As the previous poster said, once you get going you'll realize it is not all that complicated and actually quite simple the way it works.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.