コード例 #1
0
ファイル: game.cpp プロジェクト: mvaganov/aiglut201410
void Game::init() {
	objectMap.addLayer(Obstacle::STATIC, AABBf(V2f(-60, -60), V2f(60, 60)), V2i(16, 16));
	addObstacle(new CircleObject(Circf(V2f(-4, -4), 2), Obstacle::STATIC));
	addObstacle(new AABBObject(AABBf(V2f(-4, 1), V2f(-2, 5)), Obstacle::STATIC));
	addObstacle(new BoxObject(Boxf(V2f(4, 0), V2f(2, 5), V2f(1)), Obstacle::STATIC));
	addObstacle(new ConeObject(Conef(V2f(0, 1), 1.5f, (float)V_2PI * 1 / 8, (float)V_2PI * 3 / 8), Obstacle::STATIC)); // make the radius of the cone correct based on the calculated center
	V2f trapezoid[] = { V2f(-.5f, .5f), V2f(.5f, 1.2f), V2f(.5f, -1.5f), V2f(-.5f, -.8f) };
	int trapezoidCount = sizeof(trapezoid) / sizeof(trapezoid[0]);
	addObstacle(new PolygonObject(Polygon2f(V2f(5, -7), V2f((float)V_2PI*0.0f/6), trapezoid, trapezoidCount), Obstacle::STATIC)); // TODO raycast does not always hit the shape correctly from all sides
	V2f a(-2, -2), b(5, -4);
	addObstacle(new LineObject(Linef(&a, &b), Obstacle::STATIC));
	addObstacle(new PointObject(V2f(7, 7), Obstacle::STATIC));

	delaunyBoundary = new CircleObject(Circf(V2f::ZERO(), 100), Obstacle::EVERYTHING);
	delauny = new DelaunySet(delaunyBoundary);
	//delauny->addNode(V2f(3, 4));
	//delauny->addNode(V2f(-3, 4));
	//delauny->addNode(V2f(-3, -4));
	//delauny->addNode(V2f(0, -1));
//	for (int i = 0; i < 10; ++i) {
//		delauny->addNode(V2f::randomUnitVector() * Random::PRNGf() * 100);
//	}
	delauny->makeRandom(6);
	delauny->calculateAllTriangles();
}
コード例 #2
0
ファイル: DataSourcePlugin.cpp プロジェクト: chevtche/Livre
LODNode DataSourcePlugin::internalNodeToLODNode(
    const NodeId& internalNode) const
{
    const uint32_t refLevel = internalNode.getLevel();
    const Vector3ui& bricksInRefLevel =
        _volumeInfo.rootNode.getBlockSize(refLevel);
    const Boxi localBlockPos(internalNode.getPosition(),
                             internalNode.getPosition() + 1u);

    Vector3f boxCoordMin = localBlockPos.getMin();
    Vector3f boxCoordMax = localBlockPos.getMax();

    const size_t index = bricksInRefLevel.find_max_index();

    boxCoordMin = boxCoordMin / bricksInRefLevel[index];
    boxCoordMax = boxCoordMax / bricksInRefLevel[index];

    LBVERB << " Internal Node to LOD Node" << std::endl
           << " Node Id " << internalNode << " BricksInRefLevel "
           << bricksInRefLevel << std::endl
           << " lBoxCoordMin " << boxCoordMin << std::endl
           << " lBoxCoordMax " << boxCoordMax << std::endl
           << " volume world size " << _volumeInfo.worldSize << std::endl
           << std::endl;

    return LODNode(internalNode,
                   _volumeInfo.maximumBlockSize - _volumeInfo.overlap * 2,
                   Boxf(boxCoordMin * _volumeInfo.worldSize -
                            _volumeInfo.worldSize * 0.5f,
                        boxCoordMax * _volumeInfo.worldSize -
                            _volumeInfo.worldSize * 0.5f));
}
コード例 #3
0
	Boxf SphereCollider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
	{
		Vector3f size(m_radius * NazaraSuffixMacro(M_SQRT3, f) * scale);
		Vector3f position(offsetMatrix.GetTranslation());

		return Boxf(position - size, position + size);
	}
コード例 #4
0
void MoveComponent::update() {
	setSpeed();
	collide();
	
	// Stamp on the ground.
	Boxf characterFeet = Boxf(
	  Vec2(_puppet->worldBox().min().x() + TILESIZE / 3.0,
	       _puppet->worldBox().max().y() + 0.1 * COLLISION_DELTA),
	  Vec2(_puppet->worldBox().max().x() - TILESIZE / 3.0,
	       _puppet->worldBox().max().y() + 0.9 * COLLISION_DELTA));
	
	CollisionList intersections = _obj->scene()->level().collide(0, characterFeet);
	float amount = 0.0;
	
	for (Boxf collision: intersections)
		amount += collision.volume();
	
	if (amount > 0.9 * characterFeet.volume())
		_airTime = 0;
	else if (!_airTime && !_ladder)
		_airTime = 1;
	
	// Check ladder.
	if (!onLadder())
		_ladder = false;
}
コード例 #5
0
ファイル: LODNode.cpp プロジェクト: VMML/Livre
void LODNode::computeWorldBox_( const Vector3ui &levelTotalBlockDimensions )
{
    Vector3f lBoxCoordMin( getAbsolutePosition( ));
    Vector3f lBoxCoordMax( lBoxCoordMin + Vector3i( 1 ));

    const size_t index = levelTotalBlockDimensions.find_max_index();

    lBoxCoordMin = lBoxCoordMin / levelTotalBlockDimensions[index];
    lBoxCoordMax = lBoxCoordMax / levelTotalBlockDimensions[index];

    worldBox_ =  Boxf( lBoxCoordMin, lBoxCoordMax );
}
コード例 #6
0
ファイル: events.cpp プロジェクト: hernando/Livre
LODNodeSample deserializeDataSample( const ::zeq::Event& event )
{
    LODNodeSample sample;
    sample.first = event.getType();

    auto data = GetLODNode( event.getData( ));
    sample.second = livre::LODNode(
        NodeId( data->nodeId( )),
        _deserializeVector3< int32_t >( data->blockSize( )),
        Boxf( _deserializeVector3< float >( data->worldBoxMin( )),
              _deserializeVector3< float >( data->worldBoxMax( ))));

    return sample;
}
コード例 #7
0
ファイル: Camera.cpp プロジェクト: AdamosX/noser-sandbox
Matrix4x4f Camera::getWorldToClip(unsigned int width, unsigned int height) const
{
	Boxf from;
	if (height < width)
	{
		// Viewport is more wide than tall, so make sure m_zoom units are
		// visible on the Y axis.
		float aspect = (float)width / height;
		from = Boxf(
			-0.5f*m_zoom * aspect,
			0.5f*m_zoom,
			m_near,
			0.5f*m_zoom * aspect,
			-0.5f*m_zoom,
			m_far);
	}
	else
	{
		// Viewport is more tall than wide, so make sure m_zoom units are
		// visible on the X axis.
		float aspect = (float)height / width;
		from = Boxf(
			-0.5f*m_zoom,
			0.5f*m_zoom * aspect,
			m_near,
			0.5f*m_zoom,
			-0.5f*m_zoom * aspect,
			m_far);
	}

	Boxf to(-1.0f, 1.0f, 0.0f,
		1.0f, -1.0f, 1.0f);

	Matrix4x4f translate = Matrix4x4f::translate(-m_center);

	return Matrix4x4f::boxLerp(from, to) * m_rotation.getMatrix() * translate;
}
コード例 #8
0
bool MoveComponent::onLadder() {
	Boxf characterFeet = Boxf(
	  Vec2(_puppet->worldBox().min().x() + TILESIZE / 3.0,
	       _puppet->worldBox().max().y() - 1.9 * COLLISION_DELTA),
	  Vec2(_puppet->worldBox().max().x() - TILESIZE / 3.0,
	       _puppet->worldBox().max().y() - 1.1 * COLLISION_DELTA));
	
	CollisionList intersections = _obj->scene()->level().collide(1, characterFeet, true);
	float amount = 0.0;
	
	for (Boxf collision: intersections)
		amount += collision.volume();
	
	if (amount > 0.6 * characterFeet.volume())
		return true;
	return false;
}
コード例 #9
0
	Boxf Collider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
	{
		Vector3f min, max;

		// Check for existing collision handles, and create a temporary one if none is available
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
			}
			NewtonDestroyCollision(collision);
		}
		else
			NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);

		return Boxf(scale * min, scale * max);
	}
コード例 #10
0
	Boxf Collider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
	{
		Vector3f min, max;

		// Si nous n'avons aucune instance, nous en créons une temporaire
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
			}
			NewtonDestroyCollision(collision);
		}
		else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
			NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);

		return Boxf(scale * min, scale * max);
	}
コード例 #11
0
ファイル: DebugDrawer.cpp プロジェクト: GigAnon/NazaraEngine
	void DebugDrawer::Draw(const Boxi& box)
	{
		Draw(Boxf(box));
	}
コード例 #12
0
ファイル: DebugDrawer.cpp プロジェクト: GigAnon/NazaraEngine
	void DebugDrawer::Draw(const Vector3f& position, float size)
	{
		Draw(Boxf(position.x - size*0.5f, position.y - size*0.5f, position.z - size*0.5f, size, size, size));
	}