Basic Matrix Math

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
t
Posts: 43
Joined: Sun Nov 02, 2003 2:59 am
Location: Australia

Basic Matrix Math

Post by t »

Hello,
In my game I have a ship. The camera is behind the ship on the Z axis. I want to project a point forward from the ship by a certain amount, so I can place the gun turret bitmap in the right spot.

Code: Select all

	core::position2d<s32> pos;
	

		core::vector3df Target; 
		core::matrix4 mat; 

		Target.set(Player.shipnode->getPosition());
		
		mat.setRotationDegrees(Player.shipnode->getRotation()); 
		mat.transformVect(Target); 
		
		Target.normalize(); 

	    Target.setLength(10);
	

		pos =  smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
			 Player.shipnode->getPosition()  + (Target) ,NULL);

		pos.X += -16;
		pos.Y += -16;

			
driver->draw2DImage(images, 
			core::position2d<s32>(pos.X,pos.Y),
		core::rect<s32>(10,10,65,65),
		0,
		video::SColor(255,255,255,255), 
		true);

But this isn't working. Can anyone tell me how to do the matrix math? I need to get the point that is, say , 10 units infront of the ship, taking into account the ship's rotation.
t
Posts: 43
Joined: Sun Nov 02, 2003 2:59 am
Location: Australia

Post by t »

I also tried this

Code: Select all

	core::position2d<s32> pos;
	

		core::vector3df Target; 
		core::matrix4 mat; 
	
		Target.set(Player.shipnode->getPosition());

		Target.Z += 15;

        Target.rotateXZBy(Player.shipnode->getRotation().Y, Player.shipnode->getPosition()); 
	   
		pos =  smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
			Target ,NULL);

		pos.X += -16;
		pos.Y += -16;

			
driver->draw2DImage(images, 
			core::position2d<s32>(pos.X,pos.Y),
		core::rect<s32>(10,10,65,65),
		0,
		video::SColor(255,255,255,255), 
		true);
t
Posts: 43
Joined: Sun Nov 02, 2003 2:59 am
Location: Australia

Post by t »

ok.. got it working.. i think.

Code: Select all

		core::position2d<s32> pos;

		core::vector3df Target; 

		Target.set(0,0,150);

		if (Player.shipnode->getRotation().Y != 0)
		{
					Target.rotateXZBy(-Player.shipnode->getRotation().Y, core::vector3df(0,0,0) ); 
		}

		Target.rotateYZBy(Player.shipnode->getRotation().X, core::vector3df(0,0,0));


		pos =  smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(
			Player.shipnode->getPosition() + Target ,NULL);

		pos.X += -16;
		pos.Y += -16;

			
driver->draw2DImage(images, 
			core::position2d<s32>(pos.X,pos.Y),
		core::rect<s32>(10,10,65,65),
		0,
		video::SColor(255,255,255,255), 
		true);


Post Reply