cat555
Member
|
wheelFriction override help
Hi, i'm overriding
Code:
flt WheelFriction(C PhysMtrl &ground_material, C PhysMtrl &wheel_material, C ActorInfo &vehicle, WHEEL_TYPE wheel)
... but i get always unreferenced vehicle parameter.
My intention is to use vehicle information to check material under the car, for example:
Code:
flt WheelFriction(C PhysMtrl &ground_material, C PhysMtrl &wheel_material, C ActorInfo &vehicle, WHEEL_TYPE wheel) {
if (vehicle.obj && Game.World.hmMaterial(vehicle.obj.pos().xz())->user_type == GROUND_SAND)
{
return someFriction;
} else {
return 2.5;
}
}
bool Init() {
Physics.create(EE_PHYSX_DLL_PATH, CSS_MATERIALS, true).wheelFriction(WheelFriction).timestep(PHYS_TIMESTEP_VARIABLE);
}
Shouldn't Esenthel manage this by himself (passing referenced vehicle parameter), or i'm missing something here?
Thanks!
(This post was last modified: 09-08-2014 11:32 PM by cat555.)
|
|
09-08-2014 11:32 PM |
|
Esenthel
Administrator
|
RE: wheelFriction override help
Hi,
You need to first set the:
vehicle.obj(&obj);
EE.Vehicle.obj metod
|
|
09-11-2014 04:00 AM |
|
cat555
Member
|
RE: wheelFriction override help
Hi,
I've already tried that before, but can't make it work... i'm using this:
Code:
class Car : Vehicle
{
...
void create(C Vec &pos, C Vec &dir)
{
...
Game.ObjParamsPtr car_obj=UID(1429080598, 2558294431, 1169191620, 3226949371);
Game::Obj *car = Game::World.objCreateNear(*car_obj, Matrix(car_obj->scale(), Vec(0, 1, 0)));
T.obj(car);
}
Thanks!
|
|
09-11-2014 03:41 PM |
|
Esenthel
Administrator
|
RE: wheelFriction override help
Hi,
Did you check if 'Game.Obj *car' is not null ?
Or perhaps you're calling Vehicle.obj before creating the vehicle?
this is the vehicle tutorial with some modifications:
Code:
/******************************************************************************/
const bool EasyReverse=true; // if use simplified reversing (will automatically switch between reverse<->forward gears)
Memc<Actor> actors;
Vehicle vehicle;
Game.Chr chr;
/******************************************************************************/
flt WheelFriction(C PhysMtrl &ground_material, C PhysMtrl &wheel_material, C ActorInfo &vehicle, WHEEL_TYPE wheel)
{
Exit(S+vehicle.obj);
return 1;
}
void InitPre()
{
EE_INIT();
App.flag=APP_RESIZABLE|APP_MINIMIZABLE|APP_MAXIMIZABLE|APP_WORK_IN_BACKGROUND|APP_FULL_TOGGLE;
#ifdef DEBUG
App.flag|=APP_MEM_LEAKS|APP_BREAKPOINT_ON_ERROR;
#endif
Cam.dist=10;
Cam.pitch=-0.4;
D.viewFov(DegToRad(60)).mode(App.desktopW()*0.8, App.desktopH()*0.8);
}
/******************************************************************************/
bool Init()
{
Physics.create(EE_PHYSX_DLL_PATH).wheelFriction(WheelFriction); // create physics and set custom friction calculation callback
actors.New().create(Plane(Vec(0, -1, 0), Vec(0, 1, 0))); // create ground
Vehicle.Params params; // setup vehicle params
flt x=0.9, y=-0.5, z=1.8;
params.wheel[WHEEL_LEFT_FRONT ].pos.set(-x, y, z);
params.wheel[WHEEL_RIGHT_FRONT].pos.set( x, y, z);
params.wheel[WHEEL_LEFT_REAR ].pos.set(-x, y, -z);
params.wheel[WHEEL_RIGHT_REAR ].pos.set( x, y, -z);
PhysBody body; body.parts.New().create(Box(2, 1, 4)); body.setBox(); // create vehicle body
vehicle.create(body, params, 1); // create vehicle
vehicle.obj(&chr);
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
if(Kb.bp(KB_ESC))return false;
Physics.startSimulation().stopSimulation(); // update physics
// set vehicle input
flt forward=Kb.b(KB_W),
back =Kb.b(KB_S),
angle =Kb.b(KB_D)-Kb.b(KB_A),
hand =Kb.b(KB_SPACE);
// adjust gears when reversing
if(EasyReverse)
{
if(back >forward+EPS && vehicle.speed()<=0.5)vehicle.gear(-1); // set reverse gear when 'back ' exceeds 'forward' and moving very slow
if(forward>back +EPS && vehicle.gear ()<=0 )vehicle.gear( 1); // set 1st gear when 'forward' exceeds 'back ' and gear is reverse or neutral
if(vehicle.gear()<0)Swap(forward, back);
}
vehicle.accel(forward).brake(back).angle(angle).handBrake(hand);
// manual gear change
if(Kb.bp(KB_R))vehicle.gearUp ();
if(Kb.bp(KB_F))vehicle.gearDown();
if(Kb.bp(KB_Z))vehicle.matrix(MatrixIdentity).vel(0).angVel(0);
/* sample code for changing gears depending on engine speed (for this code you should disable 'autoGear')
if(vehicle.gear()>0)
{
flt frac=vehicle.engineFrac();
if( frac>=0.70f )vehicle.gearUp ();else
if( frac< 0.50f && vehicle.gear()>1)vehicle.gearDown();
}*/
// setup camera
Cam.at =vehicle.pos();
Cam.yaw=Angle(vehicle.matrix().z.xz())-PI_2;
Cam.setSpherical().updateVelocities(CAM_ATTACH_ACTOR).set();
return true;
}
/******************************************************************************/
void Draw()
{
D.clear(TURQ);
Physics.draw();
}
/******************************************************************************/
In the 'WheelFriction' you can see that the obj pointer is not null
|
|
09-12-2014 03:17 AM |
|
cat555
Member
|
RE: wheelFriction override help
Hi, well, in fact 'car' was null :\
So, it seems that my need of help in this case is about creating the obj from ObjParams... don't understand why it won't works... pelase take a look at following code and comments (what i'm doing wrong?):
Code:
class Car : Vehicle
{
...
Game::Chr *car;
...
void create(C Vec &pos, C Vec &dir) {
...
Game.ObjParamsPtr car_obj=UID(1429080598, 2558294431, 1169191620, 3226949371); // this is NOT NULL
body = car_obj->mesh(); // getting body correctly and using it Ok
phys = car_obj->phys(); // getting body correctly and using it Ok
car = (Game::Chr *) Game::World.objCreateNear(*car_obj, Matrix(car_obj->scale(), Vec(0, 1, 0))); // car is NULL
T.obj(car);
...
}
...
}
Thanks!
(This post was last modified: 09-12-2014 10:46 AM by cat555.)
|
|
09-12-2014 10:44 AM |
|
cat555
Member
|
RE: wheelFriction override help
I've making tests but i can't seem to figure out what's happening... i'm now using your racing game source code.
So, i've got a car running on the track. It's actually added to the world, how can i get vehicle's (Vehicle) object (Game.Obj)? I've searched on vehicle class and i cannot find any reference to it...
Or what it appears to be, this application just manages the physical body parts and renders the mesh of the car... so, really no object car is created in the world. So, shy to have vehicle reference as 'ActorInfo' in wheel friction... it seems that it's not really usefull... maybe it would be very useful to get as param (additionaly), the reference to an object of type 'Vehicle'. In this case, it would be possible to know the position of the car, instead of having to manage a world obj (update accordingly with car body position, etc...), which seems to be totally unnecessary...
Can you give me please some hints... i'm really confused at the moment with this issue
Thanks!
(This post was last modified: 09-12-2014 12:17 PM by cat555.)
|
|
09-12-2014 11:57 AM |
|
cat555
Member
|
RE: wheelFriction override help
Hmmm, i'll guess that i should create my own object (and pass it like you referred in last message) and then pass whatever information i need to use in wheelFriction what a confusion for something simple anyway... sorry about making you lose time with this!
Thanks!
|
|
09-12-2014 05:35 PM |
|
Esenthel
Administrator
|
RE: wheelFriction override help
Hi, 'objCreateNear' can return NULL sometimes, you can read the comment on that method to learn why.
The recommended way to do is make your own Game.Obj class that includes Vehicle as a member:
Code:
class Car : Game.Obj
{
Vehicle vehicle;
}
and then set vehicle.obj(this);
|
|
09-13-2014 03:36 AM |
|
cat555
Member
|
RE: wheelFriction override help
Hi,
It's way better than the solution i've come up with (i was just using a dummy object 'Game.Obj' for passing vehicle information as needed)
Thanks for the suggestion!
|
|
09-13-2014 11:01 AM |
|