ICameraSceneNode XYZ position

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
bronxbomber92
Posts: 27
Joined: Mon Oct 30, 2006 11:55 pm

ICameraSceneNode XYZ position

Post by bronxbomber92 »

Hey, I'm simply trying to acces and change the camera's Y coordinate. How do I do this?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You call ISceneNode::setPosition(). It takes a vector that represents the 3d position relative to the parent. If you wanted to move the camera up one unit, you would write this...

Code: Select all

core::vector3df pos = cam->getPosition();
pos.Y += 1.f;
cam->setPosition(pos);
bronxbomber92
Posts: 27
Joined: Mon Oct 30, 2006 11:55 pm

Post by bronxbomber92 »

Thanks!

I've got another question :p

I'm trying to set really simple jumping this:

Code: Select all

void CJump::initPhysics() {
	
	jumping = false;
	falling = false;
	jumpSpeed = 10.0;
	gravity = 230.0;
	
}

void CJump::jump() {
	
	
	if ((event.EventType == EET_KEY_INPUT_EVENT &&
		 event.KeyInput.PressedDown == true) )
	{
		switch( event.KeyInput.Key ) {
			case KEY_SPACE:	
				if( jumping == false ) {
					jumping = true;
				}
		}
	}
	
	if( jumping == true ) {
		jumpSpeed -= 0.5;
		gravity -= jumpSpeed;
		
	}
	
	if( gravity < 0 ) {
		falling = true;
		jumping = false;
	}
	
	if( (gravity < 230) && (falling == true) )
		gravity += (jumpSpeed + 3);
	
	if( gravity == 230 ) {
		jumpSpeed = 10;
		jumping = false;
		falling = false;
	}
	
	if( gravity > 230 )
		gravity = 230;
	
	vector3df pos = GCamera::getCamera()->getPosition();
	pos.Y = gravity;
	GCamera::getCamera()->setPosition(pos);
	
}
But it doesn't work. Is it my input? I once tried shooting, and that too did not work. Am I doing the user input in correctly?
trooper
Posts: 85
Joined: Fri Nov 03, 2006 7:34 pm
Location: Maryland, USA
Contact:

Post by trooper »

Hey There.

Can't say I've tested this, but using this :
pos.Y = gravity;
GCamera::getCamera()->setPosition(pos);
Is just going to make the camera jump 'straight' to a position, rather than gracefully move.

gravity can be set in the 'createCollisionResponseAnimator' :wink:

Code: Select all

// create collision response animator and attach it to the camera
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(60,100,60),
		core::vector3df(0,0,0), // set (0,-1,0) for gravity
		core::vector3df(0,50,0));
	camera->addAnimator(anim);
	anim->drop();
You scratch my back, I'll scratch yours.
Post Reply