hmHeight returns 0 and bad collision with terrain Author Message
kulesz
Member

 Post: #1 hmHeight returns 0 and bad collision with terrain Hi, Todays morning I broke something in my code and I can't find what :-P The ray collisions with the terrain works (plane and position of collision is calculated properly), but the actor group is constantly 0 (should be 31, as it is collision with terrain). Also, returning height with Game::World.hmHeight always returns 0 :-/ Any idea, what may be broken? (This post was last modified: 09-21-2011 09:20 PM by kulesz.)
09-20-2011 06:31 PM
kulesz
Member

 Post: #2 RE: hmHeight returns 0 and bad collision with terrais Could it have something to do with area states? World is set to MANUAL and all checked areas are ACTIVE.
09-21-2011 06:40 PM
kulesz
Member

 Post: #3 RE: hmHeight returns 0 and bad collision with terrain Still nothing, I'm generating terrain with: Code: ```Mesh * mesh = new Mesh; PhysBody * body = new PhysBody; Edit::Heightmap * l = chunks[x - 1][z]; Edit::Heightmap * r = chunks[x + 1][z]; Edit::Heightmap * b = chunks[x][z - 1]; Edit::Heightmap * f = chunks[x][z + 1]; Edit::Heightmap * lb = chunks[x - 1][z - 1]; Edit::Heightmap * lf = chunks[x - 1][z + 1]; Edit::Heightmap * rb = chunks[x + 1][z - 1]; Edit::Heightmap * rf = chunks[x + 1][z + 1]; chunks[x][z]->create(33, 0, Materials.ptrRequire("mtrl/grass/Grass0027_13_S.mtrl"), true, l, r, b, f, lb, lf, rb, rf); for (int xx=0; xx<33; x++)     for (int yy=0; yy<33; y++)         chunks[x][z]->height(xx,yy, GetHeight()); chunks[x][z]->build(*mesh, 0, 20, true, l, r, b, f, lb, lf, rb, rf); mesh->scaleMove(Vec(128, 128, 128), Vec(128 * x, 0, 128 * z)); body->parts.New().createMesh(*mesh); if (Game::World.areaActive(VecI2(x, z))) {     Memc area_states;     area_states.New().set(VecI2(x, z), Game::AREA_ACTIVE);     Game::World.areaSetState(area_states); } Game::World.areaLoaded(VecI2(x, z))->getData(); Game::World.areaLoaded(VecI2(x, z))->data()->mshg.meshes(0).create(*mesh); Game::World.areaLoaded(VecI2(x, z))->data()->phys() = *body; Game::World.areaLoaded(VecI2(x, z))->data()->actor().create(*body); mesh->del(); body->del();``` and test collisions with Code: ```SetMatrix(MatrixIdentity); C OrientP &hand_r = Players[0].cskel.getPoint("head"); // just some forward looking vector from player's head Vec start = Players[0].cskel.getPoint("head").pos + 0.45 * Players[0].cskel.getPoint("head").dir; Vec end = start + 6 *Players[0].cskel.getPoint("head").dir; if(Physics.ray(start, end-start, &phys_hit)) {     Ball(0.3, phys_hit.plane.pos).draw(BLACK);     Flt h = Game::World.hmHeight(phys_hit.plane.pos.x, phys_hit.plane.pos.z); }``` Both values of "h" and "phys_his.plane.pos.y" are 0 :-/ phys_his.plane.pos x and z values are correct... (This post was last modified: 09-24-2011 10:30 AM by kulesz.)
09-24-2011 10:30 AM
Esenthel
Administrator

 Post: #4 RE: hmHeight returns 0 and bad collision with terrain Hmheight is based on game area data heightmap image which you're not setting Your codes are incorrect, memory leaks, creating actor from physical body you later delete
09-24-2011 10:41 AM
kulesz
Member

 Post: #5 RE: hmHeight returns 0 and bad collision with terrain (09-24-2011 10:41 AM)Esenthel Wrote:  Hmheight is bass on game area data heightmap image which you're not.setting Your codes are incorrect, memory leaks, creating actor from physical body you later delete How to set a game area data heightmap? And I guess I can't do Code: ```mesh->del(); body->del();``` but I need to store them? And where are the leaks, can't see any :-)
09-24-2011 10:59 AM
Esenthel
Administrator

 Post: #6 RE: hmHeight returns 0 and bad collision with terrain Game::Area::Data::height Mesh * mesh = new Mesh; PhysBody * body = new PhysBody; where is delete? from phys body.h: Physical Bodies of Convex or Mesh type may not be deleted manually when there are still actors using the body. This means that the Physical Body may be deleted only after deleting all actors using the body.
09-24-2011 11:19 AM
kulesz
Member

 Post: #7 RE: hmHeight returns 0 and bad collision with terrain But Game::Area::Data::height is of Image type, and my heightmaps are Edit::Heightmap type. Can't find any method to fill the first one with the second one. So, when I create body, I can't delete it as long as my game area actor is using it? OK. (09-24-2011 11:19 AM)Esenthel Wrote:  Mesh * mesh = new Mesh; PhysBody * body = new PhysBody; where is delete? Last two lines. But body deletion shouldn't be there, as far as I know now. (This post was last modified: 09-24-2011 11:50 AM by kulesz.)
09-24-2011 11:49 AM
kulesz
Member

 Post: #8 RE: hmHeight returns 0 and bad collision with terrain How to fill the Game::Area::Data::height with the data from Edit::heightmap?
09-25-2011 01:48 PM
Esenthel
Administrator

 Post: #9 RE: hmHeight returns 0 and bad collision with terrain Image::pixelF
09-26-2011 11:22 AM
kulesz
Member

 Post: #10 RE: hmHeight returns 0 and bad collision with terrain Thanks. For some reason, during collisions group isn't detected as 31 (terrain), I had to set it manually. Using pixelF doesn't help, hmheight still returns 0 ;-/ Code: ```for (int x = 0; x <= heightmapResolution - 1; x++)         for (int y = 0; y <= heightmapResolution - 1; y++)             Game::World.areaLoaded(VecI2(c_x, c_z))->data()->height().pixelF(x, y, heightmap->height(x, y));``` Heights in heightmap are in 0..1 range. (This post was last modified: 09-26-2011 08:28 PM by kulesz.)
09-26-2011 08:27 PM
Esenthel
Administrator

 Post: #11 RE: hmHeight returns 0 and bad collision with terrain Code: ```mesh->del(); body->del();``` this is not to be used with c++ 'new' also: Image::createSoft(res, res, IMAGE_F32)
09-27-2011 12:15 PM
 « Next Oldest | Next Newest »