Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Recommended Posts

Leadwerks C++ Noob here...

So I'm programmatically creating a bunch of floor tiles out of PolyMesh for my player to walk around on, and it works great except for one strange behavior.

When I call Translate() on my tile Model class it slowly erodes/squishes the PolyMesh data until it is gone completely, and then my player just falls through.

If I don't translate, no problem. I looked into the docs a bit and I see that PolyMesh isn't recommended for moving objects. However when I try the same with ConvexHull() I am getting no collision data at all.

My tiles are basically small flat planes created from 2 triangles to make a rectangle.

On create...

/*
 * Generate a cTile
 * ofs of entire tile position from center
 * dim is width and length|depth
 */
Model* make_ctile(Vec3 ofs, Vec3 dim) {
	Model* cmodel = Model::Create();
	cmodel->SetColor(1., 1., 1.);
	Surface* csurface = cmodel->AddSurface();//Surface::Create();//
	Vec3 dn = Vec3(0, 1, 0); // up
	csurface->AddVertex(-dim.x, 0, -dim.y, dn.x, dn.y, dn.z); // bl
	csurface->AddVertex(dim.x, 0, -dim.y, dn.x, dn.y, dn.z); // br
	csurface->AddVertex(dim.x, 0, dim.y, dn.x, dn.y, dn.z); // tr
	csurface->AddVertex(-dim.x, 0, dim.y, dn.x, dn.y, dn.z); // tl
	// CW
	csurface->AddTriangle(2, 1, 0); // tr, br, bl
	csurface->AddTriangle(0, 3, 2); // bl, tl, tr
	csurface->Update();
	csurface->UpdateNormals();
	;
	Shape* cshape = Shape::PolyMesh(csurface);
	cmodel->SetShape(cshape);
	cshape->Release();
	cmodel->SetPhysicsMode(Entity::RigidBodyPhysics);
	cmodel->SetCollisionType(Collision::Prop);
	;
	cmodel->Translate(ofs);
	return cmodel;
}

 

On update...

for (int i = 0; i < tilex; i++) { // Pull tiles
   tiles[i].tile->Translate(0, 0, tile_speed);
}

 

Included is a view of the collision working when there is no translation, and also a view of the collision failing after translation has started.

I also included a screenshot of the output when I use ConvexHull to generate the shape, which seems to not have any collision data whatsoever.

Shape* cshape = Shape::ConvexHull(csurface);// PolyMesh(csurface);

 

I'm not really sure what to try next.

s2.png

s1.png

s0.png

Link to post
Share on other sites
  • 2 weeks later...

I never built meshes by code myself, but it sounds like the surfaces isn't being "collapsed" to the model. There should be a command to solidify/lock the matrix. I'm currently not at my PC, but I suggest to look at Model.h to see if there is a command to recalculate the surfaces.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...