Very basic collision detection I needed emergencly

#1

Hi guys i want really really basic collision detection. Im using old opengl (Glut)
So i implemented my game engine dynamic shadows,obj loader,bmp loader but something wrong i was passing from walls. So I tried to write really basic collision detector but not work as expected:

    void distance(float x1, float y1,
	float z1, float x2,
	float y2, float z2)
{
	float d = sqrt(pow(x2 - x1, 2) +
		pow(y2 - y1, 2) +
		pow(z2 - z1, 2) * 1.0);

	if(d = x2,y2,z2) {
		x2--;
		//y2--;
		z2--;
		std::cout << std::fixed;
		cout << " Colission Enter " << d;
	}

	return;
}

But my code is bad and only gets collision from one axis. I asked in stackoverflow but i dont get any answers so my last choice Khronos forums :slight_smile:

So thanks for all answers :slight_smile:

Also your code can be buggy no problem i accept everything.
I dont want use physics libraries so complex .

#2

It not works i saw a new example on internet i tried it not works

I now trying it

void collideit(int x,int y,int z,int x2, int y2, int z2) {

if ((x >= cx && x2 <= cmx) &&
	(y>= cy && y2 <= cmy) &&
	(z >= cz && z2 <= cmz)) {

	// collision repositioning
	x2--;
	y2--;
	z2--;
}
else {
	
}

but it not working so needed help emergencly

#3

why no one helping me
just help me okie

#4

At the end of the day, you’ve asked your question on an OpenGL forum. OpenGL is a rendering API; it doesn’t (typically) do collision detection. Yes, many OpenGL applications also need collision detection, but that’s typically separate from the process of rendering. And OpenGL is about rendering.

So you’re asking in the wrong place.