virtual city?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
HIM
Posts: 13
Joined: Sat Dec 20, 2003 12:22 am
Location: Stockholm, Sweden
Contact:

virtual city?

Post by HIM »

Hi
I'm trying to create a virtual city, not an extremly detailed one how ever. But a bunch of houses that looks sort of difirent, perhaps a small park.

Then I'm planning to add a character in 3rd persion perspective that can walk throught the city. But I've encountered a couple of problems.

One: how do I create the city? should I create one with a quake level editor and load that as a mesh?? or perhaps create a big height mat that represent the buildings??

Two: how the heck do I create the 3rd person perspective?? I've tried the examples that people have posted on the forum, but can't get them to work in a good properly. The biggest problem is of course to make sure that the camera doesn't vanish through the walls.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

first, you should NOT use a height map for your buildings, as it is not easy to texture faces which dont have an 'upward' facing in a height map without some tricks. Use GtkRadiant to make a BSP.

For camera work, look at the Techdemo code. It has a user-controled FPS camera which has collision detection between it and the BSP level.
cochi_

Post by cochi_ »

3rd person camera isn't so difficult, i dont understand why people always have problems with it. ok, i didn't try the most obvious way yet (setting the parent element of the camera as your characters mesh). i currently define an "offset" of the camera (e.g. vector3df(0,30,30)), set the camera target to my characters object and upon rotation using e.g. the cursor keys i rotate the offset of the camera using matrix4. then i set the position of the character plus the offset.

Your camera-"ghost" problem can be fixed by tieing a collision animator to the camera exactly the same way as you do with meshes. simply copy the instruction and substitute your character mesh's object by the ICameraSceneNode object.

Done ;)
HIM
Posts: 13
Joined: Sat Dec 20, 2003 12:22 am
Location: Stockholm, Sweden
Contact:

Post by HIM »

cochi_ wrote:i currently define an "offset" of the camera (e.g. vector3df(0,30,30)), set the camera target to my characters object and upon rotation using e.g. the cursor keys i rotate the offset of the camera using matrix4. then i set the position of the character plus the offset.
That's a nice tip... but I was wondering if you perhaps have any example code?? I can't get the offset matrix to work for me...
ErMurazor
Posts: 37
Joined: Sat Dec 13, 2003 2:00 pm
Location: Sweden
Contact:

Post by ErMurazor »

I also would be very pleased for some code example. My 3rd person view work except for the rotation matrix.
HIM
Posts: 13
Joined: Sat Dec 20, 2003 12:22 am
Location: Stockholm, Sweden
Contact:

Post by HIM »

I've managed to position the camera properly. But for some reason it looks at my models feet. Thats kind of odd. Right?
HIM
Posts: 13
Joined: Sat Dec 20, 2003 12:22 am
Location: Stockholm, Sweden
Contact:

Post by HIM »

Now the camera is working quite good. Some details remains. One thing is that it sticks extremly well behind the character. I would prefer to have it like the camera in GTA: vice city. Its a little slower than the character.

But I've discovered that my character isn't moving forward in relation to the object. But instead moving in relation to the game world. No matter how much i try to change the rotation of the object it still moves the wrong way.

I'm posting my movement and perhaps some one can see what I'm doing wrong.

Code: Select all

bool CCity::OnEvent(SEvent event)
{

	if (event.EventType == EET_KEY_INPUT_EVENT)
	{
		if (event.KeyInput.Key == KEY_ESCAPE && !event.KeyInput.PressedDown )
		{
			device->closeDevice();
			return true;
		}
		if(event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
			case KEY_KEY_S:
				hero_position = hero->getPosition();
				hero_position.X += event.KeyInput.Key == KEY_KEY_W ? (100 * timeFactor) : -(100 * timeFactor);
				hero->setPosition(hero_position);
				break;
			case KEY_KEY_A:
			case KEY_KEY_D:
				core::matrix4 hero_rotation_degrees;
				hero_rotation = hero->getRotation();
				hero_rotation.Y += event.KeyInput.Key == KEY_KEY_D ? -(100 * timeFactor) : (100 * timeFactor);
				hero_rotation_degrees.setRotationDegrees(hero_rotation);
				hero->setRotation(hero_rotation);
				break;
			}
		}
		return true;
	}
	return false;
}
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

HIM wrote:But I've discovered that my character isn't moving forward in relation to the object. But instead moving in relation to the game world. No matter how much i try to change the rotation of the object it still moves the wrong way.
based on the code you posted the character should move in the world Y direction and X direction.. but this isn't what you want? if you want the character to move based on which way the camera is facing then simply do

Code: Select all

vector3df dir = activeCamera->getTarget() - activeCamera->getPosition();
dir.normalize();
charater->setPosition( character->getPosition() + dir*scaling_factor );
if you want to keep the object from moving up or down then set dir.Y = 0 .. hope this helps!
Phunk
Posts: 78
Joined: Sun Dec 14, 2003 8:18 pm
Location: The Netherlands

Post by Phunk »

maybe some useful tips: I created a cam in irrlicht myself, like the fps with an other way to lokkt with the cam(not with the mouse). in the source code of irrlicht self I saw that cams and other things not are moved directly by the event receiver. It just flags for a button pressed or so. The real animations is done in the while(device->run) loop. to make it smooth. If you do this also with your cam, it increases the posibilities to animate the cam(and create smooth movement)
you could do for example, that the cam moves to a point behind the player, instead of fixing it on a position relative to the payermodel(just let the target be aimed at the playermodel, and let the cam move to its new position on its own) this way you would have a smooth cam, that is flexible.
and ow yeah, settarget() can be not working properly with some cams
hope this is any help
greets, Robin
(and oh yeah, it does require some recoding, but you'll have much advantage of it later, see how its done in the source of the fpscam)
HIM
Posts: 13
Joined: Sat Dec 20, 2003 12:22 am
Location: Stockholm, Sweden
Contact:

Post by HIM »

I don't really want to change the irrlicht source... Is there perhaps a way of inheriting the ICamera class so I can "create a new camera" without changing the acctual source of irrlicht??
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Yes you can just inherit from ICameraSceneNode if you want. You'll probably end up copying much of your code from CCameraSceneNode, so you wouldn't be modifying the Irrlicht source but it would still be based on it.

The way I handle my camera is to have a CameraControl object, which contains just a standard ICameraSceneNode (created using smgr->createCameraSceneNode()), and some other properties I need to use that the camera doesn't store (such as current location relative to player). You could add other properties to this as well, such as max camera movement speed, current speed, current preferred position relative to player, current position relative to player, to animate camera movement at a rate different than the player's movement. You would have to call a method each game loop to update the camera's position.

A third option is to create a new SceneNodeAnimator for a third person camera, which would have the properties mentioned above. Then just attach the animator to the camera.

So you have lots of options. The only real difference is which way you would like to view your camera control (directly in the camera, a controller for the camera, or an animator for the camera).
Post Reply