Problem in tutorial 1

Started by
12 comments, last by nefthy 18 years ago
Well when I said to use code, I meant that you would be using texture maps, otherwise you'll never finish the project [wink]. Essentially what you would do is see if you can get an aerial shot of your campus or a blueprint/landscape layout diagram would be even better. From your drawings you can then plan where you are going to put your buldings and if you have height data then you can decide how tall they are going to be. If you don't have any of this data then it's more difficult but a good guess can look just as convincing as real data in terms of sizing.

Once you have your rough size data then you would create cuboids (blocks) to make up the buldings, I'm not sure what average buildings look like in Malaysia so I'm going to use an example of a typical house from here in Scotland (very boxy). First you would use some vertices to define the shape of the box, for example:
glBegin(GL_QUADS);	// front face	glVertex3f(-10.0f, -10.0f,  10.0f);	glVertex3f( 10.0f, -10.0f,  10.0f);	glVertex3f( 10.0f,  10.0f,  10.0f);	glVertex3f(-10.0f,  10.0f,  10.0f);	// left face	glVertex3f(-10.0f, -10.0f, -10.0f);	glVertex3f(-10.0f, -10.0f,  10.0f);	glVertex3f(-10.0f,  10.0f,  10.0f);	glVertex3f(-10.0f,  10.0f, -10.0f);	// right face	glVertex3f( 10.0f, -10.0f,  10.0f);	glVertex3f( 10.0f, -10.0f, -10.0f);	glVertex3f( 10.0f,  10.0f, -10.0f);	glVertex3f( 10.0f,  10.0f,  10.0f);	// back face	glVertex3f( 10.0f, -10.0f, -10.0f);	glVertex3f(-10.0f, -10.0f, -10.0f);	glVertex3f(-10.0f,  10.0f, -10.0f);	glVertex3f( 10.0f,  10.0f, -10.0f);	// top face	glVertex3f(-10.0f,  10.0f,  10.0f);	glVertex3f( 10.0f,  10.0f,  10.0f);	glVertex3f( 10.0f,  10.0f, -10.0f);	glVertex3f(-10.0f,  10.0f, -10.0f);	// bottom face	glVertex3f( 10.0f, -10.0f,  10.0f);	glVertex3f( 10.0f, -10.0f, -10.0f);	glVertex3f(-10.0f, -10.0f, -10.0f);	glVertex3f(-10.0f, -10.0f,  10.0f);glEnd();


Now this will define you a box that looks something like this (I've overlayed triangles so don't worry about that):
A picture of an untextured cube

Now that you have your box you would then go and take some pictures of the building it represents from the sides and so on, trying to get as 'face on' (square to) as you can. Now it's snowing and miserable outside my house at the moment so I've drawn a picture of the front of a house instead of taking a picture, excuse my poor artistic skills:
A picture of the front of a house (badly drawn)

Now you need to apply this image to your box for your building. To do this you use texture co-ordinates, I explained them to someone else earlier so I will just point you towards the thread for that information, clicky. So let's put the texture on the front face only, just to demonstrate the effect:
glBegin(GL_QUADS);	// enable texturing so that we can see our texture	glEnable(GL_TEXTURE_2D);	// now bind the texture id (I assume you know how to do this from your other thread)	glBindTexture(GL_TEXTURE_2D, an_example_id_for_your_texture);	// front face	glTexCoord2f(0.0f, 0.0f);	glVertex3f(-10.0f, -10.0f,  10.0f);	glTexCoord2f(1.0f, 0.0f);	glVertex3f( 10.0f, -10.0f,  10.0f);	glTexCoord2f(1.0f, 1.0f);	glVertex3f( 10.0f,  10.0f,  10.0f);	glTexCoord2f(0.0f, 1.0f);	glVertex3f(-10.0f,  10.0f,  10.0f);	// now we disable texturing as we only have the front face's texture so far	glDisable(GL_TEXTURE_2D);	// rest of code the sameglEnd();


The building now looks like this:
A picture of a cube with the front face textured

As you can see, all this takes a long time, and this is just for one building! If you have a lot of buildings to do, especially if they're not rectangular in shape as well, then it's going to take you a very long time indeed. Also, if you want lights in your scene then you will need to specify normals for each point as well.

I hope this helps to clarify what I was talking about.
--
Cheers,
Darren Clark
Advertisement
[wow] this is what i want to do for my project, u did really helps me a lot, to build up my ideas and conceptual of the development of building blocks, hehe sure rate for u!!

From my friend of engineering student, they have drawing the map of my campus, so i can get from them, that will be more time saving for me... Thanks Darren
As an alternative, you could cast your string to a LPCWSTR.

Let's say you've got c_str myString.

The function

open(myString);

gives you a compile error. Instead use

open((LPCWSTR)myString);

A superfluous post? Perhaps. But this will work if you don't want to or can't change your settings.
A little advise from me too. If you are confident with plain C, use C instead of C++. It will save you some time. Unless you _have_ to use C++, that is.

Also about using Models from an external program, I don't think that this would be a problem, since displaying models is a bit more complicated, from a software engineering point of view, compared to drawing some textured quads. But check with your teachers to be sure.

This topic is closed to new replies.

Advertisement