/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef __GRACER_VEHICLE_H__ #define __GRACER_VEHICLE_H__ #include #include #include #include #include #include "control.h" #define SLIP_FACTOR 10.0 enum { GR_WHEEL_DRIVING = 1<<0, GR_WHEEL_STEERING = 1<<1, }; typedef enum { GR_VEHICLE_MOTORCAR = 0, GR_VEHICLE_MOTORCYCLE = 1, GR_VEHICLE_BICYCLE = 2, } GrVehicleType; typedef enum { GR_CAR_TYPE_FF, GR_CAR_TYPE_FR, GR_CAR_TYPE_4WD, } GrCarType; typedef enum { GR_WHEEL_POS_LEFT = 1, GR_WHEEL_POS_RIGHT = 2, GR_WHEEL_POS_FRONT = 4, GR_WHEEL_POS_REAR = 8, } GrWheelPosition; typedef struct _GrWheel GrWheel; typedef struct _GrVehicle GrVehicle; typedef struct _GrWheelData GrWheelData; typedef struct _GrBreakData GrBreakData; typedef struct _GrTireData GrTireData; typedef struct _GrEngineData GrEngineData; typedef struct _GrLapHistory GrLapHistory; typedef struct _GrVehicleData GrVehicleData; struct _GrBreakData { GrRef ref; /* constants */ float mu[128]; /* friction factor */ } GrBreak; struct _GrTireData { GrRef ref; float radius; float mu[128]; /* grip mu (grip force is depend on surface) */ }; struct _GrEngineData { GrRef ref; int max_gear; float *gear_ratio; float torque[128]; float limit; float moment; float friction; }; struct _GrWheelData { int flag; float m; /* inertial moment */ float ks; float kd; GrVertex pos; GrVertex rpos; GrVertex dir; GrVertex pivot; GrVertex susp; float slen; char *model_url; char *object_name; char *tire_url; char *fb_url; char *sb_url; GrBreakData *fb; /* foot break */ GrBreakData *sb; /* side break */ GrTireData *tire; }; struct _GrVehicleData { GrRef ref; char *title; char *timestamp; char *model_url; char *object_name; GrVehicleType type; GrVertex cockpit; float cockpit_height; float mass; float moment[9]; float down_force_speed_ratio; int num_wheel; int num_driving_wheel; GrWheelData *wheel; char *engine_url; GrEngineData *engine; float gear_ratio; }; typedef struct GrWheelState { GrVertex pos; GrVertex abs_pos; GrVertex pivot; GrVertex abs_pivot; GrVertex u, v; float n; float dr; /* wheel rotational velocity */ float ds; /* suspention difference */ float pds; /* previous value of suspention difference */ float slip; GrCSurface *surf; GrVertex grip; GrVertex speed; GrVertex force; GrVertex top; int segment; } GrWheelState; struct _GrWheel { /* state variables */ GrWheelState state[2]; struct { float f; float angle; } control; GrObject *obj; GrScene *scene; GLuint dl; }; struct _GrLapHistory { int lap; double time; double laptime; GrLapHistory *next; }; struct _GrVehicle { GrRef ref; GrRigidBody body; /* control variables */ GrControl control; /* state variables */ struct { double me; double rpm; double spd; } state[2]; GrWheel *wheel; /* temporal variables */ GrVertex fg; GrVehicleData *data; /* drawing */ GrObject *obj; GrScene *scene; GLuint dl; /* game related variables */ GrCLineInfo cinfo; double time; int lap; int lap_count; int entry_no; double prev_laptime; double arc; GrLapHistory *laphistory; GrLapHistory *bestlap; }; /* call this function after set essential parameters onto the struct */ GrVehicleData* gr_vehicle_data_new_from_file (FILE *file); GrEngineData* gr_engine_data_new_from_file (FILE *file); GrTireData* gr_tire_data_new_from_file (FILE *file); GrBreakData* gr_break_data_new_from_file (FILE *file); GrVehicleData* gr_get_vehicle_data (char *url); GrVehicle* gr_vehicle_new (GrVehicleData *vd); void gr_vehicle_initialize (GrVehicle *vehicle, char *url); void gr_vehicle_integral (GrVehicle *vehicle, GrCourse *course, int from, int to, double h); int gr_vehicle_put (GrVehicle *car, GrCourse *course, double threshold, double h, int limit); #endif /* __GRACER_VEHICLE_H__ */