Welcome! Log In Create A New Profile

Advanced

Assignment 2

Posted by t0xic 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Anonymous User
Re: Assignment 2
September 15, 2011 12:45PM
OK, I'm all done. Will look into drawing spheres without gluSphere()...this is probably be an astronomically sized can of worms! Grrrrr...
avatar Re: Assignment 2
September 15, 2011 12:52PM
You have some time. I would cover my bets if I were you. And you can do this with the assurance that you at least have some kind of "case for the other point of view". But the instructions in the question are very specific, so I reckon you'd do well to at least open the can and sample a worm or two. grinning smiley

(Send a little note of apology to your coming weekend regretting that you will not be able to attend, due to unforseen circumstances).

To get you started, notice the orientation of the sphere in the picture that goes with the model code. I found I had to hack and kludge things to make my sphere nicer. It didn't just work right out the box for me. However, maybe if you pause and think the geometry through first you can make that part work sweetly to begin with. It would be nice to hear that someone did it without hackery.
Re: Assignment 2
September 15, 2011 02:10PM
@eddy - Thanks for the advice! I do remember stepping through my code last night, and it was hitting the right values at the right time (the texture coords were 0.5 when my outer loop value was 0, when drawing), but I will double check today. I will probably end up going back and double checking my maths anyways! I'll let you know how it goes (I do have a feeling I'll end up submitting without any texturing working though)
Good luck with yours - tonight could be the night it all works!
avatar Re: Assignment 2
September 15, 2011 02:24PM
Sadly my graphics assignment is now in the queue behind the C++ again. And the C++ has probably got more education for me than I'd like right now.

I was just thinking. I make my Sun inside a pushMatrix ... popMatrix (the way Cunningham suggests), and my texture is in the next push.. pop together with the Earth. Now whenever I use texture the Sun goes dim. If I move it round manually I can eventually see it (and it corresponds with the position of the light), but it has lost its shine. If I turn texture off, the Sun shines again. That sounds similar to the problem you're having with light and texture on the Earth all at the same time.

So maybe a few experiments with pushing and popping rearranged might fix things for you? You see, I have "the same problem" when it comes to the Sun; but my Earth with texture lights up just fine.

Hoo boy. So many loose ends lying around here. And the worst is that a lot of those are conceptual loose ends. Hope there's a good tut letter explaining how it ought to work, and covering common errors.
Anonymous User
Re: Assignment 2
September 15, 2011 02:48PM
OK, for now focusing on getting the new sphere to work, I have a weird (very cool looking) bunch of disks rather than a sphere. I guess some of the axial transformations I apply prior to drawing the sphere messes the 3D geometry up a little bit because my quad strips are drawn in the plan rather than perpendicular to it.

With regards to the push/pop matrix texture issue you're having. Try the following:

Language: C++
glEnable(GL_TEXTURE_2D); glPushMatrix(); // do your rotation/translation etc etc manipulations here // glBindTexture(GL_TEXTURE_2D, your texture); // draw your Earth glPopMatrix(); glDisable(GL_TEXTURE_2D);
Re: Assignment 2
September 15, 2011 02:57PM
Just had a quick look at my code, and realized I am actually just rotating the camera by 23 degrees, and when I draw the sun, I compensate so it appears the sun is rotating on the y = 0 axis. I'll have to play around tonight, and do it properly. The list of outstanding issue is getting longer instead of shorter!
Re: Assignment 2
September 15, 2011 07:05PM
No progress is being made - urgh. I started from scratch again, and built up the project bit by bit. I still cannot get the texture to work!
I even went and used this example HERE (scroll down just past half way, and I couldn't even get that to work!). All I end up with is a distorted grey scale map on only a portion of the globe.

@eddy - I've tried adjusting my angles and multiplying by factors and such, but it just will not come right. I'm pretty sure my maths is off. I cant find any forumlas on how to convert the two angles used with drawing the sphere (phi and theta), into two dimensions to use for the texture locations (I guess this is the main problem for both of us).

I am slowly running out of idea's and running out of the will to actually carry on trying to get this to work.
avatar Re: Assignment 2
September 15, 2011 07:26PM
Maybe you're being too complicated?

What do you need? A way of generating numbers between 0 and 1.

So you need fractions. As simple as you can. I made very small modifications to their control variables of the for loops used to construct the sphere (just doing the bare minimum it takes to map them to positive numbers). That gave me the distorted images I've described in previous posts. Then, as I said, I gave up trying to work it out from the conceptual angle, and just used those very same fractions I'd been using all the time by trial and error, "correcting" what my eyes told me the computer had calculated. No more math. Just, "Well that's halved so I'll double it" or (better guess) "Well that's only getting half way, so I'd better halve it again." (Since the problem is that you're getting to 1 too soon, which means your fractions are probably too big rather than too small?)

The trick is to get away from the pen and paper, and just try plugging in small changes to the fractions you're using on screen.

If I find some more time for this (it's waiting until I'm sure I'm about out of time) I need to make my planetary motions work. I haven't even fixed it so it it wobbles annually.

I reckon if you've got the motions worked out, and you indicate what to comment out to get it working this way, and what to comment out to get it working that, you'll at least get some credit.

(And BTW: cool resource you found there. )
Anonymous User
Re: Assignment 2
September 15, 2011 07:55PM
Grrrr!!!!
Re: Assignment 2
September 15, 2011 08:09PM
Maybe I am making it too complicated - I just dont know.

The thing is, I am generating numbers between 0 and 1, and to me, it makes sense and is correct. Yet it just does not work. I'm going to try explain my understanding of how the sphere is drawn up, and the method I use to get the values between 0 and 1 - I'll see if I make sense, and maybe you can comment if my logic is way out there.

We have two loops, an outer loop, which runs between -90 and 90. This tracks the "up/down" angle for which we are drawing. Hence -90, is south, 0 is on the equator and 90 is north (these effectively map to the longitudes). The inner loop, tracks the position going around the globe, and runs from -180, up to 180 (these are the lines of latitude).
So, when looping through, when we start at -90:-180, this is the south pole, and this should map to (0, 1) on the texture (bottom left corner). As the inner loop increments, the latitude values changes (as we track around the globe), so the first value of the texture mapping increases, while the second value stays at 1. If you think of the texture as a 2d array, we are moving along the very bottom, starting at (0, 1), which maps to -90:-180, up to (1, 1), which maps -90:180.
As the outer loop increases, we slowly move up the globe. So each iteration of the outer loop, the second value in the texture mapping decreases (as we move up to the north pole).
In my head, if I think of the texture as a 2d array, we start at the bottom left slot, and move right across the columns. Then we move up a row, and move right across the columns, and repeat.

My calculation takes this all into account. So, when I am at (-90, -180), my texture mapping coords are (0, 1), when I am at (0, 0), my texture mapping coords are (0.5, 0.5), and when I am at (90, 180), my coords are (1, 0).

In my head, this all makes sense, and yet when it executes, it just does not reflect what I think it should.

Does this make sense, or is my understanding just so totally completely wrong?
Anonymous User
Re: Assignment 2
September 15, 2011 08:45PM
Sorry for not really commenting on your actual question re logic, but I've had a rough few days with work and this assignment and I'm not as sober of thought as I'd like to be (in fact, I'm going to hit the sack as soon as I hit "Post Message" after this).

What I can tell you is that you have to calculate your coordinate point at the same place you calculate your vertex and that you MUST set your tex coord before your vertex (you may very well already know this).

The calculation you need for your tex coord is very straightforward and is as follows:

Language: C++
u = outer anlge you are currently using for your vertex / 360; v = (2* the inner loop angle you are currently using for your vertex) / 360; glTexCoord2f(u, v); glVertex3f(x,y,z);

The 2 we multiply with here is related to the ratio of your image (e.g. the Earth texture map provided and most of the ones I've looked at are 2:1). You might have to play around a bit with the signs and with the increments to get it just right (in other words, depending on your implementation, you may need to pop in a - or add your loop increment to an angle here...it will obviously depend on where you are in your loop and which vertex you're calculating, but the calculations for u and v I've given remain as straight forward as that).

I'm going to ask one of you (or both) if you would just throw me a bone re how to "fix" that blooming piece of code provided in 2.4.3 because all I'm getting is either the weird disky sphere I've previously described, or using another implementation using only quad strips, the strange inverted texturised implementation I've also mentioned previously.
Re: Assignment 2
September 15, 2011 09:14PM
@ phyz - thanks for the tips regarding the values of u and v. I tried to implement it (adjusting for my loop values sometimes being negative etc), but it must be doing something wrong. I end up with a textured mess on part of my sphere. Oh well - I think its going to be submitted like this.

With regards to your sphere problems - If you ignore the axis transformation (comment out the code), does your earth appear as a sphere? In the end I used the code on page 20 of the tut 101 letter, and it just worked for me.
Without giving away too much (unless you prefer I just tell you how I do it), in my "display" method (in here I call methods to draw the sphere and draw the sun etc), I just inserted one line of code, and that takes care of the tilting of the earth, and another line of code which takes care of the rotation. That part of the assignment I managed to get working using existing examples from the text book.
If you implement the sphere code as is from page 20, does it not work? - or am I just misunderstanding where the issue is?
avatar Re: Assignment 2
September 15, 2011 09:24PM
@ InSaNiE.

One thing you could try is to think again about what the values of your bottom left TexCoord should be. (Nudge, nudge -- unless it's just a typo).

As far as the values in between were concerned, I didn't even think about them. I looked at bottom left (which may have different values to those you're using), and top right. I have different numbers to phyz in my actual solution (and to be honest the numbers I have don't make any logical sense to me; they just work, that's all), but it's the same idea, roughly.

As I said, I've frigged things so that there are no negatives in my calcs, but I doubt that's truly necessary. (All I did was "right shift" everything).

Theoretically your bottom left (whatever it may be) must map to the correct bottom left (Tex) coordinate, and your top right, to the correct top right (Tex) coordinate.

Bear in mind that my texture is still stuck just on the quad strips, so I might find it ends up irrevocably broken when I move to mapping it to the many aliases North and South have.

@ phyz. What I had to do was reconsider "who should be x, y, z". However, the sphere always looked spherical. I suspect your copy of the book's code has a typo or something like that in it. Hmm ... I had some very uncool artifacts from the Poles for a while (you have to watch the sign there) now I think of it.

Are you sure it's quad strips lying in the disks? Maybe you somehow are still doing triangle fans? Those could perhaps end up in disks? I can't imagine what this would be. I'll think about it on paper and see if I can come up with a possibility. (And if I get my graphs working for C++ tonight (what a nightmare: all the things I left for later have come back to haunt me. Crash. Crash. Kerrumph.) .. er if I get C++ to function as it should I'll even have a bash at breaking my sphere tomorrow. It would be interesting to see the world as disks (as long as I have a safe copy of the "working code" somewhere first).
Re: Assignment 2
September 15, 2011 10:24PM
@eddy - you were right! My understanding was slightly off, I was under the impression that bottom left was (0, 1). I've adjusted my code, but still, not a clear texture image.

I'm pretty certain my values in between are being calculated correctly - but obviously they aren't. I think I have an understanding of what needs to be done, and how to do it - and I think I've done it, yet it still doesn't work. I dont think I'm going to get it working before Monday, and I know I dont want to spend hours over the week-end. I'm going to start cleaning up my code, and writing a "readme" with some explanations for why my textures is half working.
If you decide to push on - good luck! I'll still probably end up fiddling a little bit - and if I suddenly strike gold and get it to work, I'll be sure to post here.
Anonymous User
Re: Assignment 2
September 16, 2011 07:25AM
Thanks for the input! I'll definitely have a look at your suggestions.

In general: here's another link

@InSaNiE

Don't give up yet mate! The due date is only the 19th...I know it's not a great way to spend a weekend, but you still have two more days of trying and it might just be the breakthrough you need smiling smiley

@eddy

I can help you with the chart aspect. I used someone else's lib for the charting last semester and simply noted it to the lecturers and they were fine with it, so just let me know ok?
Anonymous User
Re: Assignment 2
September 16, 2011 10:21AM
Got a complete Earth the manual way! WAHAAAA!!! Can't believe it was actually so easy! HUGELY embarrasing considering my maths background grinning smiley

Now I just need to sort out all my rotations and lighting again as that's all messed up...but that shouldn't be too much of a mission * touch wood *
Sorry, only registered users may post in this forum.

Click here to login