Strange problem with wheels Author Message
joacorock
Member

 Post: #1 Strange problem with wheels Hi, I don't know how to explain it very well so I filmed a video where the problem ocurrs: http://www.youtube.com/watch?v=8TGoW5PjSow&hd=1 As you can see at the begining the Wheel mesh, matchs exactly with the circumference, but when I acelerate/reverse the wheel mesh start moving outside the circumference. And at certain point, the program uses 50% of CPU when the wheels are far of they starting point, and then comes back to the start position. I can post some code if needed. Thanks, Joaquin
10-04-2010 03:07 AM
Esenthel

 Post: #2 RE: Strange problem with wheels yes, please paste some codes, by any chance do you update physics during drawing? you should do it during Update
10-04-2010 04:46 PM
joacorock
Member

 Post: #3 RE: Strange problem with wheels Ok, here you have some code, no, in Draw() i use Physics.draw (); Vars Code: ```Actor car; Wheel wheel[4]; Mesh carMesh,wheelMesh; Material wheel0,wheel1; //0 for tire, 1 for "rims" xD``` Code: ```Bool Init() { //...         carMesh.load("obj/auto/ferrari.mesh");     carMesh.scale(Vec(2.3,2.3,2.3));     wheelMesh.create(2);     wheelMesh.load("obj/auto/rueda.mesh");     wheel0.load("Mtrl/rueda/cubierta2.mtrl");     wheel1.load("Mtrl/rueda/llanta2.mtrl");     wheelMesh.part(1).setMaterial(&wheel1);     wheelMesh.part(0).setMaterial(&wheel0); //...         car.mass(1500);     car.create(Box(2,1,4.5),2);     car.massCenterL(car.pos()-Vec(0,0.8,0)); // lower mass center     car.pos(Vec(1,3,1));     Wheel::Param wp;     wp.mass=20;     wheel[0].create(car,Matrix().setPos(Vec( 2,2, 2.2)),wp); // left -front     wheel[1].create(car,Matrix().setPos(Vec(0,2, 2.2)),wp); // right-front     wheel[2].create(car,Matrix().setPos(Vec( 0,2,-0.5)),wp);// left -rear     wheel[3].create(car,Matrix().setPos(Vec(2,2,-0.5)),wp);// right-rear //... }``` Code: ```Bool Update() { //.. Physics.startSimulation().stopSimulation();     if(Kb.bp(KB_ENTER))car.pos(Vec(1,3,1)); // reset car position on ENTER key     // Working with joypad [LS Right/Left; A for Acelerate; X for Reverse; RT for Brake]     {         AdjustValTime(angle,(Joypad[0].dir_a[0].x)*PI_4,0.01); // adjust wheel angle         Flt accel,brake;             accel=(Joypad[0].b(1)-Joypad[0].b(2))*1200, // acceleration                 brake= (Joypad[0].b(5))        *3200; // brakes         wheel[0].angle(angle).accel(accel); // set angle, acceleration and brakes to left -front wheel         wheel[1].angle(angle).accel(accel); // set angle, acceleration and brakes to right-front wheel         //4x4         wheel[2].brake(brake);         wheel[3].brake(brake);     } //.. REPAO(wheel).update(); }``` Code: ```void Render() {          Game::World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)     // <------- HERE     switch(Renderer()){         case RM_SOLID:         autoMesh.draw(car.matrix());         case RM_SHD_MAP:             ruedaMesh.drawShadow(wheel[0].matrix());             ruedaMesh.drawShadow(wheel[1].matrix());             ruedaMesh.drawShadow(wheel[2].matrix());             ruedaMesh.drawShadow(wheel[3].matrix());             autoMesh.drawShadow(car.matrix());     } }``` Code: ```void Draw() {     D      .clear();     Physics.draw ();     car.draw(RED);     autoMesh.draw(car.matrix());     Renderer(Render);     car.draw(RED);     car.massCenterL().draw(BLUE);     //Aca dibujo las ruedas, mas tarde con textura     ruedaMesh.draw(wheel[0].matrix());     ruedaMesh.draw(wheel[1].matrix());     ruedaMesh.draw(wheel[2].matrix());     ruedaMesh.draw(wheel[3].matrix());     D.text(0,0.7,S+"Speed " + 3.6*car.vel());     LightDir(Vec(0,0,1)).set(); // set directional light in (0,0,1) direction before rendering to achieve lighting (NOTE: only directional light is supported in simple rendering mode) }``` Tell me if you need more
10-04-2010 07:39 PM
Esenthel

 Post: #4 RE: Strange problem with wheels you forgot to call break's in Render switch and in Draw you sould only call Renderer(Render), followed optionally by Physics.draw, later followed by optional 2D graphics.
10-04-2010 08:35 PM
joacorock
Member

 Post: #5 RE: Strange problem with wheels (10-04-2010 08:35 PM)Esenthel Wrote:  you forgot to call break's in Render switch and in Draw you sould only call Renderer(Render), followed optionally by Physics.draw, later followed by optional 2D graphics. Thanks, now the things are better, the program stays stable but... the wheels still getting out from the circumference, as you can see at the video. I putted the Draw() extra code at Update(): Code: ```car.draw(RED);     carMesh.draw(car.matrix());          car.draw(RED);     car.massCenterL().draw(BLUE);     wheelMesh.draw(wheel[0].matrix());     wheelMesh.draw(wheel[1].matrix());     wheelMesh.draw(wheel[2].matrix());     wheelMesh.draw(wheel[3].matrix());``` is that correct?
10-05-2010 01:19 AM
Esenthel

 Post: #6 RE: Strange problem with wheels where's that code? you should draw 3D graphics only inside Render function after checking Renderer() mode using switch in Update and Draw don't call any Mesh::draw
10-05-2010 01:25 PM
joacorock
Member

 Post: #7 RE: Strange problem with wheels Cool , but now i'm having some problems, with the cpu load. Sometimes it uses 50% of the CPU Here is the complete code: Code: ```/******************************************************************************/ #include "stdafx.h" /******************************************************************************/ Flt   angle   ; // car wheel angle Actor car; // ground actor MeshBase mshb; Wheel wheel[4]; // wheels Mesh autoMesh,ruedaMesh; Material rueda0,rueda1; Camera desired_camera; /******************************************************************************/ #include "../../../../../data/enum/_enums.h" /******************************************************************************/ /******************************************************************************/ Game::ObjMemx Statics; // container for static    objects Game::ObjMemx Items;   // container for item      objects Game::ObjMemx Chrs;    // container for character objects /******************************************************************************/ void InitPre() {     App.name("Juego Autos");     App.flag=APP_MS_EXCLUSIVE|APP_FULL_TOGGLE;     IOPath("../data");     Paks.add("../data/engine.pak");     D.full(true).sync(true).hpRt(true).hdr(true);     Cam.dist =10;     Cam.yaw  =-PI_4;     Cam.pitch=-0.5;     Cam.at.set(16,0,16); } Bool Init() {     Cam.dist=10;     Physics.create();     //Investigar sobre el motion blur porque todos los que pongo estan mal.     Game::World.init(); // initialize world, optionally you can change default parameters here     // once the world is initialized, we need to tell the world 'which class handles which type'     // this is done by assigning memory containers to certain Object Types defined in Game Enums (which were used in the World Editor)     Game::World.setObjType(Statics,OBJ_STATIC)  // set 'Statics' memory container for 'OBJ_STATIC' objects         .setObjItem(Items  ,OBJ_ITEM  )  // set 'Items'   memory container for 'OBJ_ITEM'   objects         .setObjType(Chrs   ,OBJ_PLAYER); // set 'Chrs'  ' memory container for 'OBJ_PLAYER' objects     // now when the engine is set up properly we can start a 'new game' with a builded world     Game::World.New("world/ciudad.world"); // create the world by giving path to builded world     autoMesh.load("obj/auto/ferrari.mesh");     autoMesh.scale(Vec(2.3,2.3,2.3));     ruedaMesh.create(2);     ruedaMesh.load("obj/auto/rueda.mesh");     rueda0.load("Mtrl/rueda/cubierta2.mtrl");     rueda1.load("Mtrl/rueda/llanta2.mtrl");     ruedaMesh.part(1).setMaterial(&rueda1);     ruedaMesh.part(0).setMaterial(&rueda0);     //ruedaMesh.scale(Vec(0.8,0.8,0.8));     /*ground .create(Box_U(100,1,100),0);     ground .pos   (ground.pos()-Vec(0,3,0));*/     Sun.image=Images("gfx/sky/sun.gfx");     Sky.atmospheric();     D.bumpMode(BUMP_FLAT);     //mshb.create(Torus(1,0.3),VTX_NRM);     Game::World.init(); // initialize world, optionally you can change default parameters here     // once the world is initialized, we need to tell the world 'which class handles which type'     // this is done by assigning memory containers to certain Object Types defined in Game Enums (which were used in the World Editor)     Game::World.setObjType(Statics,OBJ_STATIC)  // set 'Statics' memory container for 'OBJ_STATIC' objects         .setObjItem(Items  ,OBJ_ITEM  )  // set 'Items'   memory container for 'OBJ_ITEM'   objects         .setObjType(Chrs   ,OBJ_PLAYER); // set 'Chrs'  ' memory container for 'OBJ_PLAYER' objects     // now when the engine is set up properly we can start a 'new game' with a builded world     Game::World.New("world/pista.world"); // create the world by giving path to builded world     // when the world is loaded it doesn't actually load all the terrain and objects into memory     // it loads only information about them     // you need to tell the world which terrain and objects you need to use at the moment     // to do that call:     Game::World.update(Cam.at); // which updates world to use only terrain and objects at given position, here camera position is used     // create car     Cam.setPosDir(Vec(1,3,1));     // create car wheels     car.mass(1500);     car.create     (Box(2,1,4.5),2);//2,1,4                     // create actor     car.massCenterL(car.pos()-Vec(0,0.8,0)); // lower mass center     car.pos(Vec(1,3,1));     Wheel::Param wp; // wheel parameters     wp.mass=20;     wheel[0].create(car,Matrix().setPos(Vec( 2,2, 2.2)),wp); // left -front     wheel[1].create(car,Matrix().setPos(Vec(0,2, 2.2)),wp); // right-front     wheel[2].create(car,Matrix().setPos(Vec( 0,2,-0.5)),wp); // left -rear     wheel[3].create(car,Matrix().setPos(Vec(2,2,-0.5)),wp); // right-rear     return true; } void Shut() { } /******************************************************************************/ /******************************************************************************/ Bool Update() {     Flt accel,brake;     if(Kb.bp(KB_ESC))return false;     CamHandle(0.1f,200,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));     /*     Control de la camara     INICIO     */     // first setup the desired camera as in the previous tutorials     //desired_camera.yaw =LerpAngle(Cam.yaw,-car.matrix().angles().y,Time.d()*5);     desired_camera.yaw  -=Ms.ds.x;          // update camera yaw   angle according to mouse smooth delta x     desired_camera.pitch+=Ms.ds.y;          // update camera pitch angle according to mouse smooth delta y     Clamp(desired_camera.pitch,-PI_2,PI_4); // clamp to possible camera pitch angle     desired_camera.dist=Max(1.0f,desired_camera.dist*ScaleFactor(Ms.wheel()*-0.2)); // update camera distance according to mouse wheel     desired_camera.at  =car.pos();     desired_camera.setSpherical(); // set as spherical from current values, this will set the camera's matrix (desired_camera.matrix)     // now what we'll do is cast a small sized Ball from starting position to target camera destination     // we'll stop the ball at first contact point, and set camera at that place     // create a helper ball which will be used for collision detection     Ball ball(0.1f, desired_camera.at); // we place it at starting point (where the camera is looking at)     // now we'll move the ball in the direction where the camera should be     Physics.move(ball, desired_camera.matrix.pos-ball.pos); // use physics movement to move the ball as far as it can go without any collisions     // now the ball.pos is located at either maximum movement distance or at nearest collision point     // having ball's position we can now set the final camera position     Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y); // we'll use 'desired_camera.matrix' directions which were set in 'setSpherical' camera method     Cam.updateVelocities().set(); // update camera velocities and activate it     //Fin del control de la camara     Physics.startSimulation().stopSimulation();     if(Kb.bp(KB_ENTER))car.pos(Vec(1,3,1)); // reset car position on ENTER key     // adjust car controls     {         AdjustValTime(angle,(Joypad[0].dir_a[0].x)*PI_4,0.01); // adjust wheel angle         accel=((Joypad[0].b(1)*2)-Joypad[0].b(2))*1200, // acceleration             brake= (Joypad[0].b(5)*5)        *3200; // brakes         wheel[0].angle(angle).accel(accel); // set angle, acceleration and brakes to left -front wheel         wheel[1].angle(angle).accel(accel); // set angle, acceleration and brakes to right-front wheel         //4x4         wheel[2].brake(brake);         wheel[3].brake(brake);     }     /*if(accel>0){     accel=accel*0.8;     }*/     // update wheels     REPAO(wheel).update();     Game::World.update(Cam.at);     return true; } void Render() {     Game::World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)     // <------- HERE     switch(Renderer()){         case RM_PREPARE:             autoMesh.draw(car.matrix());             /*             Dibujo las ruedas             */             ruedaMesh.draw(wheel[0].matrix());             ruedaMesh.draw(wheel[1].matrix());             ruedaMesh.draw(wheel[2].matrix());             ruedaMesh.draw(wheel[3].matrix());             break;         case RM_SHD_MAP:             ruedaMesh.drawShadow(wheel[0].matrix());             ruedaMesh.drawShadow(wheel[1].matrix());             ruedaMesh.drawShadow(wheel[2].matrix());             ruedaMesh.drawShadow(wheel[3].matrix());             autoMesh.drawShadow(car.matrix());             break;     } } void Draw() {     D.clear();     Renderer(Render);     D.text(0,0.7,S+"Speed " + 3.6*car.vel());     //Physics.draw (); } /******************************************************************************/``` Thanks
10-06-2010 01:46 AM
Esenthel

 Post: #8 RE: Strange problem with wheels Game::World.update already calls physics simuation, so dont call it manually everything else looks ok
10-06-2010 08:56 AM
joacorock
Member

 Post: #9 RE: Strange problem with wheels =/ so weird, is better but when i play for 2 minutes then it starts to use too much cpu. Can this be posible because i don't have nVidia GPU?
10-06-2010 01:56 PM
Esenthel

 Post: #10 RE: Strange problem with wheels also you don't need to call D.clear since Renderer(Render) does that too high cpu usage is normal for games ati/nvidia doesn't make a difference, only model of your gpu and cpu matters.
10-06-2010 05:20 PM
joacorock
Member

 Post: #11 RE: Strange problem with wheels I have C2D e8400 and Ati 5770 is good i think. The problem is that the car starts to shake at that point (when the cpu load grows)
10-06-2010 05:44 PM
 « Next Oldest | Next Newest »