/*
 * $Id: $
 *
 * Description  : Data structure describing main information of the vehicle simulation
 * Author       : Jiri Bittner
 *
 * Purpose      :
 *     Long description of what the file is for.
 */


#ifndef __VEHICLE_SIMULATION_DATA__H__
#define __VEHICLE_SIMULATION_DATA__H__

namespace VRUT
{
	struct VehicleSimulationData
	{
		int vehicleID;
		int controllerID;
		Vector3 velocity;			///< Linear velocity in m/s
		Vector3 acceleration;			///< Linear velocity in m/s
		Vector3 position;			///< Position in the world
		Vector3 orientation;		///< Orientation (rotation relative to (0.0, 0.0, 1.0))
		Vector3 angularVelocity;		///< angular velocity of the body
		float steeringTorque;		///< moment on the steering wheel

		NODE_ID nodeID;           ///< Geometry node ID

		// emgine related values
		float engineRPM;			///< Engine RPM
		float engineTorque;			///< Engine torque
		int gear;

		// wheel related values
		int wheelSlipInfo[4]; ///< boolean indicating slipping of the given wheel
		
		int wheelContactInfo[4];
		Vector3 wheelPosition[4];

		int virtualWheelContactInfo[4];
		Vector3 virtualWheelPosition[4];

		// simple neigborhood info
		float collisionDistance; /// frontal distance to the other car 1000.0f - for no detected car in front
		
		float distance;	///< Total distance traveled by the vehicle in km
		float range;	///< Driving range
		float charge;	///< Charge of the battery

		// states of the vehicle controls send back from simulator
		float wheel;
		float gas;
		float brake;
		int buttons;
		// flags sent in the buttons variable 
		enum {WAS_RESET_FLAG = 0x10000};
		
		VehicleSimulationData() : vehicleID(0), controllerID(0), velocity(0, 0, 0), acceleration(0,0,0), position(0, 0, 0), orientation(0, 0, 0), nodeID(0), engineRPM(0), engineTorque(0), gear(0),
				collisionDistance(0), distance(0), range(0), charge(0), wheel(0), gas(0), brake(0), buttons(0) {}

		VehicleSimulationData(const VehicleSimulationData &other) : vehicleID(other.vehicleID), controllerID(other.controllerID), velocity(other.velocity), acceleration(other.acceleration),
				position(other.position), orientation(other.orientation), nodeID(other.nodeID), engineRPM(other.engineRPM), engineTorque(other.engineTorque), gear(other.gear),
				collisionDistance(other.collisionDistance), distance(other.distance), range(other.range), charge(other.charge), wheel(other.wheel), gas(other.gas),
				brake(other.brake), buttons(other.buttons)
		{
			for (int i=0; i < 4; i++) {
				wheelContactInfo[i] = other.wheelContactInfo[i];
				wheelPosition[i] = other.wheelPosition[i];
				virtualWheelContactInfo[i] = other.virtualWheelContactInfo[i];
				virtualWheelPosition[i] = other.virtualWheelPosition[i];
				wheelSlipInfo[i] = other.wheelSlipInfo[i];
			}
		}
		float GetSpeed() const { return velocity.Length(); }
		float GetAcceleration() const { return acceleration.Length(); }
	};
}

#endif
