About Store Forum Documentation Contact



Post Reply 
Car mesh
Author Message
CroMan Offline
Member

Post: #1
Car mesh
Hi,

I'm having some trouble with replacing wireframe box (car body in vehicle.cpp tutorial) with my own model of car body (mesh).

can you tell me what should i put instead of this line of code so i can have my own model as car body?
car.crt (BOX(2,1,4)); // create car body

Thanks in front,
Alen
07-21-2008 05:27 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Car mesh
Hello,
you should always create a vehicle from simple geometric shapes (that's how physics works in games)
but for rendering you can use a mesh instead of a box

so the actor ACTR will be a box
but in the rendering process, you'll render a mesh with a vehicle matrix, like this:

mesh.rndr(car.mtrx())

let me know if you need more assistance.
07-21-2008 05:42 PM
Find all posts by this user Quote this message in a reply
CroMan Offline
Member

Post: #3
Re: Car mesh
what could be the most easy way to do that? sorry for so many questions but i'm still not familiar enough with this engine smile

here's my code (it's mostly or all from vehicle.cpp):
Code:
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/
using namespace GAME; // use game namespace
FLT   ang   ; // car wheel angle
ACTR  car   , // car    actor
      ground; // ground actor
WHEEL whl[4]; // wheels
/******************************************************************************/

VOID InitPre()
{
   App.name="GameWIP";
   //App.flg =APP_DISP;
   IOPath="../data/";
   PakAdd("../data/engine.pak",NULL);

   D.full(true).sync(true).shdSize(1024);
}
BOOL Init()
{
   //Cam.dist=10;
   Phys.crt(-1,60); // limit physics calculations to 60 frames per second, above that PhysX seems to have problems with wheels
   //ground.crt(BOX_U(100,1,100),0);ground.pos(ground.pos()-VEC(0,3,0));

   // create car
   car.crt     (BOX(2,1,4));                  // create actor
   car.mass(FLT(100.0));
   car.massCntr(car.massCntr()-VEC(0,1.0,0)); // lower mass center

   // create car wheels
   WHEEL_PAR wp; // wheel parameters
   whl[0].crt(car,VEC( 1,-0.5, 1.5),wp);
   whl[1].crt(car,VEC(-1,-0.5, 1.5),wp);
   whl[2].crt(car,VEC( 1,-0.5,-1.5),wp);
   whl[3].crt(car,VEC(-1,-0.5,-1.5),wp);
    
    
   car.pos(car.pos()+VEC(15,3,15));


   Wrld.crt("wrld/sample","temp" ); // please note that here an additional "set" is called, this is used for enabling built-in character<->item relations such as picking up and dropping items
  
   Cam.setSphr(VEC(16,0,16),-PI_4,-0.5,0,10).set(); // set initial camera

   return true;
}
/******************************************************************************/
VOID Shut()
{
}
/******************************************************************************/
BOOL Main()
{
   if(Kb.bp(KB_ESC))return false;
   //CamHandle(0.1f,200,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   Phys.sim();
   Phys.get();

   if(Kb.bp(KB_ENTER))car.pos(VEC(0,3,0)); // reset car position on ENTER key

   // adjust car controls
   {
      ang=LerpTime(ang,(Kb.b(KB_D)-Kb.b(KB_A))*PI_4,0.01); // adjust wheel angle

      FLT acc=(Kb.b(KB_W)-Kb.b(KB_S))*1600, // acceleration
          brk= Kb.b(KB_SPC)          *3200; // brakes

      whl[0].ang(ang);          // set angle
      whl[1].ang(ang);          // set angle
      whl[2].acc(acc).brk(brk); // set acceleration and brakes
      whl[3].acc(acc).brk(brk); // set acceleration and brakes
   }

   // update wheels
   REPAO(whl).upd();
   Wrld.upd(Cam.at); // update world to given position
   return true;
}
VOID Rndr()
{
   Wrld.draw();
   switch(R())
   {
      case RNDR_LGT:
         LGT_DIR(1,!VEC(1,-1,1)).add();
      break;
   }

  
}
VOID Draw()
{
    R(Rndr);
   //D.clr();
   Phys.draw();
   (car.massCntr()*car.mtrx()).draw(RED); // draw mass center
}
/******************************************************************************
/
07-21-2008 06:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: Car mesh
add a "MESH mesh" to your variables on top

Code:
FLT   ang   ; // car wheel angle
ACTR  car   , // car    actor
     ground; // ground actor
WHEEL whl[4]; // wheels
MESH mesh; // <---------  HERE

load the mesh in Init()

Code:
BOOL Init()
{
   mesh.load(...); // <------ HERE

render the mesh in Rndr()

Code:
VOID Rndr()
{
   Wrld.draw();
   switch(R())
   {
      case RNDR_SLD:
      case RNDR_SHDM:
           mesh.rndr(car.mtrx()); // <------- HERE
      break;

      case RNDR_LGT:
         LGT_DIR(1,!VEC(1,-1,1)).add();
      break;
   }
}
07-21-2008 06:44 PM
Find all posts by this user Quote this message in a reply
CroMan Offline
Member

Post: #5
Re: Car mesh
aaaah, i tried exactly like that but i got some errors. now i see why. i spelled rndr -> Rndr. foolish me smile

thanks alot
07-21-2008 07:14 PM
Find all posts by this user Quote this message in a reply
Post Reply