C++ OpenGL in Xcode Generic Regular Prism Drawing Tutorial

C++ OpenGL in Xcode Generic Regular Prism Drawing Tutorial

C++ OpenGL in Xcode Generic Regular Prism Drawing Tutorial

In our search for a “C++ (Xcode IDE) OpenGL desktop application regular polygon drawer” (if anybody asks today what I do, that’s it, for the day), feel that they can’t channel the lyrics of Charlene this time, as we have some more generic offering today.

We now have a hybrid of the wonderful Indiana State University Maths and Computing Department C++ code of yesterday (C++ OpenGL in Xcode Hexagonal Prism Tutorial) merged in with some Land Surveying thoughts … remember …

What we found to be the case, practically speaking, to imagine the drawing of a regular even-sided convex polygon (with “numsides” sides) was …

  • look north …
  • turn clockwise (360° / numsides) for first line to draw (NB. there is more symmetry if this number is then divided by 2) … then from then on …
  • off this previous line, turn clockwise (180° + (360° / numsides)) for subsequent lines

… from one of the sequence of geometrical tutorials called PHP and Javascript and CSS Shape Drawing Tutorial which set us up for what this current OpenGL quest will link up with via WebGL, at a later date?

Well, instead of “look north … turn clockwise (360° / numsides) for first line to draw” today we do what amounts to the same thing, relatively (speaking), with …

arrange to have the prism top face first line run horizontally … (ie. look east …)

… and the rest is the same “Land Surveying” feeling idea. Land Surveyors performing a Survey Traverse start by establishing a known direction, or bearing … and ours, here today, is arranged to be 90° (ie. Easting (or x) changes (positively), Northing (or y) doesn’t). Then they measure angles with a theodolite (in the old days) for subsequent legs (whose length they also measure) all the way through to another known bearing, usually at the end of the traverse. That way any angular errors can be distributed evenly across the traverse calculations. This is all you need for a “relative” view of the situation … what ties the traverse down in an “absolute” view of the scenario is to know the co-ordinates of a couple (or more) of the “marks” (our “vertices” in OpenGL talk), and derive the other co-ordinates via the “ingrained” Land Surveyor equations …

ΔE (of a leg) = sin(bearing) * length
ΔN (of a leg) = cos(bearing) * length

… a by the by here is that any errors of E and N encountered while calculating between known co-ordinates is adjusted out (after the separate angular adjustment) by applying a Bowditch Adjustment (in the old days) … and so, today, the Land Surveying “feeling” bit about the generic algorithm to draw a regular polygon is to imagine a Land Surveyor traversing around our regular polygon as per …

  • look east …
  • off this previous line, turn clockwise (180° + (360° / numsides)) for subsequent lines

… to establish the “vertices” … as per (C++ code snippet, channelling yesterday’s the information we intend to peruse next (thanks)) …


void drawPrism(int numsides, GLfloat s, GLfloat h) { // thanks to //cs.indstate.edu
GLfloat a = s/(2.0f*tan((180.0 / (GLfloat)numsides) / 57.2957795)); //sqrt3; // apothem
GLfloat halfs = s/2.0f; // half side length
GLfloat bearing = 90.0, x=halfs, y=a;
struct pointXZ hex[(numsides + 1)];
hex[0] = {-halfs, a};
hex[1] = {halfs, a};
for (int ii=2; ii<=numsides; ii++) {
bearing += (360.0 / numsides);
x += (s * sin(bearing / 57.2957795));
y += (s * cos(bearing / 57.2957795));
hex[ii] = {x, y};
}
// ... more C++ code from Indiana State University Maths and Computing Department ... thanks ...
}

… and then use the wonderful code of Indiana State University Maths and Computing Department (as first mentioned yesterday) for the rest.

So please have a look at the C++ programming source code you could call main.cpp of today.

The C++ code above changed from yesterday as per main.cpp of today.

After today’s tutorial, our “quest” thoughts turn to WebGL, as the Javascript web based equivalent functionality to the C++ desktop OpenGL thoughts we’ve been developing recently.


Previous relevant C++ OpenGL in Xcode Hexagonal Prism Tutorial is shown below.

C++ OpenGL in Xcode Hexagonal Prism Tutorial

C++ OpenGL in Xcode Hexagonal Prism Tutorial

People think differently.

People have reverence for different things.

Some people do not like generalizations (“bye for now”).

We like …

  • associations
  • linkages
  • patterns
  • creeping up on knowledge, especially if the subject matter is difficult

… and so we proceed, on our quest, learning OpenGL … yesterday we drew a cube … yay!! … today a hexagonal prism … yayyyyyy!! … except those of you disappointed … why no genericity yet?! … and we say …

We’re “creeping up on knowledge” … sssshhhhhh

… and we’re aiming for some generic principles we can use with WebGL by looking at associations, linkages and patterns that we see (or get help from the web, seeing).

So the great place that helped today was from Indiana State University Maths and Computing Department … thanks for being so public with your brilliance.

This all being said, a large part of what this blog’s philosophy, concerning “learning”, involves revolves around (we hope) …

  • self reliance (in an OpenSource world)
  • being curious (about all publicly available software solutions)
  • knowing how to look for information
  • knowing where to look for information (we try to help, but this touches on “artistry”)

… and knowing when something requires deep understanding, you know when to say … “I need to enroll in a course to get full understanding here” … else … we say there are a lot of things you can teach yourself.

So the crux of the matter is, if you are on the same OpenGL quest as we are at the moment, go zooming ahead with your understanding should going from a “cube” to a “hexagonal prism” (with your OpenGL ideas today) give you enough clues, or take a look at the information we intend to peruse next, or enroll in a course, or look up more yourself with all those great “search” resources (eg. search engines) that exist on the World Wide Web.

Have a look at the C++ programming source code you could call main.cpp of today.

The C++ code above changed from yesterday as per main.cpp of today.

Another “take home” from today’s tutorial may be that an IDE-style run of the C++ today in Xcode can still make use of command line arguments as per the image below, snapshotted after Product->Scheme->Edit Scheme…

Word of the day

Apothem


C++ OpenGL in Xcode Follow Up Tutorial

C++ OpenGL in Xcode Follow Up Tutorial

OpenGL has a OpenGL.org landing page which will talk about all the platforms supported, and let’s just remind you about the purpose, with a quote from the webpage …

The Industry’s Foundation for High Performance Graphics
from games to virtual reality, mobile phones to supercomputers

… in other words, it is a big topic area, and we are chipping away at it.

Yesterday, we concentrated on the install, and if you are new to something, this is often exhausting enough in itself. Today we creep up on some of the concepts to representing a 3D object in a graphical way. Some of the concepts we see are …

  • object vertices definition
  • object colour
  • lighting … direction, type, angle, numbers of sources etcetera
  • perspective … field of view, aspect ratio, Z position

… with the help of the OpenSource brilliance of the following links …

  • The link has great software ideas for the code today … thanks … and thanks for the links below …
  • Another useful link

Think, if you are following along with us here, the next best advice we have is to examine the code of the experts amalgamated into our C++ programming source code you could call main.cpp of today.

The C++ code above changed from yesterday as per main.cpp of today.

Please take a careful look and learn. It’s all pretty amazing to me, as it has been for a very very very long time now.


Previous relevant C++ OpenGL in Xcode Primer Tutorial is shown below.

C++ OpenGL in Xcode Primer Tutorial

C++ OpenGL in Xcode Primer Tutorial

OpenGL is, to quote from the OpenGL.org landing page …

The Industry’s Foundation for High Performance Graphics
from games to virtual reality, mobile phones to supercomputers

… a big player for game developers for desktop, web, and mobile platforms. Today (and please note we have this blog posting in a WordPress 4.1.1 website at C++ OpenGL in Xcode Primer Tutorial) we are trying an install in a Mac OS X (Yosemite 10.10) environment using …

  • MacPorts … to install …
  • glew
  • glut and freeglut

… and the OpenSource brilliance of the following links …

  • The link has great software ideas for the code today … thanks … and thanks for the links below …
  • This link has good information regarding The OpenGL Extension Wrangler Library
  • Useful link talks about measures in Xcode to take to facilitate the compilation of the OpenGL application

… to create a Mac OS X Xcode C++ project to create our Hello World scenarios for today’s tutorial.

As you can see, there is so much more to learn with this subject area, and eventually feel that it will lead to some WebGL work down the track for some 3D rendering on the HTML canvas element.

If you enjoy such environments you may be very interested in researching Tcl/Tk in this subject area as well.

Here is the C++ programming source code you could call main.cpp

Onwards and upwards! Hope you enjoy today’s tutorial, which included a Mac Update of the Xcode Command Line tools, along the way.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, GUI, Operating System, Tutorials, Xcode and tagged , , , , , , , , , , , , , . Bookmark the permalink.

24 Responses to C++ OpenGL in Xcode Generic Regular Prism Drawing Tutorial

  1. I have to express my admiration for your kind-heartedness in support of those people who absolutely need help with this important theme. Your special dedication to passing the solution all-around appeared to be definitely good and has consistently helped professionals like me to achieve their targets. Your warm and helpful suggestions can mean this much a person like me and substantially more to my office workers. Regards; from everyone of us.

  2. blog kami says:

    But wanna say that this is invaluable , Thanks for taking your time to write this.

  3. Wonderful post, you’ve pointed out some excellent details , I too conceive this s a really great web site.

  4. I actually wanted to jot down a remark so as to say thanks to you for the amazing ideas you are sharing here. My time intensive internet research has now been recognized with really good ideas to talk about with my friends. I ‘d declare that most of us readers are quite blessed to be in a magnificent website with so many wonderful professionals with insightful techniques. I feel really privileged to have discovered your entire website page and look forward to plenty of more cool times reading here. Thanks a lot once again for a lot of things.

  5. Great write-up, I¡¦m normal visitor of one¡¦s site, maintain up the excellent operate, and It is going to be a regular visitor for a long time.

  6. click here says:

    Enjoyed studying this, very good stuff, regards . “Talk sense to a fool and he calls you foolish.” by Euripides.

  7. Lucky says:

    Very interesting info!Perfect just what I was searching for!

  8. I like what you guys are up also. Such smart work and reporting! Keep up the superb works guys I¡¦ve incorporated you guys to my blogroll. I think it will improve the value of my web site :)

  9. application says:

    Wow, amazing weblog layout! How lengthy have you been blogging for? you make running a blog glance easy. The overall glance of your web site is magnificent, as neatly as the content material!

  10. pitch says:

    I not to mention my friends have been checking out the good guides found on your web blog and then all of a sudden got a terrible feeling I had not expressed respect to the site owner for those tips. Those men were absolutely very interested to read through all of them and now have sincerely been using those things. Thanks for truly being very considerate and also for picking such impressive resources millions of individuals are really desperate to know about. My honest apologies for not expressing gratitude to sooner.

  11. Dependable says:

    You made some nice points there. I looked on the internet for the issue and found most people will agree with your site.

  12. You actually make it seem so easy with your presentation but I find this topic to be really something that I think I would never understand. It seems too complex and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

  13. I enjoy, cause I discovered just what I used to be taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  14. open says:

    I needed to write you a very small note so as to say thank you once again for all the pretty ideas you have contributed here. It was tremendously open-handed of people like you in giving unreservedly what exactly many people would have advertised for an e-book to end up making some bucks on their own, chiefly given that you might well have done it in the event you considered necessary. These ideas also worked to be a good way to understand that other people online have the identical passion the same as my very own to figure out lots more concerning this matter. I believe there are thousands of more pleasurable occasions in the future for individuals that examine your blog post.

  15. What i do not realize is in truth how you’re no longer actually a lot more neatly-appreciated than you may be now. You’re so intelligent. You already know therefore considerably when it comes to this topic, made me individually consider it from a lot of various angles. Its like men and women are not involved unless it¡¦s something to accomplish with Girl gaga! Your own stuffs nice. Always handle it up!

  16. I have been exploring for a little bit for any high-quality articles or blog posts in this sort of space . Exploring in Yahoo I at last stumbled upon this site. Reading this information So i¡¦m glad to convey that I’ve a very excellent uncanny feeling I found out just what I needed. I such a lot definitely will make certain to don¡¦t forget this website and provides it a glance on a relentless basis.

  17. Antone Mcmorris says:

    Great presentation, I like your style of presenting, very natural. thanks

    http://www.youtube.com/watch?v=Sg5Wm66NVko

  18. Thank you, I have just been searching for info approximately this topic for ages and yours is the greatest I have found out till now. But, what about the bottom line? Are you positive in regards to the source?

  19. Automotive says:

    Nice weblog right here! Additionally your website rather a lot up very fast! What web host are you using? Can I am getting your affiliate link in your host? I desire my website loaded up as fast as yours lol

  20. Tremendous things here. I am very satisfied to look your article. Thank you so much and I am taking a look ahead to contact you. Will you please drop me a mail?|

  21. Bus Tours says:

    Awsome info and right to the point. I am not sure if this is in fact the best place to ask but do you guys have any thoughts on where to get some professional writers? Thanks in advance :)

  22. Generally I do not learn article on blogs, however I wish to say that this write-up very compelled me to take a look at and do so! Your writing taste has been amazed me. Thank you, very great article.

  23. I am now not positive the place you’re getting your information, however good topic. I needs to spend some time learning more or understanding more. Thanks for great information I used to be in search of this information for my mission.

  24. I in addition to my guys happened to be checking out the nice information and facts found on your site and so all of a sudden I got a terrible feeling I had not expressed respect to you for those tips. Most of the boys are already certainly stimulated to read them and already have very much been taking advantage of these things. Thank you for being quite accommodating and also for getting variety of incredible ideas millions of individuals are really needing to be informed on. Our sincere apologies for not expressing gratitude to sooner.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>