Exemple #1
0
VehicleObject* GameWorld::tryToSpawnVehicle(VehicleGenerator& gen)
{
	constexpr float kMinClearRadius = 10.f;

	if (gen.remainingSpawns <= 0) {
		return nullptr;
	}

	/// @todo take into account maxDelay as well
	if (gen.lastSpawnTime + gen.minDelay > int(state->basic.timeMS)) {
		return nullptr;
	}

	/// @todo verify this logic
	auto position = gen.position;
	if (position.z < -90.f) {
		position = getGroundAtPosition(position);
	}

	// Ensure there's no existing vehicles near our spawn point
	for (auto& v : vehiclePool.objects)
	{
		if (glm::distance2(position, v.second->getPosition())
				< kMinClearRadius * kMinClearRadius) {
			return nullptr;
		}
	}

	int id = gen.vehicleID;
	if (id == -1) {
		// Random ID found by dice roll
		id = 134;
		/// @todo use zone information to decide vehicle id
	}

	auto vehicle = createVehicle(
				id,
				position);
	vehicle->setHeading(gen.heading);
	vehicle->setLifetime(GameObject::TrafficLifetime);

	/// @todo apply vehicle colours
	/// @todo apply locked & alarm thresholds

	// According to http://www.gtamodding.com/wiki/014C the spawn limit
	// doesn't work.
#if 0
	if (gen.remainingSpawns < 101) {
		gen.remainingSpawns --;
	}
#endif

	gen.lastSpawnTime = state->basic.timeMS;

	return vehicle;
}
CreateVehicleDialog::CreateVehicleDialog(QWidget* parent)
    : QDialog(parent),
      _ui(new Ui::CreateVehicleDialog),
      _vehicle(0)
{
    _ui->setupUi(this);

    this->connect(_ui->_buttonAdd, SIGNAL(clicked()), this, SLOT(createVehicle()));
    this->connect(_ui->_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
}
Exemple #3
0
VehicleCloning::VehicleCloning(hkDemoEnvironment* env, hkBool createWorld)
:	hkDefaultPhysicsDemo(env)
{
	m_bootstrapIterations = 200;

	m_track = HK_NULL;
	m_numWheels = 4;
	
	m_landscapeContainer = HK_NULL;
	setUpWorld();

	if (!createWorld)
	{
		return;
	}

	m_world->lock();

	const VehicleCloningVariant& variant =  g_variants[m_variantId];

	m_vehicles.setSize( variant.m_numVehicles );

	// Create a vehicle to use as a template for cloning other vehicles
	hkpPhysicsSystem* vehicleSystem = createVehicle();


	// Clone the vehicle and add the clones to the world

	hkArray<hkAabb> spawnVolumes;
	spawnVolumes.pushBack(hkAabb(hkVector4(-95, 2, -95), hkVector4(95, 8, 95)));

	AabbSpawnUtil spawnUtil( spawnVolumes );

	for ( int i = 0; i < variant.m_numVehicles; ++i )
	{
		hkpPhysicsSystem* newVehicleSystem = vehicleSystem->clone();

		hkVector4 objectSize( 4, 4, 4 );
		hkVector4 position; 
		spawnUtil.getNewSpawnPosition( objectSize, position );

		newVehicleSystem->getRigidBodies()[0]->setPosition(position);
		m_vehicles[i] = static_cast<hkpVehicleInstance*>(newVehicleSystem->getActions()[0]);
		m_vehicles[i]->addReference();
		m_world->addPhysicsSystem( newVehicleSystem );
		newVehicleSystem->removeReference();
	}

	createWheels(variant.m_numVehicles);

	vehicleSystem->removeReference();

	m_world->unlock();
}
Exemple #4
0
gkLogic::gkLogic(gkScene* scene)
	: m_scene(scene), m_tree(0),
	  m_camera(scene->getMainCamera()), m_upKeyNode(0), m_downKeyNode(0),
	  m_leftKeyNode(0), m_rightKeyNode(0), m_spaceKeyNode(0), m_rKeyNode(0),
	  m_cameraNode(0), m_dKeyNode(0), m_cKeyNode(0)
{
	GK_ASSERT(m_scene);
	m_tree = gkNodeManager::getSingleton().createLogicTree(m_scene->getGroupName());

	createInput();
	createVehicle();
	createCamera();
	createDisplayProps();

	m_tree->solveOrder();
	m_camera->attachLogic(m_tree);
}
static int testSteeringScreen_Enter( void )
{
	cam_TurnOnFlags( 0, 1 );

	int width, height;
	gfx_GetRenderSize( &width, &height );
	cam_SetCenteredProjectionMatrix( 0, width, height );

	bordersMax.x = ( (float)width / 2.0f );
	bordersMax.y = ( (float)height / 2.0f );
	bordersMin.x = -( (float)width / 2.0f );
	bordersMin.y = -( (float)height / 2.0f );
	
	gfx_SetClearColor( CLR_BLACK );

	createVehicle( VEC2_ZERO, CLR_GREEN );

	input_BindOnMouseButtonPress( SDL_BUTTON_LEFT, repositionTarget );

	return 1;
}
PVehicle *PSim::createVehicle(TiXmlElement *element, const std::string &filepath, PSSModel &ssModel)
{
  const char *val;
  
  const char *type = element->Attribute("type");
  if (!type) {
    PUtil::outLog() << "Vehicle has no type\n";
    return null;
  }
  
  vec3f pos = vec3f::zero();
  
  val = element->Attribute("pos");
  if (val) sscanf(val, "%f , %f , %f", &pos.x, &pos.y, &pos.z);
  
  quatf ori = quatf::identity();
  
  val = element->Attribute("ori");
  if (val) sscanf(val, "%f , %f , %f , %f", &ori.w, &ori.x, &ori.y, &ori.z);
  
  return createVehicle(type, pos, ori, filepath, ssModel);
}
void
GameObjectInfo_Boat::createAllBoats( GameObjectList& gameObjects )
{
	GameObjectInfo_Boat* veh = 0;

	// Patrolboat
	veh = dynamic_cast<GameObjectInfo_Boat*>(createVehicle(GameObjectInfo::GO_CAT_BOAT));
	veh->descriptiveName_ =	"Patrolboat";
	veh->tinyName_ = "PBR31";
	veh->modelName_ = "pbr31mk2";
	veh->gameSet_ = MF_GAMESET_MODERN;
	veh->category_ = GameObjectInfo::GO_CAT_BOAT;
	veh->class_ = CLASS_BOAT_PATROL;
	veh->flags_ = 0;
	veh->caps_ = HC_DUALGUNS;
	veh->renderFlags_ = 0;	
    VectorSet( veh->turnSpeed_, 50, 100, 20 );		
	VectorSet( veh->camDist_, 0, 100, 70 );
	VectorSet( veh->camHeight_ , 0, 100, 20);		
    veh->maxHealth_ = 350;		
	veh->shadowShader_ = SHADOW_DEFAULT;	
	Vector4Set( veh->shadowCoords_, 4, 0, 34, 24 );	
	Vector4Set( veh->shadowAdjusts_, 0, 0, 0, 0 );	
	VectorSet( veh->gunoffset_, 5, 0, 8 );		
	VectorSet( veh->cockpitview_, 0, 0, 6 );	
	veh->airRadar_ = new VehicleRadarInfo(-1, 8000, CAT_PLANE|CAT_HELO);		
	veh->groundRadar_ = new VehicleRadarInfo(0, 7000, CAT_GROUND|CAT_BOAT);			
	veh->minThrottle_ = -5;
	veh->maxThrottle_ = 10;
	veh->acceleration_ = 15;
	veh->maxFuel_ = 150;
	veh->sonarInfo_ = new VehicleRadarInfo(0, 3000, CAT_BOAT); 		
    veh->maxSpeed_ = 50;		
	gameObjects.push_back(veh);
	//8,							// max angle to lean when turning <- gearheight
	//-5,							// bowangle (depends on speeed) <-tailangle 
}
VehicleApiDemo::VehicleApiDemo(hkDemoEnvironment* env)
:	hkDefaultPhysicsDemo(env)
{
	m_tag = 0;

	///[driverInput]
	/// Initially controller is set to 0,0 i.e. neither turning left/right or forward/backward,
	/// so vehicle is not accelerating or turning.	///
	m_inputXPosition = 0.0f;
	m_inputYPosition = 0.0f;
	///>

	{
		hkVector4 from(0.0f, 0.0f, 10.0f);
		hkVector4 to(0.0f, 0.0f, 0.0f);
		hkVector4 up(0.0f, 1.0f, 0.0f);
		setupDefaultCameras( env, from, to, up );
	}

	//
	// Create the world.
	//
	{
		hkpWorldCinfo info;
		info.m_collisionTolerance = 0.1f;
		info.m_gravity.set(0.0f, -9.8f, 0.0f);
		info.setBroadPhaseWorldSize(1000.0f) ;
		info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
		m_world = new hkpWorld( info );
		m_world->lock();

		// Register all agents.
		hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher());

		// Graphics.
		setupGraphics();

	}

	///[buildLandscape]
	/// Build the landscape to drive on and add it to m_world. The landscape is simply five
	/// boxes, one for the ground and four for the walls.
	///
	buildLandscape();
	///>

	///
	/// Create the chassis
	///
	hkpConvexVerticesShape* chassisShape = VehicleApiUtils::createCarChassisShape(); 
	hkpRigidBody* chassisRigidBody;
	{
		hkpRigidBodyCinfo chassisInfo;

		// NB: The inertia value is reset by the vehicle SDK.  However we give it a
		// reasonable value so that the hkpRigidBody does not assert on construction. See
		// VehicleSetup for the yaw, pitch and roll values used by hkVehicle.
		chassisInfo.m_mass = 750.0f;	
		chassisInfo.m_shape = chassisShape;
		chassisInfo.m_friction = 0.4f;

		// The chassis MUST have m_motionType hkpMotion::MOTION_BOX_INERTIA to correctly simulate
		// vehicle roll, pitch and yaw.
		chassisInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
		chassisInfo.m_position.set(0.0f, 1.0f, 0.0f);
		hkpInertiaTensorComputer::setShapeVolumeMassProperties(chassisInfo.m_shape,
										chassisInfo.m_mass,
										chassisInfo);

		chassisRigidBody = new hkpRigidBody(chassisInfo);

		// No longer need reference to shape as the hkpRigidBody holds one.
		chassisShape->removeReference();

		m_world->addEntity(chassisRigidBody);
	}
	///>
	/// In this example, the chassis is added to the Vehicle Kit in the createVehicle() method.


	///
	createVehicle( chassisRigidBody );
	chassisRigidBody->removeReference();
	///>

	///[buildVehicleCamera]
	/// This camera follows the vehicle when it moves.
	///
	{
		VehicleApiUtils::createCamera( m_camera );
	}
	///>

	createDisplayWheels();

	m_world->unlock();
}
Exemple #9
0
TruckDemo::TruckDemo(hkDemoEnvironment* env)
:	CarDemo(env, false, 4, 1)
{
	m_world->lock();
	{
		//
		// Create vehicle's chassis shape.
		//
		hkpConvexVerticesShape* chassisShape = HK_NULL;
		{
			hkReal xSize = 1.9f;
			hkReal xSizeFrontTop = 0.7f;
			hkReal xSizeFrontMid = 1.6f;
			hkReal ySize = 0.9f;
			hkReal ySizeMid = ySize - 0.7f;
			hkReal zSize = 1.0f;

			//hkReal xBumper = 1.9f;
			//hkReal yBumper = 0.35f;
			//hkReal zBumper = 1.0f;

			// 16 = 4 (size of "each float group", 3 for x,y,z, 1 for padding) * 4 (size of float).
			int stride = sizeof(float) * 4;
			
			{
				int numVertices = 10;

				float vertices[] = { 
					xSizeFrontTop, ySize, zSize, 0.0f,	// v0
					xSizeFrontTop, ySize, -zSize, 0.0f,	// v1
					xSize, -ySize, zSize, 0.0f,			// v2
					xSize, -ySize, -zSize, 0.0f,		// v3
					-xSize, ySize, zSize, 0.0f,			// v4
					-xSize, ySize, -zSize, 0.0f,		// v5
					-xSize, -ySize, zSize, 0.0f,		// v6
					-xSize, -ySize, -zSize, 0.0f,		// v7
					xSizeFrontMid, ySizeMid, zSize, 0.0f,	// v8
					xSizeFrontMid, ySizeMid, -zSize, 0.0f,	// v9
				};
				
				//
				// SHAPE CONSTRUCTION.
				//
				{
					hkStridedVertices stridedVerts;
					{
						stridedVerts.m_numVertices = numVertices;
						stridedVerts.m_striding = stride;
						stridedVerts.m_vertices = vertices;
					}
					chassisShape = new hkpConvexVerticesShape(stridedVerts);
				}
			}
		}

		createDisplayWheels(0.5f, 0.3f);

		for (int vehicleId = 0; vehicleId < m_numVehicles; vehicleId++)
		{
			//
			// Create the vehicle.
			//
			{
				//
				// Create the chassis body.
				//
				hkpRigidBody* chassisRigidBody;
				{
					hkpRigidBodyCinfo chassisInfo;

					chassisInfo.m_mass = 5000.0f;	
					chassisInfo.m_shape = chassisShape;
					chassisInfo.m_friction = 0.8f;
					chassisInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
					// Position chassis on the ground.
					chassisInfo.m_position.set(-10.0f, -4.5f, vehicleId * 5.0f);
					hkpInertiaTensorComputer::setShapeVolumeMassProperties(chassisInfo.m_shape,
																			chassisInfo.m_mass,
																			chassisInfo);

					chassisRigidBody = new hkpRigidBody(chassisInfo);
				}

				TruckSetup tsetup;
				m_vehicles[vehicleId].m_vehicle = createVehicle( tsetup, chassisRigidBody);
				m_vehicles[vehicleId].m_lastRPM = 0.0f;

				HK_SET_OBJECT_COLOR((hkUlong)chassisRigidBody->getCollidable(), 0x80ff8080);

				// This hkpAction flips the car upright if it turns over. 	 
				if (vehicleId == 0) 	 
				{ 	 
					hkVector4 rotationAxis(1.0f, 0.0f, 0.0f); 	 
					hkVector4 upAxis(0.0f, 1.0f, 0.0f); 	 
					hkReal strength = 8.0f; 	 
					m_reorientAction = new hkpReorientAction(chassisRigidBody, rotationAxis, upAxis, strength); 	 
				}

				chassisRigidBody->removeReference();
			}
		}
		chassisShape->removeReference();
	}

	//
	// Create the camera.
	//
	{
		VehicleApiUtils::createCamera( m_camera );
	}
	m_world->unlock();
}
void ASimModeWorldMultiRotor::setupVehiclesAndCamera(std::vector<VehiclePtr>& vehicles)
{
    //get player controller
    APlayerController* player_controller = this->GetWorld()->GetFirstPlayerController();
    FTransform actor_transform = player_controller->GetActorTransform();
    //put camera little bit above vehicle
    FTransform camera_transform(actor_transform.GetLocation() + FVector(-300, 0, 200));

    //we will either find external camera if it already exist in evironment or create one
    APIPCamera* external_camera;

    //find all BP camera directors in the environment
    {
        TArray<AActor*> camera_dirs;
        UAirBlueprintLib::FindAllActor<ACameraDirector>(this, camera_dirs);
        if (camera_dirs.Num() == 0) {
            //create director
            FActorSpawnParameters camera_spawn_params;
            camera_spawn_params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
            CameraDirector = this->GetWorld()->SpawnActor<ACameraDirector>(camera_director_class_, camera_transform, camera_spawn_params);
            spawned_actors_.Add(CameraDirector);

            //create external camera required for the director
            external_camera = this->GetWorld()->SpawnActor<APIPCamera>(external_camera_class_, camera_transform, camera_spawn_params);
            spawned_actors_.Add(external_camera);
        }
        else {
            CameraDirector = static_cast<ACameraDirector*>(camera_dirs[0]);
            external_camera = CameraDirector->getExternalCamera();
        }
    }

    //find all vehicle pawns
    {
        TArray<AActor*> pawns;
        UAirBlueprintLib::FindAllActor<TMultiRotorPawn>(this, pawns);

        //if no vehicle pawns exists in environment
        if (pawns.Num() == 0) {
            //create vehicle pawn
            FActorSpawnParameters pawn_spawn_params;
            pawn_spawn_params.SpawnCollisionHandlingOverride = 
                ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
            TMultiRotorPawn* spawned_pawn = this->GetWorld()->SpawnActor<TMultiRotorPawn>(
                vehicle_pawn_class_, actor_transform, pawn_spawn_params);

            spawned_actors_.Add(spawned_pawn);
            pawns.Add(spawned_pawn);
        }

        //set up vehicle pawns
        for (AActor* pawn : pawns)
        {
            //initialize each vehicle pawn we found
            TMultiRotorPawn* vehicle_pawn = static_cast<TMultiRotorPawn*>(pawn);
            vehicle_pawn->initializeForBeginPlay();

            //chose first pawn as FPV if none is designated as FPV
            VehiclePawnWrapper* wrapper = vehicle_pawn->getVehiclePawnWrapper();
            if (enable_collision_passthrough)
                wrapper->config.enable_passthrough_on_collisions = true;  
            if (wrapper->config.is_fpv_vehicle || fpv_vehicle_pawn_wrapper_ == nullptr)
                fpv_vehicle_pawn_wrapper_ = wrapper;

            //now create the connector for each pawn
            auto vehicle = createVehicle(wrapper);
            if (vehicle != nullptr) {
                vehicles.push_back(vehicle);

                if (fpv_vehicle_pawn_wrapper_ == wrapper)
                    fpv_vehicle_connector_ = vehicle;
            }
            //else we don't have vehicle for this pawn
        }
    }

    CameraDirector->initializeForBeginPlay(getInitialViewMode(), fpv_vehicle_pawn_wrapper_, external_camera);
}
Exemple #11
0
PVehicle *PSim::createVehicle(const std::string &type, const vec3f &pos, const quatf &ori, const std::string &filepath, PSSModel &ssModel)
{
  PVehicleType *vtype = loadVehicleType(PUtil::assemblePath(type, filepath), ssModel);
  
  return createVehicle(vtype, pos, ori, ssModel);
}