Lots of errors

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.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You are defining all of these variables in shared.h, so every file that includes that file gets a definition. When the linker combines the object files, it sees multiple definitions, which is forbidden.

You need to provide definitions for in one source file. I suggest you modify shared.h to look like this...

Code: Select all

// ...

#include <irrlicht.h>

using namespace irr; 
using namespace core; 
using namespace scene; 
using namespace video; 
using namespace io; 
using namespace gui; 
using namespace irrklang; 

namespace api 
{ 
   extern SIrrlichtCreationParameters params; 
   extern IrrlichtDevice *device; 
   extern ISoundEngine* engine; 
   extern IVideoDriver* driver; 
   extern ISceneManager* smgr; 
   extern IGUIEnvironment* guienv; 
   extern ITimer* pTimer; 
   extern u32 uLastTime; 
   extern ICameraSceneNode* camera; 
   extern u32 uCurrentTime; 
   extern u32 uElapsedTime; 
} 

// ...
Then make a shared.cpp that looks something like this...

Code: Select all

#include "shared.h"

namespace api 
{ 
   SIrrlichtCreationParameters params; 
   IrrlichtDevice *device = 0; 
   ISoundEngine* engine = 0; 
   IVideoDriver* driver = 0; 
   ISceneManager* smgr = 0; 
   IGUIEnvironment* guienv = 0; 
   ITimer* pTimer = 0; 
   u32 uLastTime = 0; 
   ICameraSceneNode* camera = 0; 
   u32 uCurrentTime = 0; 
   u32 uElapsedTime = 0; 
} 
If you are interested in some feedback, I've got a few suggestions.
  1. Avoid using global variables, if you really need them, wrap them up in an object and pass that around, make it global, or use a singleton/monostate pattern.
  2. Don't put using namespace clauses in headers.
  3. Read a C++ book.
Travis
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

Read a C++ book
i suggest professional c++ by Nicholas A.Soltar
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

why are you telling me to buy a c++ book?
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Because I suggested you read a C/C++ book. You seem to have a poor understanding of the language, and carefully reading such a book would be more productive than writing a ton of code that doesn't compile or link.

Travis
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

OK I got a book called "Programming Practice and Principles Using C++" which is written by Bjarne Stroustrup, the original designer/implementer of C++ and it is very interesting and educational, I have already learnt a lot about the basic stuff that I didn't know already.

Now I would like help with something else. I copied the event receiver from the Irrlicht forums, and I use it to see if the user is pressing any keys, when they press the W or the S key, then the camera should move forward and backwards accordingly, but the way I'm doing it, it doesn't. All the stuff with the vDirectionVector and mTransVector is for moving the camera relative to the camera's rotation. Can someone please look at my code and tell me what I am doing wrong?

Thanks for your time :)

This is the code for movement, my camera is created by addCameraSceneNode()

Code: Select all

VEC_T vDirectionVector = api::camera->getRotation();
	if(api::receiver.IsKeyDown(KEY_KEY_W))
	{
		matrix4 mTransVector = api::camera->getAbsoluteTransformation(); 
		mTransVector.rotateVect(vDirectionVector); 
		api::camera->setPosition
			(api::camera->getPosition() + VEC_T(vDirectionVector.X,0,vDirectionVector.Z)); 
	}
	if(api::receiver.IsKeyDown(KEY_KEY_S))
	{
		matrix4 mTransVector = api::camera->getAbsoluteTransformation(); 
		mTransVector.rotateVect(vDirectionVector); 
		api::camera->setPosition
			(api::camera->getPosition() - VEC_T(vDirectionVector.X,0,vDirectionVector.Z)); 
	}
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

I also need to know how rotate the camera depending on how to mouse moves, like the camera created by addCameraSceneNodeFPS()

Can someone tell me?
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Is there some reason you can't just use the existing FPS camera, maybe using a keymap? To answer your question, search the forums. It should only take a few minutes to find something.

Travis
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

I just really don't want to use it.
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Great. Since the FPS camera scene node is pretty much exactly what you want, but you don't want to use it, you can copy the FPS camera animator code from CSceneNodeAnimatorCameraFPS.cpp into your own animator or camera class and modify it as you see fit.

Travis
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

Thanks, I have my character moving properly now.
I need help with my Zombie AI now, this is what I think my code should do:

1. Position the current zombie(tZombies[nZombie_counter]) at the player
2. Rotate him/her to a random angle along the Y axis.
3. Move him/her forward to a random co-ordinate(his Z pos + randint(100-200))

And It doesn't work. I have been trying to fix this problem for 2 days now, and with no success.

This is the relevant code:

Code: Select all

void api::C_MainController::Update()
{
	if(nZombie_counter >= MAX_ZOMBIES)
		nZombie_counter = 0;

	if(!tZombies[nZombie_counter]->GetNode()->isVisible()
		/*&& tZombies[nZombie_counter]->ShouldSpawnAgain()*/)
	{
		tZombies[nZombie_counter]->GetNode()->setPosition(api::camera->getPosition());
		tZombies[nZombie_counter]->GetNode()->setRotation(vec_t(0,0,0));

		tZombies[nZombie_counter]->GetNode()->setRotation(vec_t(
				tZombies[nZombie_counter]->GetNode()->getRotation().X,
				randint(0,360),
				tZombies[nZombie_counter]->GetNode()->getRotation().Z));

		tZombies[nZombie_counter]->GetNode()->setPosition(vec_t(
			tZombies[nZombie_counter]->GetNode()->getPosition().X,
			tZombies[nZombie_counter]->GetNode()->getPosition().Y,
			randint(100, 200)) + tZombies[nZombie_counter]->GetNode()->getRotation());
		
		tZombies[nZombie_counter]->Spawn();
		nZombie_counter++;
	}

	for(int i=0;i<MAX_ZOMBIES;i++)
	{
		if(tZombies[i]->GetNode()->isVisible())
			tZombies[i]->Update();
	}
}
You help will and has been appreciated : )
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Your code appears to match your requirements exactly. You say it doesn't work, but you don't describe what it does that is wrong. Do you want your zombies to always spawn on the same side of the camera regardless of the direction that the camera is facing? That is wht your code appears to do.
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

what the zombies do is they all spawn in the same place, a little bit further on the z azis then the player, then they do their Update() thing which is to move towards the player.
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

      tZombies[nZombie_counter]->GetNode()->setPosition(vec_t( 
         tZombies[nZombie_counter]->GetNode()->getPosition().X, 
         tZombies[nZombie_counter]->GetNode()->getPosition().Y, 
         randint(100, 200)) + tZombies[nZombie_counter]->GetNode()->getRotation()); 
You're adding a position and a rotation. This is not valid, and is not going to get you the behavior you want.

It appears that you want to move the zombie to some position that is between 100 and 200 units from the player in any direction. You could simplify your code greatly by using a matrix.

I think this should work.

Code: Select all

scene::ISceneNode* zombie = tZombies [nZombie_counter]->GetNode();

// set the zombie to have a random rotation on Y
zombie->setRotation(vec_t(0.f, randint(0, 360), 0.f));
zombie->updateAbsolutePosition();

// pick a random offset vector
core::vector3df offset (0.f, randint(100, 200), 0.f);

// rotate the offset vector so it is in line with the direction the zombie is facing
zombie->getAbsoluteTransformation().rotateVect(offset);

// move the zombie offset units from the camera position
zombie->setPosition(api::camera->getAbsolutePosition() - offset);
Last edited by vitek on Wed Sep 30, 2009 5:06 am, edited 1 time in total.
tomtetlaw
Posts: 110
Joined: Sun Jul 05, 2009 9:57 am

Post by tomtetlaw »

When I run it, I get this error:

c:\documents and settings\tom\my documents\visual studio 2008\projects\irrlicht game engine\irrlicht game engine\c_maincontroller.cpp(42) : error C2039: 'updateAbsoluteTransformation' : is not a member of 'irr::scene::IAnimatedMeshSceneNode'
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Fixed. Please note, I said this should work. I don't always have time or access to the necessary tools to test code, so what you see is what you get.

Travis
Post Reply