Computer Science Canada 3D Sphere Creation + Rotation |
Author: | MihaiG [ Tue Jun 11, 2013 11:22 pm ] | ||
Post subject: | 3D Sphere Creation + Rotation | ||
Heya folks, its been almost 5 years since my last submission so I decided to get out and do some fun stuff. A lot of you will be doing math and calculus once you enter university. One important thing youll learn is coordinate systems! One such system is the Spherical Polar Coordinates https://en.wikipedia.org/wiki/Spherical_coordinate_system Using just two angles we are able to address any point on a R= 1 sphere.. meaning if we were to go through every possible angle--to a degree-- we could figure out the converted points on our cartesian plane! Woah! Using a bit of logic i decided.. well let me create a sphere first.. but it didnt look well.. it needs an aspect of volume. So for each point i calculate i determine a predetermined width and create a polygon based on our resolution of the sphere.. i even made it.. so the higher the resolution the smaller the blocks looK! ![]()
The rotation stuff ill leave as an exercise to the reader.. If you have any questions or improvements let me know! This was about 2-4 hours of work through about 3 different revisions! |
Author: | DemonWasp [ Wed Jun 12, 2013 10:29 am ] |
Post subject: | Re: 3D Sphere Creation + Rotation |
Not bad. As a suggestion, try eliminating the magic numbers. Is 0.999847695 = cos(1 degree)? Is 0.0174524064 = sin(1 degree)? Your code doesn't tell me. Also, you have a bug: ![]() |
Author: | MihaiG [ Wed Jun 12, 2013 12:41 pm ] | ||||
Post subject: | Re: 3D Sphere Creation + Rotation | ||||
DemonWasp @ Wed Jun 12, 2013 11:29 am wrote: Not bad. As a suggestion, try eliminating the magic numbers. Is 0.999847695 = cos(1 degree)? Is 0.0174524064 = sin(1 degree)? Your code doesn't tell me.
Also, you have a bug: Yea, i had the magic numbers for cos/sin i got lazy to change them to something else.. Regarding your bug its because im re drawing over the poles try chaning line 18 to as well as 8
Seems to fix that issue of over drawing. It would draw each section twice, that small fix should address a few of the issues.. Though now tmax has to be double what your theta subdivision would be.. ie try 6/3 and you get the shape you want! Let me know if this works for you Here is the updated code!
Ill add in keyboard rotation when i get some time.. this was more for fun than anything, i stole some ideas from my 3d engine from 5 years ago |