void fKinematicController::draw(sf::RenderTarget &target, sf::RenderStates states) const {
	if(_debugDraw)
	{
		sf::RectangleShape rectangle;
		rectangle.setPosition(sf::Vector2f(getAABB().left, getAABB().top));
		rectangle.setSize(sf::Vector2f(_aabbSize.x, _aabbSize.y));
		rectangle.setOutlineColor(sf::Color::Green);
		rectangle.setOutlineThickness(1);
		rectangle.setFillColor(sf::Color::Transparent);
		target.draw(rectangle, states);
	}
}
Beispiel #2
0
int main(int argc, char * argv[])
{
    if(argc != 2)
    {
        std::cerr << "Usage : ply2h <label> <file.ply >file.h\n";
        return EXIT_FAILURE;
    }

    std::vector<Vertex> vertices;
    std::vector<Face> faces;

    if(!load(std::cin, vertices, faces))
    {
        std::cerr << "Input corrupted\n";
        return EXIT_FAILURE;
    }

    AABB aabb = getAABB(vertices);
    AABB new_aabb = { -1, 1, -1, 1, -1, 1 };

    convertAABB(vertices, aabb, new_aabb);

    if(!save(std::cout, argv[1], vertices, faces))
    {
        std::cerr << "Error while saving\n";
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
Beispiel #3
0
	gaProceduralTown()
		: m_intersectCount(0)
	{
		coUint32 seed = 1;
		for (coFloat& gridVal : m_grid)
		{
			gridVal = coMath_f::randFloat(seed) * 0.9f + 0.1f;
		}

		coAABB aabb;
		for (coUint y = 0; y < GRID_SIZE; ++y)
		{
			for (coUint x = 0; x < GRID_SIZE; ++x)
			{
				getAABB(aabb, x, y);

				m_bvh.insert(aabb, x | (y << 16));
			}
		}

		coAABB groundAABB(coVec3(0.f), SCALE*coVec3((coFloat)GRID_SIZE, (coFloat)GRID_SIZE, 0.001f));
		m_bvh.insert(groundAABB, 0);

		coLOG("leafs: "<<m_bvh.getLeafCount()<<", nodes: "<<m_bvh.getNodeCount());

		gaDumpBVH(m_bvh);
	}
Beispiel #4
0
void Geometry::renderAABB() const {
  static GLuint indices[]={
		0,1,2,3, 4,5,6,7, 1,4,7,2, 5,0,3,6, 5,4,1,0, 3,2,7,6
  };

	AxisAlignedBoundingBox::Vertices vertices;
	getAABB(vertices);

	glPushAttrib(GL_ENABLE_BIT);
	glDisable(GL_CULL_FACE);
	glDisable(GL_LIGHTING);

	GLint polygon_mode[2];
	glGetIntegerv(GL_POLYGON_MODE,polygon_mode);
	glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

	glBegin(GL_QUADS);
		for (int i=23;i>=0;--i) glVertex3fv(vertices[indices[i]].getData());
	glEnd();

	glPolygonMode(GL_FRONT,polygon_mode[0]);
	glPolygonMode(GL_BACK,polygon_mode[1]);

	glPopAttrib();
}
Beispiel #5
0
PlayerBase::PlayerBase(const std::string &newName, const glm::vec3 &newColor, const float &newSpeed, ObjModel *newMesh, unsigned int tex)
: name(newName), color(newColor), speed(newSpeed), mesh(newMesh), texture(tex)
{
	flyingAngle = rand() % 360;
	frame.position = glm::vec3(0.0f, 0.0f, 0.0f);
	_finished = false;
	aabb = getAABB(mesh);
}
Beispiel #6
0
void PressureBody::DrawMe()
{
	
	//AABB *aabb = getAABB();
	
    float srodekX = ((getAABB()->Max.X - getAABB()->Min.X)/2) + getAABB()->Min.X;
    float srodekY = ((getAABB()->Max.Y - getAABB()->Min.Y)/2) + getAABB()->Min.Y;

	Vector2 *shape = new Vector2[mPointMassesC+2];

    shape[0].X = srodekX;
	shape[0].Y = srodekY;

    for (unsigned int i = 0; i < mPointMassesC; i++)
    {
        shape[i+1] = ((PointMass*)mPointMasses.at(i))->Position;
    }

    shape[mPointMassesC + 1] = mPointMasses[0]->Position;

	Renderer::FillBlobShape(shape,(mPointMassesC+2),0,1,0);
	Renderer::RenderGlobalShapeLine(mPointMasses,0,0,0);

	//delete aabb;
	delete [] shape;
}
Beispiel #7
0
AABB Sprite3D::getAABBRecursively()
{
    AABB aabb;
    const auto children = getChildren();
    for (const auto iter: children)
    {
        Sprite3D* child = dynamic_cast<Sprite3D*>(iter);
        if(child)
        {
            aabb.merge(child->getAABBRecursively());
        }
    }
    aabb.merge(getAABB());
    return aabb;
}
bool fKinematicController::overlaps(fGroup *group, const std::function<void (fKinematicController *a, fKinematicController *b)> f )
{
	bool overlaps = false;
	for(unsigned i = 0; i<group->size(); i++)
	{
		fKinematicController *a;
		if((*group)[i]->isAlive() &&  (a = dynamic_cast<fKinematicController *>((*group)[i])) != nullptr)
		{
			if(getAABB().intersects(a->getAABB()))
			{
				f(this, a);
				overlaps = true;
			}
		}
	}
	return overlaps;
}
Beispiel #9
0
void EnemyGrunt::subUpdate(float dt, int subStep, int numSubSteps) {
	float numSubstepsInv = 1.0f / numSubSteps;

	// Walls
	sf::FloatRect newAABB = getAABB();

	if (getRoom()->wallCollision(newAABB)) {
		setPosition(ltbl::rectCenter(newAABB));
		_hitWall = true;
	}

	// Accumulate pushes
	std::vector<QuadtreeOccupant*> occupants;

	sf::FloatRect rangeRect = ltbl::rectFromBounds(_position - sf::Vector2f(_radius, _radius), _position + sf::Vector2f(_radius, _radius));

	getRoom()->getQuadtree().queryRegion(occupants, rangeRect);

	sf::Vector2f moveDir(0.0f, 0.0f);

	for (int i = 0; i < occupants.size(); i++) {
		Entity* pEntity = static_cast<Entity*>(occupants[i]);

		if (pEntity != this && (pEntity->_type == 1 || pEntity->_type == 2)) {
			float entityRadius = std::max(pEntity->getAABB().width, pEntity->getAABB().height);

			sf::Vector2f dir = _position - ltbl::rectCenter(pEntity->getAABB());

			float dist = ltbl::vectorMagnitude(dir);

			if (dist < entityRadius + _radius)
				moveDir += ltbl::vectorNormalize(dir) * numSubstepsInv;
		}
	}

	_position += moveDir;
}
Beispiel #10
0
	void occlusionCulling(std::list<std::shared_ptr<DRBData>> &list, bool drawDebugLines)
	{
		SCOPE_profile_cpu_function("Camera system");

		auto depthMap = GetRenderThread()->getDepthMapManager().getReadableMap();
		//for (auto &e : cameraList->meshs)
		//{
		//	readableDepthMap->testBox()
		//}

		if (depthMap.isValid() == false)
		{
			return;
		}

		auto j = list.begin();
		while (j != std::end(list))
		{
			auto &d = *j;
			auto mesh = std::static_pointer_cast<DRBMeshData>(d);
			if (mesh->hadRenderMode(AGE_OCCLUDER))
			{
				++j;
				continue;
			}
			auto BB = mesh->getAABB();


			glm::vec2 minPoint = glm::vec2(1);
			glm::vec2 maxPoint = glm::vec2(-1);

			float minZ = std::numeric_limits<float>::max();

			for (std::size_t i = 0; i < 8; ++i)
			{
				auto point = depthMap->getMV() * d->getTransformation() * glm::vec4(BB.getCornerPoint(i), 1.0f);
				point /= point.w;

				if (point.x < -1)
				{
					point.x = -1;
				}
				if (point.y < -1)
				{
					point.y = -1;
				}
				if (point.x > 1)
				{
					point.x = 1;
				}
				if (point.y > 1)
				{
					point.y = 1;
				}

				minPoint.x = std::min(minPoint.x, point.x);
				minPoint.y = std::min(minPoint.y, point.y);
				maxPoint.x = std::max(maxPoint.x, point.x);
				maxPoint.y = std::max(maxPoint.y, point.y);

				point.z = (point.z + 1.0f) * 0.5f;
				minZ = std::min(minZ, point.z);
			}

			glm::uvec2 screenMin(((minPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight()));
			glm::uvec2 screenMax(((maxPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight()));

			if (minZ < 0)
			{
				minZ = 0;
			}

			if (depthMap->testBox((uint32_t)(minZ * (1 << 24)), screenMin, screenMax) == false)
			{
				list.erase(j++);
				continue;
			}
			if (drawDebugLines)
			{
				GetRenderThread()->getQueue()->emplaceTask<AGE::Commands::ToRender::Draw2DQuad>(glm::vec2(minPoint.x, minPoint.y), glm::vec2(minPoint.x, maxPoint.y), glm::vec2(maxPoint.x, maxPoint.y), glm::vec2(maxPoint.x, minPoint.y), glm::vec3(0, 1, 0));
			}
			++j;
		}
	}
Beispiel #11
0
AABB Shape::getClippedAABB(const AABB &box) const {
	AABB result = getAABB();
	result.clip(box);
	return result;
}
Beispiel #12
0
void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
#if CC_USE_CULLING
    // camera clipping
    if(_children.size() == 0 && Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&getAABB()))
        return;
#endif
    
    if (_skeleton)
        _skeleton->updateBoneMatrix();
    
    Color4F color(getDisplayedColor());
    color.a = getDisplayedOpacity() / 255.0f;
    
    //check light and determine the shader used
    const auto& scene = Director::getInstance()->getRunningScene();

    // Don't override GLProgramState if using manually set Material
    if (_usingAutogeneratedGLProgram && scene)
    {
        const auto lights = scene->getLights();
        bool usingLight = false;
        for (const auto light : lights) {
            usingLight = light->isEnabled() && ((static_cast<unsigned int>(light->getLightFlag()) & _lightMask) > 0);
            if (usingLight)
                break;
        }
        if (usingLight != _shaderUsingLight)
        {
            genMaterial(usingLight);
        }
    }
    
    for (auto mesh: _meshes)
    {
        mesh->draw(renderer,
                   _globalZOrder,
                   transform,
                   flags,
                   _lightMask,
                   Vec4(color.r, color.g, color.b, color.a),
                   _forceDepthWrite);

    }
}
bool CollisionInfoAABB::PairwiseCollisionTest( CollisionInfo *other )
{
	return other->CollisionTest( &( getAABB()) );
}
bool CollisionInfoAABB::CollisionTest( sf::Sprite *s, CollisionTools::TextureBitmap *b )
{
	return CollisionTools::RectangleSpriteIntersection( getAABB(), *s, *b);
}
bool CollisionInfoAABB::CollisionTest( sf::Shape *s)
{
	return CollisionTools::RectangleShapeIntersection( getAABB(), *s );
}
inline bool fKinematicController::overlaps(const fKinematicController *other) const { return getAABB().intersects(other->getAABB()); }
std::shared_ptr<Mesh> OctreeSDF::generateMesh()
{
	std::vector<Cube> cubes = getCubesToMarch();
	return MarchingCubes::marchSDF(cubes, getInverseCellSize(), getAABB().min);
}
Beispiel #18
0
void Player::update(sf::Time dt)
{


	if(mIsMovingLeft || mIsMovingRight || mIsJumping)
		mMovement.x*=mFrictionStart;
	else
		mMovement.x*=mFrictionStop;

	if(mIsJumping)
		mMovement.y+=mFrictionVertical;

 
	
	sf::FloatRect playerRect = getTransform().transformRect(mAnimation.getGlobalBounds());
	playerRect.left+=mMovement.x*dt.asSeconds();
	playerRect.top+=mMovement.y*dt.asSeconds();

	// Update player's collision points
	mCollPoints.up[0]=sf::Vector2f(playerRect.left+mCollMarg,playerRect.top);
	mCollPoints.up[1]=sf::Vector2f(playerRect.left+playerRect.width-mCollMarg,playerRect.top);
	mCollPoints.down[0]=sf::Vector2f(playerRect.left+mCollMarg,playerRect.top+playerRect.height);
	mCollPoints.down[1]=sf::Vector2f(playerRect.left+playerRect.width-mCollMarg,playerRect.top+playerRect.height);
	mCollPoints.left[0]=sf::Vector2f(playerRect.left,playerRect.top+mCollMarg);
	mCollPoints.left[1]=sf::Vector2f(playerRect.left,playerRect.top+playerRect.height-mCollMarg);
	mCollPoints.left[2]=sf::Vector2f(playerRect.left,playerRect.top+playerRect.height/2);
	mCollPoints.right[0]=sf::Vector2f(playerRect.left+playerRect.width,playerRect.top+mCollMarg);
	mCollPoints.right[1]=sf::Vector2f(playerRect.left+playerRect.width,playerRect.top+playerRect.height-mCollMarg);
	mCollPoints.right[2]=sf::Vector2f(playerRect.left+playerRect.width,playerRect.top+playerRect.height/2);

	//Collision detection
	collisionDetection(playerRect);
	pickupCollisionDetection(playerRect);



	if(mCollisionRight)
		if(mMovement.x>0)
			mMovement.x*=-0.1f;
			
	if(mCollisionLeft)
		if(mMovement.x<0)
			mMovement.x*=-0.1f;

	if(mCollisionUp)
		if(mMovement.y<0)
			mMovement.y*=-0.1f;

	if(mCollisionDown)
	{
		if(!(mIsMovingLeft || mIsMovingRight || mPlayerDead))
			mAnimation.playAnimation("stay");
		if(mMovement.y>0)
		//	mMovement.y*=-0.1f;
			mMovement.y=0;

		mIsJumping=false;
	}
	else
	{
		/*if(mAnimation.getCurrentAnimation()!="jump")
			mAnimation.playAnimation("fall");*/
		mIsJumping=true;
		mMovement.y+=getGravity();
	}


	
	mAnimation.update(dt);

	move(mMovement*dt.asSeconds());

	if(mEnemyManager->intersection(getAABB()))
	{
			mPlayerDead=true;
			mAnimation.playAnimation("dead");
	}

	if(mStar->getGlobalBounds().intersects(getAABB()))
		mLevelCompleted=true;

	//ss.str("");
	//ss << "Left: "<<(int)mCollisionLeft<< "\nRight: "<<(int)mCollisionRight<<"\nUp: "<<(int)mCollisionUp<<"\nDown: "<<(int)mCollisionDown;// put float into string buffer
	
	//Reset variables

	mIsMovingLeft=false;
	mIsMovingRight=false;

	mCollisionDown=false;
	mCollisionLeft=false;
	mCollisionRight=false;
	mCollisionUp=false; 
	
}
bool CollisionInfoAABB::CollisionTest( sf::FloatRect *r )
{
	return getAABB().intersects(*r);
}
Beispiel #20
0
Rect Sprite3D::getBoundingBox() const
{
    AABB aabb = getAABB();
    Rect ret(aabb._min.x, aabb._min.y, (aabb._max.x - aabb._min.x), (aabb._max.y - aabb._min.y));
    return ret;
}
Beispiel #21
0
int main(int argc, char* argv[])
{
    if (argc < 3) {
        return 1;
    }

    std::string inFile(argv[1]);
    std::string outFile(argv[2]);

    auto reader = (Potree::LASPointReader*)Proxy::createPointReader(inFile);

    if (!reader) {
        // TODO
        return 1;
    }

    auto aabb = reader->getAABB();

    aabb.size = aabb.max - aabb.min;

    aabb.makeCubic();

    uint64_t pointNum = 0;
    uint64_t flushNum = 0;

    FILE* fp = nullptr;
    fopen_s(&fp, outFile.c_str(), "wb");

    fseek(fp, sizeof(TMPHeader), SEEK_SET);

    std::vector<Point> points;
    points.reserve(reader->numPoints());

    static const uint32_t FLUSH_NUM = 10000;

    while (reader->readNextPoint()) {
        auto point = reader->getPoint();

        pointNum++;
        flushNum++;

        Point pt;

        pt.pos[0] = point.position.x;
        pt.pos[1] = point.position.y;
        pt.pos[2] = point.position.z;

        pt.rgba[0] = point.color.x;
        pt.rgba[1] = point.color.y;
        pt.rgba[2] = point.color.z;
        pt.rgba[3] = 0xff;

        points.push_back(pt);

        if (flushNum == FLUSH_NUM) {
            printf("%d\n", pointNum);
            fwrite(&points[0], sizeof(Point), flushNum, fp);
            points.clear();
            flushNum = 0;
        }
    }

    if (flushNum > 0) {
        printf("%d\n", pointNum);
        fwrite(&points[0], sizeof(Point), flushNum, fp);
        points.clear();
        flushNum = 0;
    }

    // Write header.
    {
        TMPHeader header;
        header.fileSize = ftell(fp);
        header.vtxFormat = VtxFormat::Position | VtxFormat::Color;
        header.vtxNum = pointNum;
        
        auto& aabbMin = aabb.min;
        auto& aabbMax = aabb.max;

        header.aabbMin[0] = aabbMin.x;
        header.aabbMin[1] = aabbMin.y;
        header.aabbMin[2] = aabbMin.z;

        header.aabbMax[0] = aabbMax.x;
        header.aabbMax[1] = aabbMax.y;
        header.aabbMax[2] = aabbMax.z;

        fseek(fp, 0, SEEK_SET);
        fwrite(&header, sizeof(header), 1, fp);
    }

    fclose(fp);

	return 0;
}