PHP

search for


Last updated: Wed, 10 Dec 2008

CheckForCollision

IrrLib 1.X

CheckForCollisionChecks if 2 Irr2DObj or Irr3DObjects collided

Description

int CheckForCollision ( )

Parameters

None

Return Values

Number of hits

Examples

Example #1 This is a live example showing a ball bounce between 2 squares.

#include <iostream>
#include "IrrLib.h"
#include <irrlicht.h>
 
using namespace std;
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
int main(){
	IrrLib Irrlicht(5, 640, 480, 16, false, true, false);
	Irr3DObjColor col1;
	Irr3DObjColor col2;
	int vel = 1;
	int nHits;
	//int nTimes = 0;
 
	//Color 1
	col1.a = 255;
	col1.r = 0;
	col1.g = 255;
	col1.b = 5;
 
	//color 2
	col2.a = 255;
	col2.r = 0;
	col2.g = 255;
	col2.b = 255;
 
	//Pos 1
	Irr3DPos pos1;
	Irr3DPos pos2, pos3;
 
	pos3.x = -200;
	pos3.y = 0;
	pos3.z = 0;
 
	pos2.x = 200;
	pos2.y = 0;
	pos2.z = 0;
 
	pos1.x = 0;
	pos1.y = 0;
	pos1.z = 0;
 
    Irr3DObj obj1;
    obj1->setColor(col1);
    obj1->setMesh("sphere.3ds");
	Irr3DObj obj2, obj3;
	obj3->setMesh("cube.3ds");
	obj2->setMesh("cube.3ds");
	obj2->setColor(col2);
	obj3->setColor(col2);
	obj1->addToScene();
	obj2->addToScene();
	obj3->addToScene();
	Irrlicht.AddFPSCam();
    obj2->Move(pos2);
    obj3->Move(pos3);
	while (Irrlicht.DeviceIsRunning())
	if (Irrlicht.IsActiveWindow())
	{
	    pos1.x = pos1.x + vel;
	    obj1->Move(pos1);
	    nHits = CheckForCollision(obj1,obj2);
	    if (nHits > 0)
	    {
	        vel = vel * -1;
	    }
	    nHits = CheckForCollision(obj1,obj3);
        if (nHits > 0)
	    {
	        vel = vel * -1;
	    }
        Irrlicht.BeginScene(Irrlicht.Color.RED);
        Irrlicht.DrawAll();
        Irrlicht.EndScene();
        nHits = 0;
	}
	Irrlicht.EndIrrlicht();
	return 0;
}
 

You can find the meshes used in this example here.

Notes




Last updated: Wed, 10 Dec 2008
User Contributed Notes
CheckForCollision
Your name(or email):
Comment:
Security Code: CAPTCHA ImageReload Image