collision camera and model, model->setVisible(false)

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
ijo coim
Posts: 57
Joined: Fri Mar 25, 2005 1:29 pm
Location: indonesia, jogja-jogja

collision camera and model, model->setVisible(false)

Post by ijo coim »

HI,

i am still confused with collision code.

i have camera and faerie. what i want is after the camera through the faerie, faerie get lost (faerie->setVisible(false)).

have any idea?


thx.

ijo coim
Guest

Post by Guest »

Simplest way would be to use distance rather than collision. Something like this:

Code: Select all

vector3df cameraPosition = cameraNode.getPosition();
f32 distance = cameraPosition.getDistanceFrom(faerie.getPosition());
if (distance < 80.0f)
{
    faerie->setVisible(false);
}
Set the distance to whatever the collision radius is. This way you don't need to worry about messing with collisions.
ijo coim
Posts: 57
Joined: Fri Mar 25, 2005 1:29 pm
Location: indonesia, jogja-jogja

it work

Post by ijo coim »

hey, it work.

thx guest.

when i compile the program, the faerie get lost (faerie->setVisible(false).

from here, i know if the code is work.

now, i must make a funtion, if the camera come to faerie, faerie get lost.


thx once again guest.


ijo coim.
ijo coim
Posts: 57
Joined: Fri Mar 25, 2005 1:29 pm
Location: indonesia, jogja-jogja

it really2 work

Post by ijo coim »

guest, it really2 work. i use a boolean function to test this code. maybe another can use this code too. here it is :
1.declare an bool

Code: Select all

bool tabrak_2=false;
2. in event receiver, make the bool work, if right click is click:

Code: Select all

class MyEventReceiver : public IEventReceiver{
public :
	virtual bool OnEvent(SEvent event){

	if(event.EventType==irr::EET_MOUSE_INPUT_EVENT && 
			event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)
		{
		tabrak_2=!tabrak_2;
		return true;
		}


		return false;
	}
}
;


3.tell the device

Code: Select all

MyEventReceiver terima;
	IrrlichtDevice *device =
		createDevice(driverType, core::dimension2d<s32>(512, 384), 16, false,false,false,&terima);
	
4. in loop, give the GUEST'S code :

Code: Select all

while(device->run())
	if (device->isWindowActive())
	{
		driver->beginScene(true, true, 0);
		smgr->drawAll();

		if(tabrak_2)
		{
		
		// buat tabrakan dengan mesh dan kamera
	vector3df cameraPosition = node_coba->getPosition(); 
	f32 distance = cameraPosition.getDistanceFrom(node_coba->getPosition()); 
	if (distance < 10.0f) 
		{ 
			node_coba->setVisible(false); 
		} 
		

		}

.
.
.

thx.

regards,
ijo coim
Post Reply