Пример #1
0
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source) const
{
    assert(m_starSystem);
    assert(source.IsSystemPath());

    const SystemPath &dest = m_starSystem->GetPath();

    Sector source_sec(source.sectorX, source.sectorY, source.sectorZ);
    Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ);

    Sector::System source_sys = source_sec.m_systems[source.systemIndex];
    Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex];

    const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ);
    const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ);

    // find the first non-gravpoint. should be the primary star
    Body *primary = 0;
    for (BodyIterator i = BodiesBegin(); i != BodiesEnd(); ++i)
        if ((*i)->GetSystemBody()->type != SystemBody::TYPE_GRAVPOINT) {
            primary = *i;
            break;
        }
    assert(primary);

    // point along the line between source and dest, a reasonable distance
    // away based on the radius (don't want to end up inside black holes, and
    // then mix it up so that ships don't end up on top of each other
    vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0;
    assert(pos.Length() > primary->GetSystemBody()->GetRadius());
    return pos + primary->GetPositionRelTo(GetRootFrame());
}
Пример #2
0
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source, const SystemPath &dest) const
{
	assert(m_starSystem);
	assert(source.IsSystemPath());

	assert(dest.IsSameSystem(m_starSystem->GetPath()));

	RefCountedPtr<const Sector> source_sec = m_sectorCache->GetCached(source);
	RefCountedPtr<const Sector> dest_sec = m_sectorCache->GetCached(dest);

	Sector::System source_sys = source_sec->m_systems[source.systemIndex];
	Sector::System dest_sys = dest_sec->m_systems[dest.systemIndex];

	const vector3d sourcePos = vector3d(source_sys.GetPosition()) + vector3d(source.sectorX, source.sectorY, source.sectorZ);
	const vector3d destPos = vector3d(dest_sys.GetPosition()) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ);

	Body *primary = 0;
	if (dest.IsBodyPath()) {
		assert(dest.bodyIndex < m_starSystem->GetNumBodies());
		primary = FindBodyForPath(&dest);
		while (primary && primary->GetSystemBody()->GetSuperType() != SystemBody::SUPERTYPE_STAR) {
			SystemBody* parent = primary->GetSystemBody()->GetParent();
			primary = parent ? FindBodyForPath(&parent->GetPath()) : 0;
		}
	}
	if (!primary) {
		// find the first non-gravpoint. should be the primary star
		for (Body* b : GetBodies())
			if (b->GetSystemBody()->GetType() != SystemBody::TYPE_GRAVPOINT) {
				primary = b;
				break;
			}
	}
	assert(primary);

	// point along the line between source and dest, a reasonable distance
	// away based on the radius (don't want to end up inside black holes, and
	// then mix it up so that ships don't end up on top of each other
	vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0;
	assert(pos.Length() > primary->GetSystemBody()->GetRadius());
	return pos + primary->GetPositionRelTo(GetRootFrame());
}
Пример #3
0
void Space::CreateTestScene(Entity player, double time)
{
	auto renderer = p3::game->GetRenderer();
	m_renderer = renderer;

	StarSystemCache::ShrinkCache(SystemPath(), true);
	Sector::cache.ClearCache();
	SystemPath path(10,0,0,0);
	m_starSystem = StarSystemCache::GetCached(path);

	GenBody(time, m_starSystem->m_rootBody.Get(), m_rootFrame.get());
	m_rootFrame->UpdateOrbitRails(time, 1.0);

	//init "player"
	{
		auto model = p3::game->GetModelCache()->FindModel("kanara");
		SDL_assert(model);
		player.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		player.assign<PosOrientComponent>(vector3d(0,0,1e6), matrix3x3d(1.0));
		player.assign<MassComponent>(10.0);
		player.assign<DynamicsComponent>();
		player.assign<ThrusterComponent>();
		player.assign<WeaponComponent>();
		player.assign<PlayerInputComponent>();
		player.assign<CollisionMeshComponent>(player, model->GetCollisionMesh());
		player.assign<FrameComponent>(GetRootFrame());
		//player.assign<ColorComponent>(Color(0,255,255,255));
		player.assign<ShipAIComponent>();
		player.assign<NameComponent>("Player");

		GetRootFrame()->GetCollisionSpace()->AddGeom(player.component<CollisionMeshComponent>()->geom.get());
	}

	//init "AI"
	{
		auto model = p3::game->GetModelCache()->FindModel("natrix");
		SDL_assert(model);
		Entity ship = m_entities->create();
		ship.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		ship.assign<PosOrientComponent>(vector3d(0,0,1e6 - 200), matrix3x3d(1.0));
		ship.assign<MassComponent>(10.0);
		ship.assign<DynamicsComponent>();
		ship.assign<ThrusterComponent>();
		ship.assign<WeaponComponent>();
		ship.assign<CollisionMeshComponent>(ship, model->GetCollisionMesh());
		ship.assign<FrameComponent>(GetRootFrame());
		ship.assign<ColorComponent>(Color(255,0,0,255));
		ship.assign<ShipAIComponent>();
		ship.assign<NameComponent>("Drone");
		ship.assign<AICommandComponent>(); //kamikaze
		auto aicmd = ship.component<AICommandComponent>();
		aicmd->SetKamikaze(player);

		GetRootFrame()->GetCollisionSpace()->AddGeom(ship.component<CollisionMeshComponent>()->geom.get());
	}

	//some scenery
	//Entity obstacle = m_entities->create();
	if (0)
	{
		Entity obstacle = m_entities->create();
		auto model = p3::game->GetModelCache()->FindModel("kbuilding02");
		obstacle.assign<PosOrientComponent>(vector3d(0, 0, -200), matrix3x3d(1.0));
		obstacle.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		obstacle.assign<MassComponent>(100.0);
		obstacle.assign<DynamicsComponent>();
		obstacle.assign<CollisionMeshComponent>(obstacle, model->GetCollisionMesh());
		obstacle.assign<FrameComponent>(GetRootFrame());

		GetRootFrame()->GetCollisionSpace()->AddGeom(obstacle.component<CollisionMeshComponent>()->geom.get());

		Entity hangAroundMember = m_entities->create();
		hangAroundMember.assign<PosOrientComponent>(vector3d(0.0), matrix3x3d(1.0));
		hangAroundMember.assign<AttachToEntityComponent>(obstacle, vector3d(0, 50, 0));
		hangAroundMember.assign<GraphicComponent>(new ModelGraphic(renderer, model));
		hangAroundMember.assign<FrameComponent>(GetRootFrame());
	}

	//init camera
	//left camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.f, 0.f, 0.5f, 1.f);
		camc->camera->clearColor = Color(0, 40, 0, 0);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 50, 100), matrix3x3d(1.0));
		camera.assign<CameraLookAtComponent>(player);
		camera.assign<FrameComponent>(GetRootFrame());
		//camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 50));
	}

	//right top camera
	if (0)
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		camc->camera->viewport = vector4f(0.5f, 0.5f, 0.5f, 0.5f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(100, -10, -10), matrix3x3d(1.0));
		//camera.assign<CameraLookAtComponent>(obstacle);
		camera.assign<FrameComponent>(GetRootFrame());
	}
	//right bottom camera
	{
		Entity camera = m_entities->create();
		ent_ptr<CameraComponent> camc(new CameraComponent());
		camc->camera.reset(new Camera());
		//camc->camera->clearColor = Color(10, 10, 10, 0);
		camc->camera->viewport = vector4f(0.0f, 0.f, 1.0f, 1.0f);
		//camc->camera->viewport = vector4f(0.5f, 0.f, 0.5f, 1.0f);
		camera.assign(camc);
		camera.assign<PosOrientComponent>(vector3d(0, 0, 0), matrix3x3d(1.0));
		camera.assign<AttachToEntityComponent>(player, vector3d(0, 5, 10));
		camera.assign<FrameComponent>(GetRootFrame());
	}
}