Welcome! Log In Create A New Profile


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
avatar Assignment 2
September 10, 2011 11:52AM
You are required to write a program that shows a view of the earth as seen from the moon.

In particular:
1. The earth must be displayed as a sphere.
2. An image of the earth's surface must be mapped to the surface of the sphere.
3. The earth must rotate on its axis (between the north and south poles).
4. The light of the sun must fall on the surface of the earth. The other side of the earth (where it is night)
must be dark.
5. Since the moon revolves around the earth once every 30 days, the light cast by the sun on the earth
(and the shadow where it is night) as seen from the moon must change. As far as the moon is
concerned, the sun appears to "move around the earth" once every 30 days.

Could someone kindly explain exactly what is meant by point 5.

Am I correct in assuming that we are not going to follow the traditional view of the solar system and actually move the sun and light source around?
avatar Re: Assignment 2
September 10, 2011 12:23PM
You view this solar system from the Moon.

Now if you viewed it from the Earth you'd see the Sun appear to "rise" and "set" each day. Likewise the Moon would rise and set at night.

I think it's simpler viewing from the Moon.

For instance the Moon's day works out such that the same face of the Moon always faces the Earth.

We've also been given rougher approximations. If I recall correctly the Moon's orbit is something like 28 or 29 days (between these). We're not being asked to construct a planetarium.

Anyway, if this is the only problem you're having with this one you're at least way ahead of me. I'm not managing to get texture to render, or lights to show. In fact all I have is my two spheres, really. I would've posted if I had a problem I could express in a solvable manner.

I suppose one question you could answer for me is whether you're managing to use the .bmp file, and if not, what you're using to make it "raw". (And maybe if you have the Gimp, you could tell me whether that ought to work or not for converting to RGB from BMP?)
Re: Assignment 2
September 11, 2011 12:46PM

Did you manage to get the texture of lighting to work?
I'm pretty much having the same problem. I've managed to get a sphere drawn (red sphere, with a green square going through it, so I can see rotations happening), and have it rotating at a 23.5 degree angle. I cannot however get the texture or the lighting to work. As far as I can tell, I've set everything up correctly - it just doesn't do anything.
avatar Re: Assignment 2
September 11, 2011 12:50PM

Take a look at assignment B towards the end of TL101, there is a piece of code that we used last semester to convert the bmp into a texture map.
Use that as a starting point...
avatar Re: Assignment 2
September 11, 2011 02:46PM
Thanks Ben! You're a star, mate. I've moved entirely over to getting my C++ assignment completed (and that's mainly yet another graphics problem, as you've probably seen on the other threads), but I'll follow your tip quite soon, I think. (Because at the moment I'm settling for just hacking on their answer to Q9, there).

GL_REPEAT? That sounds wrong. But seeing as everything I've tried till now has done nothing more than inspire me to learn new ways of saying "Oh dearie dearie me", "Well I never..." and "Tut tut" loud enough for the neighbours to feel they need to call the police again, I suppose it can't hurt to try something that works....

Man would I be chuffed if I saw a texture on my rendering of the Earth! (@InSaNiE: that means I'm still in the same boat as you, but some hope has just shone through.)
Re: Assignment 2
September 11, 2011 06:46PM
@eddy - any luck getting the texture to work?

I tried using that example as well, with no luck. For me, I think the loading of the file into a byte array is working fine, its just when it comes to applying it as a texture, thats where I am missing something (and thats the part which is not in the example) Anyways, I'll carry on plugging away.

I did however finally manage to get the lighting to work (to some degree). I am getting my light (and circle representing the sun) to rotate around the earth and moon correctly (the timing etc is all correct).
The problem I am having with this: my objects ares grey, and not the original color I specific. I realize that when lighting is enable, effectively the glColor command has no effect. If I use the glMaterialfv commend just before drawing my earth or sun, setting the color, then the earth, for example, will be drawn as a red sphere - but lighting doesn't seem to have any effect on it (no shadows etc).
I do realize its probably something to do with my lighting settings, but if anyone has any advice or insight that might help - it would be greatly appreciated.

avatar Re: Assignment 2
September 11, 2011 08:01PM
No, I'm still on the C++. The texture has to be "fractionally applied". I've seen an example somewhere where someone used just "0.5 to 0.7" on one of the texture axes, for instance. One of the things I think I need to look at again in mine is whether I'm counting my lines of longitude and latitude right (to get the right fractions of the texture to apply). I'm glad to see it would a appear that a straight BMP can be used, at least.

Wow! So you've got glMaterial working for you? Surely you're close then? Maybe your light has too wide a beam to be a "spotlight"? As I understand it, if you have a white surface (material? color? Material, I think), then if you shine a red light on it, you get red reflection. If you shine yellow, yellow, etc. If you have a blue surface plus red light you'll get black reflection. You should only get any kind of color if the light is shining properly on the surface.
Re: Assignment 2
September 11, 2011 09:06PM
After going back to the drawing board with the lighting, I started from scratch and looked through a few examples, I finally managed to get the lighting working!
I now have a blue sphere (the earth), which rotates on a tilted axis, and have a yellow circle (the sun) circling the earth every 28 rotations of the earth (I know the spec says 30, but 28 is more accurate). The light source tracks with the sun, so the light and shadow being cast on the earth is looking correct - FINALLY!

The last thing that is not working is the texture - I think I'm going to have to go back to the drawing board with this as well, and see if I can come up with anything.
@eddy - if you do manage to get yours working, could you let us know here (and I'll let you know if I get mine working). And we can both try get things done from there..

Good luck with yours!
avatar Re: Assignment 2
September 12, 2011 10:37AM
Aye, that I'll do. At least there are signs that it's doable.
Re: Assignment 2
September 12, 2011 07:57PM
I've been working on getting the texture to work now, for the better part of (another) 3 hours. Unsuccessfully. I'm beginning to think that textures do not, and will never ever work in opengl. Ever.

Has anyone managed to set the picture as a texture on the sphere?

I could really use some help/input/advice: I'm pretty certain that I am loading the image into memory correctly. My coords are probably being set incorrectly (using glTexCoord2d), but I have tried a whole bunch of things unsuccessfully. My application doesn't crash or such, the texture is just not rendered.

Does anyone have any tips or hints on getting the coords set correctly? Or suggestions on things I may have overlooked?

I'm pretty much at the point where I have run out of examples to look at and idea's to try - and still it will just not work.

Thanks in advance.
avatar Re: Assignment 2
September 12, 2011 09:35PM
I've put a lot more than 3 hours into trying to get textures to work in this one. I can tell you what appears not to work:

Converting it to raw format, as Cunningham says we must. Doesn't help (by itself) at all.
Changing size.
Changing to GL_REPEAT.

Maybe I've got the wrong idea. I thought you would take the "bottom corner" of the Earth, and assign a glTexCoord of (0.0 , 0.0) there. Then you would step across and up all the way to a glTexCoord of (1.0, 1.0) at the "top of the world". Now I've left the polar regions out of this. At this stage they get assigned a color I've called "white". The rest of the Earth I envisage as a single sheet, somewhat distorted, and every time I read the book (or an article online) I get the idea we're meant to have it so that at the middle of your array of the earth the glTexCoord is meant to be (0.5, 0.5).

My solution is stuck at that point, and I'm getting to the point where if it stays stuck there it's just going to have to stay stuck there. My eyes are threatening to go on strike, and when that happens something like passing a course starts to look fairly trivial. Escaping the headache matters much more.
Re: Assignment 2
September 13, 2011 10:24AM
@eddy -sounds like you've made some progress with the textures. No matter what I attempt to do, I cannot get ANY texture to display anywhere.

But I am on the same page as you. I'm going to spend maybe tonight and tomorrow evening working on it, but after that, its just going to be submitted as is. In the grander scheme of things, spending hours and hours on getting the textures to work, when in the end they probably only count 1% of my final year mark - its just not worth it!
avatar Re: Assignment 2
September 13, 2011 01:12PM
Greetz Guys,

I have been working hard on this project (the better part of the weekend) and find myself pretty much in the same place.

I spent a day trying to figure out the rotation and animations as I just couldn't grasp the sun moving thing from the Moon POV.
I ended up doing a quick mock up in Maya which cleared things up. I just parented a camera to the moon so I could see what was going on.
For late comers here is my playblast :

As for the texturing, I spent another 3 days to no avail.

My solution as it stand now is to do it my own way. That is, I have used Angels' section 2 sphere for the Sun.
I have used a gluShere for the earth.
I have used a modified bmp loader to get the texture loaded nicely. (I tried converting the .BMP to RAW in 5 different applications including photoshop, but my texture was always grayscale and repeated )
This works but it's not what was explicitly asked of us.

If I finish my Advanced Programming Assignment 2 in ample time, I will come back to this and have a look at the texturing issue.
avatar Re: Assignment 2
September 13, 2011 01:40PM
Possibly the trick is to move the code to a different location. Things that didn't work for my by following examples that put them in the init() function have worked when I moved the code to the display() function. Just a thought. As yet, no texture.

Yes, I thought of going the gluSphere route, just to see if it could get the texture onto Something. Later. In my C++ it looks like I deleted one of my files that worked and replaced it with the previous one. Or maybe I deleted part of the code and forgot to redo it? Disaster anyway. Demoralizing to see your Assignment 1 going under the waves while you're busy on Assignment 2. I don't mind things that were NOT working staying a mess. Sometimes that just happens. But this was something that Was working. Quite sad, really. Anyway that means less time for graphics (we all seem to have made the same mistake trying to share time between graphics and C++ here?).
Re: Assignment 2
September 13, 2011 10:06PM
@eddy - losing already working code files is very annoying and frustrating, I've been there before.

I've finally managed to get SOME texturing working, although its not doing it correctly. Currently its only on a quarter of the sphere.
If anyone has successfully managed to get the bmp as a texture for the entire globe - could you let us (me) know what values you are using for the glTexCoord2d command? (assuming you are using the sample in Angel, and on page 20 of the tut letter). This is the last bit which is incorrect for me, and it is just not coming together.

One way or another, its coming to an end. Tomorrow is code cleanup, and if I do not get it working then - its going to be submitted as is (everything working, apart from the texturing).
avatar Re: Assignment 2
September 14, 2011 10:18AM
That sounds like whatever routine you're using is not working for negative numbers?

A hemisphere would be covered if you took everything from 0 to 80 (missing out -80 to 0). And then reduce that to half a hemisphere (ie a quarter of a sphere) if you skipped out -180 to 0 the other way.

Did you have to move code from one function to another? Or did you have to put it in a different order? Or was a completely fresh look needed? (I can't ask you exactly how you did it, but would be glad if you could give a broad hint that still puts the thinking onto my shoulders).

Oh and I got to the bottom of that problem I had. I think what actually happened was I took great care not to break the fragile bit of code I was going to "fix later" to make the file based on that section that I needed for the next; and then "later" never happened. Looks like my Assignment 2 there is now pretty bulletproof at least (certainly it's survived my attempts to break it again). Just one more subsection of that one and I've done the whole bang shoot. So then graphics gets a bit more attention. Phew!
Re: Assignment 2
September 14, 2011 11:36AM
@ eddy

The problem I was having was strange, and not related to code directly (as such). Basically, when I was reading in the bmp, I just had it as "earth.bmp", no path. When I ran from the IDE, the application didn't crash, but no texture was happening. For no real reason, I decided to run the exe directly from the build directly, and suddenly I had texture!
Then I hardcoded the path of the bmp in my code, and now the texture is happening. Its very strange.

And I think you are correct with the problem I am having. I know if I spend time really trying to understand the problem, and sit down I can probably solve it - I just feel like I dont have it in me, after spending hours and hours up to this point, and not getting much for my time tongue sticking out smiley

I'll see how things go this evening - but I have a feeling you are correct. I'll need to investigate how I calculate the coords for the texture. I also currently dont have the texture AND lighting working at the same time, so that is more time to get that working. I think its all going to take more time than I am hoping.

Good luck with yours, and just shout if you want some hints or tips or whatever as to how I implemented some of my code.
avatar Re: Assignment 2
September 14, 2011 01:33PM
Thanks for that. OK I already have my path to the BMP hard coded. At least I know there's some texture appearing from a BMP somewhere out there (as opposed to messing about with RAW files etc) signs of hope are always welcome eh?

If you're using squares your sign will vanish. Some trig functions could give hassles too? If you get a quarter of a globe with texture I reckon you've probably got yourself 90% of the available marks for that part of it anyway. Hope it goes well.
Re: Assignment 2
September 14, 2011 03:10PM
@eddy - Is yours not rendering at all, although it all appears to be correct? When I get home later, I can post a few links that I used to get mine working, as well as a few checks you can do to see if you missing a setting or such in code.

And yeah, I'm using trig functions to try locate the correct position for the texture. I'll probably end up removing the texture, and just having a blue sphere, with lighting and everything else working - and if I end up with 60-70% for the assignment, I'll be happy with that.
avatar Re: Assignment 2
September 14, 2011 03:56PM
Hmm.. I think I might be "rendering" a uniform dark grey texture now.

I call my set texture function from points inside the display function, and "the lights go out". So something is happening.

If I put it where it seems it ought to belong (once off in init), it does nothing.

Could be that all I need to do is call the glEnable call, so I must do an experiment restoring things like setting up the matrix to where it makes sense to me, and then calling a reduced subset of the calls inside display. ... Yes, that sounds like what I'll do.

Also I must remove my own function for reading, and copy over the example function that Ben pointed us toward. That might help some.

As far as having both lights and textures goes? Maybe set the glMatrix to GL_TEXTURE and somehow transform that? ( in unison with your transformations of the lights that presumably are happening separately but in unison with your transformations of the position of the "Sun"winking smiley You had a pair of coupled transformations; now have triple.

Sorry I'm so far away from there now that I have but the vaguest notion.

Right now I'm about ready to settle for "something" for the assignment (that "something" being just about anything non-zero). My "clockwork" was sort of working, but has somehow gone and broken down, too.
avatar Re: Assignment 2
September 14, 2011 04:40PM
Update: @ InSaNiE, you know that delighted feeling one gets when one sees an ugly little bit of texture on just a quarter of your globe? ... Yeeeee Ha! It might look like crud, but it's Texture!! At long last, some texture.

The way this happened was by fixing the file IO. The IO suggested by Cunningham just didn't work for me. (It produced uniform grey, it turns out). As soon as I got round to doing things as suggested in the example Ben pointed us to, I got a quarter globe of texture of some sort.

I think I must switch spin off and examine it a bit more closely.

I have a weird quarter-textured globe. It's not a "quadrant", it's a "slice" (think segments of an orange to get the picture).

We're getting there, ja?

I think maybe it's painting itself "East to North" "West to South" for some reason. I'll pin it and have a good look. If so, the trick would be to swop the matrix dimensions? ... Hmm ... no this is looking like a lousy theory...
Anonymous User
Re: Assignment 2
September 14, 2011 05:21PM
Coming late to the party.

Eddy, if you're only seeing a slice or so of your globe textured, then it's (probably) because you file read width/height ratio is different from your file resolution. Easy way to check is to right click your image file, hit Properties -> Details and see what the resolution is (under Dimensions...obviously) and then make sure that where you read your file, you've set the parameters correctly. For example (I use the following snippet to read data from the raw file I created via Gimp and my file res is 768 x 384):

int width = 768;
int height = 384;

FILE * file;
file = fopen(filename, "r"winking smiley;
if(file == NULL)return 0;

data = (unsigned char *)malloc(width * height * 3);
fread(data, width * height * 3, 1, file);
blah blah blah OpenGL stuff that I probably shouldn't share blah blah

Hope that helps somewhat.

EDIT: Also worth noting is that, if your earth image looks like this:


You need to rotate it 180 degrees as well as flip it on the horizontal before reading it in as the reading method above results in a coordinate set that is nothing like what you might expect and will result in a mirror Earth image if you read it straight from the file without the manipulation.
Anonymous User
Re: Assignment 2
September 14, 2011 05:43PM
InSaNiE Wrote:
> @eddy - Is yours not rendering at all, although it
> all appears to be correct? When I get home later,
> I can post a few links that I used to get mine
> working, as well as a few checks you can do to see
> if you missing a setting or such in code.
> And yeah, I'm using trig functions to try locate
> the correct position for the texture. I'll
> probably end up removing the texture, and just
> having a blue sphere, with lighting and everything
> else working - and if I end up with 60-70% for the
> assignment, I'll be happy with that.

Trig functions are definitely not the way to go. If I may be so bold to say it, but you are going completely the wrong direction and making this much more difficult than it needs to be. Forget about the pointers given in the assignment question. Have a look at quadrics and gluSphere() (I know it sounds tricky, but it's not compared to three-dimensional geometry). If you really don't come right, I'll try to log in more often over the next two or three days to assist where I can (while finishing up my own assignment).

Good luck!

(Text can often come across as rude/smartass/overbearing, it is not my intent, just trying to point you in the right direction since I also struggled a lot initially).
avatar Re: Assignment 2
September 14, 2011 05:46PM
Thanks phyz. Arrived to report that a careful examination of my smudges reveals that I have 3 copies of the Earth on what might actually be a third of the sphere.

I was scratching my head about what to do about the image (which is inverted, of course)... And said "Doh" to myself (giving myself an old fashioned clip on the ear at the same time) when you gave the solution. Rotate it. ... "where?" .... «CLIP!!» ...

... Ah ha! In the Gimp or whichever. (My raw file is now displaying in triplicate, and that came from Irfanview).

++ And don't worry. You don't sound as rude and overbearing as you usually do. grinning smiley

I think you might've solved a mystery for InSaNiE too. No weirdness to do with the loss of signs.

It looks a bit like my red white and blue may have been separated out, though. I shall report back later in the night with the next exciting update.

++ Yet another Edit ====
6 Quad Strips textured with an Earth each (in grey) ... but only 1/3 (or maybe 1/4) of the Earth has these Earths.

I think the first problem there is that the glTexCoords are being set within

Language: C++
glBegin(GL_QUAD_STRIP) ... glEnd()

Strange, though. The book says if you specify that your bottom left (geometric) has texture coordinate (0.0, 0.5) that only the part of the texture starting there should be assigned. You can "cut out bits of texture". So surely the strips would each be given just a bit of texture?....
Re: Assignment 2
September 14, 2011 07:40PM
@phyz - thanks for the input, and no worries - you didn't come across as anything but helpful! And I do appreciate the input.

Are you suggesting abandoning using the pointers in the tutorial letter for the assignment, and to not use section 2.4.3 of Angel to draw the sphere, and use gluSphere instead? If so, I'm a bit hesitant to do that, as the question does say we "must do the following", and then goes on to list using 2.4.3 of Angel. (unless I misunderstood, which is entirely possible)

I'm currently stuck with two versions of my application:
  • Version 1: Blue sphere for an early, light working
  • Version 2: Texture semi working (not really, but I have some texturing) and light not working.
If all else fails, I'll submit version 1. But for now, I'll work on getting the texture working in version 2.

Assuming we do have to use 2.4.3 of Angel to draw the sphere, I need to work on getting the texcoords correct. I'm going to try that for a bit..
avatar Re: Assignment 2
September 14, 2011 07:50PM
One thing you might try with the combination of texture and lighting is fiddling with the opacity of your lights and your material light properties. I'm not sure if it helps, but it's something I've done, and I can see a bit of my spectacular specular on the sphere with the many grey Earths. ie. Lighting does seem to be working for me in combination with texture.

You might also want to have a squizz at page 416 ( just before the plates). I have a note that mentions that here, so it might be of some use. I have rubbish in my notes, too, obviously, but something rings a bell with that one. I'll try to remember to follow up.

I've tried various denominators with the fractions we're to assign, and managed to produce even more strips of Earth map. One can also make the third of the sphere they occupy split itself into two directly opposing 1/6 of a sphere slices. I've yet to reduce the number, though.
Anonymous User
Re: Assignment 2
September 14, 2011 08:24PM
Mmmm...I hear what you guys are saying re the pointers in the assignment. However, I'm of the opinion that they are more interested in the result than in the implementation (I may obviously be wrong) and my personal interpretation of the assignment question is that the "In particular" bit is the actual assignment and the rest are guidelines and hints.

Even doing it my way, I've worked too hard to start from scratch, so I'm sticking with that for now. What you could perhaps look into if you're going to go the "manual" sphere route is the glTexGeni function on p424...not sure if it will help, but mentioning it on the off chance that it turns out to be the final ingredient you're looking for.
avatar Re: Assignment 2
September 14, 2011 09:33PM
I think you might find taking the gluSphere route is a bit risky. I'm almost certain I've come across examples in which just about this exact problem was solved that way, and that they're not going to want lots of those arriving. Maybe if you get it all running nicely with your gluSphere, come back to the version me and InSaNiE (and ToXic, too, I think) have been torturing ourselves with. That would mean do it with triangle strips and quad strips, get its orientation right, and then do as you've suggested with the texture.

I think I have the glTexGeni command in there somewhere. The details of my texture handling are copied straight from Cunningham, almost. (Or maybe some website; I'm not sure any more).

Unless you end up pushed for time I reckon you should at least do Earth the painful way. I even had a Sun done the painful way for a while, although my present Sun goes all the way in the other direction, and is a glutSolidSphere (it has now vanished from my little world for some reason).

Anyway, I've arrived here to announce that I have a grey texture vaguely resembling the Earth on my sphere now. The tip for it is to make the best guess at the fraction of the globe your current effort is covering, and then to fiddle the fractions to give this currently covered part less of the texture (and hopefully then give what you've thus taken away here to the uncovered part there). The horrible thing about this is that the equations I used to make the partially textured Earth still make sense to me, and these equations that "work" do not.

OK. And I'll need to improve this to bring in the polar regions as full-on textured areas too, I think, if I look at that. Now one may ask, "but where are you going to get all your vertices for that?" I mean the only point you really add to the map up there is the Pole, right?

I think the answer is something to do with the difference between a vertex and a location in space. One location in Space (or if you want to confuse yourself, call it a "point"winking smiley can have as many vertices as you like mapped to it. I think that's what one would have to do. The Pole has the vertex mapped to TexCoord (0.0, 0.0) .. and so does the Pole have the vertex mapped to TexCoord (1.0, 1.0). One location in space; two different vertices. In fact more like ... 8? different vertices? Maybe more? Actually more like 18 I think it is.

Now if you'll pardon me I have to go and walk on that cloud again...
Re: Assignment 2
September 14, 2011 11:06PM
@phyz - thanks for the tip about the glTexGeni command, unfortunately it didn't seem to work (or I didn't implement it correctly)

I started from scratch, and tried to understand how the sphere was being drawn up. I finally understand how the sphere is being built up, but I still cannot seem to link the vertices to the coords in the texture. I''ve tried many things today, but still nothing. Well, not nothing, but I have a grey earth like map which covers the top 1/2 of the northern hemisphere of my globe. And lighting now working well at all.

I think I'll try one more time tomorrow evening, trying to understand the maths and the trig involved using the two angles. But its really beginning to get to me now, that this texture thing will just not work at all.

@eddy - And you are right about the poles having multiple texture coords mapped to it. I am under the impression that that is okay though, but as always, I could be wrong.

I'm calling it a night.
avatar Re: Assignment 2
September 15, 2011 12:41PM
If you're already using your poles in your texture calcs you have (part of) a nicer solution than me. At the moment my poles lack texture. Ja, I was trying to say that it's OK for this to be so back there. Point in space != vertex. I had to realise that to begin to realise that I can map to the poles.

OK as far as your half an Earth of texture goes, if you just fiddle the numbers a bit in a proportional way, you'll get your entire globe covered. Once you have some texture you're very close to having it all under texture.

Your texture map is being allocated to half the northern hemisphere. So you need to stretch it South and EastWest. What's happening? You reach 1.0, 1.0 half way through your angles (or whatever related thing you're using as a basis for your fractions). So by the time you reach zero degrees North to South or East to West on each of those you've reached X/X == 1. And what would you have liked to have reached at that point? x/X == 0.5, right? So fiddle with that fraction to make your answer 0.5, and see what happens... (ie. don't waste time on understanding it, just conduct trials grinning smiley )
Sorry, only registered users may post in this forum.

Click here to login