CollisionResponseAnimator -> change params

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
nero24
Posts: 3
Joined: Wed Nov 18, 2009 7:33 pm

CollisionResponseAnimator -> change params

Post by nero24 »

Hello everybody

i'm new to irrlicht and i have a favor t ask:

i started with the engine a few days ago and now i'm trying to write some new code in to example 7 -> collision

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

class MyEventReceiver : public IEventReceiver 
{ 
    public: 
    virtual bool OnEvent(const SEvent& event) 
        { 
        if (event.EventType == EET_KEY_INPUT_EVENT) 
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown; 
        return false; 
        } 
	virtual bool IsKeyDown(EKEY_CODE keyCode) const {return KeyIsDown[keyCode];} 
    MyEventReceiver(){for(u32 i=0; i<KEY_KEY_CODES_COUNT; ++i) KeyIsDown[i] = false;} 
  private: 
    bool KeyIsDown[KEY_KEY_CODES_COUNT]; 
};

int main()
{	
	video::E_DRIVER_TYPE driverType;

	printf("Please select the driver you want for this example:\n"\
		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
		" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
		" (f) NullDevice\n (otherKey) exit\n\n");

	char i;
	std::cin >> i;

	switch(i)
	{
		case 'a': driverType = video::EDT_DIRECT3D9;break;
		case 'b': driverType = video::EDT_DIRECT3D8;break;
		case 'c': driverType = video::EDT_OPENGL;   break;
		case 'd': driverType = video::EDT_SOFTWARE; break;
		case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
		case 'f': driverType = video::EDT_NULL;     break;
		default: return 0;
	}

	IrrlichtDevice *device =
		createDevice(driverType, core::dimension2d<u32>(640, 480), 16, false);

	if (device == 0)
		return 1;
	
	MyEventReceiver receiver;
	device->setEventReceiver(&receiver);

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");

	scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
	scene::IMeshSceneNode* q3node = 0;

	if (q3levelmesh)
		q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0), 0, 0);

	scene::ITriangleSelector* selector = 0;

	if (q3node)
	{
		q3node->setPosition(core::vector3df(-1350,-130,-1400));

		selector = smgr->createOctTreeTriangleSelector(
				q3node->getMesh(), q3node, 128);
		q3node->setTriangleSelector(selector);
	}
	
	scene::ICameraSceneNode* camera =
		smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, 1, 0, 0, true, 3.f);
	camera->setPosition(core::vector3df(50,50,-60));
	camera->setTarget(core::vector3df(-70,30,-60));

	if (selector)
	{
		scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
			selector, camera, core::vector3df(30,50,30),
			core::vector3df(0,-10,0), core::vector3df(0,30,0));
		selector->drop(); 
		camera->addAnimator(anim);
		anim->
		anim->drop();
	}

	device->getCursorControl()->setVisible(false);

	int lastFPS = -1;
		
	f32 then = (f32) device->getTimer()->getTime();

	const f32 MOVE_SPEED = 300.0f;

	while(device->run())
	if (device->isWindowActive())
	{
		f32 now = (f32) device->getTimer()->getTime(); 
		f32 deltaTime =	(now - then)/1000.0f;
		then = now;
		
		
		core::vector3df pos = camera->getPosition();

		core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition());
		core::vector3df relativeRotation = target.getHorizontalAngle();

		target.set(0,0, core::max_(1.f, pos.getLength()));
		core::vector3df movedir = target;

		core::matrix4 mat;
		mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0));
		mat.transformVect(target);

		mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0));
		mat.transformVect(movedir);

		movedir.normalize();
		
		if (receiver.IsKeyDown(KEY_KEY_W))
			pos += movedir * deltaTime * MOVE_SPEED;

		if (receiver.IsKeyDown(KEY_KEY_S))
			pos -= movedir * deltaTime * MOVE_SPEED;

		core::vector3df strafevect = target;
		strafevect = strafevect.crossProduct(camera->getUpVector());

		strafevect.Y = 0.0f;

		strafevect.normalize();

		if (receiver.IsKeyDown(KEY_KEY_A))
			pos += strafevect * deltaTime * MOVE_SPEED;

		if (receiver.IsKeyDown(KEY_KEY_D))
			pos -= strafevect * deltaTime * MOVE_SPEED;
			
		camera->setPosition(pos);

		target += pos;

		driver->beginScene(true, true, 0);
		smgr->drawAll();
	
		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw str = L"Collision detection example - Irrlicht Engine [";
			str += driver->getName();
			str += "] FPS:";
			str += fps;

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}

	device->drop();

	return 0;
}

i've started to include my own movement functions ok these ones are not from me but i included them by myself

and now i want that the player can crouch when he presses the c button on keyboard

my idea is it to change the ellipsoidtranslation from the collisionresponseanimator but i dunno how i can change this param do you have any ideas how i can do this or is there any other way how i can make the player crouch besides i dont want to change the camera it should be a smoove movement like the others moves

for example:

Code: Select all


if (receiver.IsKeyDown(KEY_KEY_C))
       anim.ellipsoidtranslation.y = crouch_speed * deltaTime * MoveSpeed;
or something like that ^^


thank you very much for ideas

and please be nice to mee im from germany and my english isnt the best

greetz nero[/code]
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You'll probably have to remove the current collision animator and add a smaller collision animator. Then do the opposite when the player stops crouching.
Image Image Image
nero24
Posts: 3
Joined: Wed Nov 18, 2009 7:33 pm

Post by nero24 »

thank you very much for your answer but i already tried this and it's like a heavy movement you can also switch the camera there is no difference

im sitting since sunday on this problem i could really cry T_T
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

well, you should make it like that:


if (receiver.IsKeyDown(KEY_KEY_C))
crouch=true;

And in the while loop: u put this:

Code: Select all

if(crouch==true)
{// here yopu will make the 3d mesh play the crouch animation
selector = smgr->createTriangleSelector(node);//new selector
        node->setTriangleSelector(selector);
        selector->drop(); 
speed*=c*speed //were c is the drop ratio of the speed


}crouch=false;
if its wrong tell me cuz i really dont understand what is your problem
Post Reply