newton collision

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
mrbig
Posts: 29
Joined: Wed Mar 17, 2004 5:38 am
Location: lakeland, Florida
Contact:

newton collision

Post by mrbig »

my boxes are not hitting the map or eney of the other objects on the map
they don't fall throu the floor but they like stop above the floor
Image

Code: Select all

video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* sm = device->getSceneManager();
	quakeLevelMesh = sm->getMesh("stage1.bsp");;
	
	if (quakeLevelMesh)
		quakeLevelNode = sm->addOctTreeSceneNode(quakeLevelMesh->getMesh(0));
	NewtonCollision *g_newtonmap = NewtonCreateTreeCollision(nWorld, NULL);
	NewtonTreeCollisionBeginBuild(g_newtonmap);
	int cMeshBuffer, j;
	int v1i, v2i, v3i;
	scene::IMeshBuffer *mb;

	float vArray[9]; // vertex array (3*3 floats)

	int tmpCount = 0;

	for (cMeshBuffer=0; cMeshBuffer<quakeLevelMesh->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
	{	
		mb = quakeLevelMesh->getMesh(0)->getMeshBuffer(cMeshBuffer);

		video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices();

		u16* mb_indices  = mb->getIndices();

		// add each triangle from the mesh
		for (j=0; j<mb->getIndexCount(); j+=3)
		{
			v1i = mb_indices[j];
			v2i = mb_indices[j+1];
			v3i = mb_indices[j+2];
	
			vArray[0] = mb_vertices[v1i].Pos.X;
			vArray[1] = mb_vertices[v1i].Pos.Y;
			vArray[2] = mb_vertices[v1i].Pos.Z;
			vArray[3] = mb_vertices[v2i].Pos.X;
			vArray[4] = mb_vertices[v2i].Pos.Y;
			vArray[5] = mb_vertices[v2i].Pos.Z;
			vArray[6] = mb_vertices[v3i].Pos.X;
			vArray[7] = mb_vertices[v3i].Pos.Y;
			vArray[8] = mb_vertices[v3i].Pos.Z;

			NewtonTreeCollisionAddFace(g_newtonmap, 3, (float*)vArray, 12, 1);
		}

	}
	NewtonTreeCollisionEndBuild(g_newtonmap, 0);
	NewtonBody *g_newtonmapbody = NewtonCreateBody(nWorld, g_newtonmap);
// set the newton world size based on the bsp size
	float boxP0[3]; 
	float boxP1[3]; 
	float matrix[4][4]; 
	NewtonBodyGetMatrix (g_newtonmapbody, &matrix[0][0]); 
	NewtonCollisionCalculateAABB (g_newtonmap, &matrix[0][0],  &boxP0[0], &boxP1[0]); 
	// you can pad the box here if you wish
	//boxP0.y -= somevalue; 
	//boxP1.y += somevaluef; 
	NewtonSetWorldSize (nWorld, (float*)boxP0, (float*)boxP1);
			if (quakeLevelNode)
		{
			quakeLevelNode->setPosition(core::vector3df(-1300,-70,-1249));
			quakeLevelNode->setVisible(true);
			
			// create map triangle selector
			mapSelector = sm->createOctTreeTriangleSelector(quakeLevelMesh->getMesh(0),
				quakeLevelNode, 128);

			// set additive blending if wanted
			if (additive)
				quakeLevelNode->setMaterialType(video::EMT_LIGHTMAP_ADD);
		}
Last edited by mrbig on Tue May 18, 2004 9:24 pm, edited 2 times in total.
mrbig
Posts: 29
Joined: Wed Mar 17, 2004 5:38 am
Location: lakeland, Florida
Contact:

Post by mrbig »

don't know what happend to that pic
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

The image you included is: http://iron-core-studios.cjb.net/phy.bmp

1. bmp format doesn't work in web browsers
2. that domain doesn't exist
Unarekin
Posts: 60
Joined: Thu Apr 22, 2004 11:02 pm

Post by Unarekin »

Try changing the height of the box collision primitive used for the boxes.
Guest

Post by Guest »

Try this

vArray[0] = mb_vertices[v1i].Pos.X;
vArray[1] = mb_vertices[v1i].Pos.Y;
vArray[2] = mb_vertices[v1i].Pos.Z;
vArray[6] = mb_vertices[v2i].Pos.X;
vArray[7] = mb_vertices[v2i].Pos.Y;
vArray[8] = mb_vertices[v2i].Pos.Z;
vArray[3] = mb_vertices[v3i].Pos.X;
vArray[4] = mb_vertices[v3i].Pos.Y;
vArray[5] = mb_vertices[v3i].Pos.Z;
Guest

Post by Guest »

comment out the following line:

quakeLevelNode->setPosition(core::vector3df(-1300,-70,-1249));

and set your camera position different. if you really want to reset the position of the level, you have to pass these changes to newton when reading the vertices
mrbig
Posts: 29
Joined: Wed Mar 17, 2004 5:38 am
Location: lakeland, Florida
Contact:

Post by mrbig »

thx that did it
Post Reply