const RectangleF* FieldController::FindClosestRectangles(RectangleF* pRectangle, Chromosome* pChromosome, bool bDirection)
{
	std::vector<const RectangleF*> pModels = FindIntersectedRectangles(pRectangle, pChromosome, bDirection);

	const RectangleF* pResultModel = NULL;

	Vector2F projectionAxis;
	if (!bDirection)
		projectionAxis = Vector2F(0, 1);
	else
		projectionAxis = Vector2F(1, 0);

	Vector2F min, max, modelMin, modelMax;
	float minLength = 12345678.f;

	GetProjection(pRectangle, projectionAxis, modelMin, modelMax);

	for (int i = 0, i_end = pModels.size(); i < i_end; ++i)
	{
		GetProjection(pModels[i], projectionAxis, min, max);
		// we are interested in one side models only 
		if (min > modelMin)
		{
			Vector2F lengthVec = (modelMax - min);
			float tempLength = lengthVec.X() * lengthVec.X() + lengthVec.Y() * lengthVec.Y();
			if (tempLength < minLength)
			{
				pResultModel = pModels[i];
				minLength = tempLength;
			}
		}
	}

	return pResultModel;
}
Exemple #2
0
void RotateAction::Perform ()
{
	Action::Perform();

	assert(m_pSource);

	if (!m_pSource->Has<CMovement>()) return;

	// TODO: Mass affects angle increment?

	// Compute the rotation matrix
	float cos_theta = std::cos(m_theta);
	float sin_theta = std::sin(m_theta);
	Matrix2F rot{{cos_theta, -sin_theta,
					  sin_theta, cos_theta}};
	
	// Apply rotation on the object's direction
	VectorF const& dir = m_pSource->Get<CMovement>().GetDirection();
	ColMatrix2F res = rot * ColMatrix2F(dir);
	m_pSource->Get<CMovement>().SetDirection(Vector2F(res[0], res[1]));

	// Apply rotation on the object's surface polygon, if any
	if (m_pSource->Has<CBody>())
	{
		ColMatrix2F res;
		for (auto& v : m_pSource->Get<CBody>().GetSurface().vertices)
		{
			res = rot * ColMatrix2F(Vector2F(v.x, v.y));
			v.x = res[0];
			v.y = res[1];
		}
	}
}
float FieldController::GetHoleSquad(const RectangleF* pRectangle, Chromosome* pChromosome)
{
	std::vector<const RectangleF*> intersectedModels = FindIntersectedRectangles(pRectangle, pChromosome, VERTICAL_DIRECTION);

	if (intersectedModels.empty())
		return 0;

	std::vector<Segment> modelTopLine;
	modelTopLine.reserve(intersectedModels.size());


	std::vector<const RectangleF*>::const_iterator it_intersectedModels = intersectedModels.begin();
	while (it_intersectedModels != intersectedModels.end())
	{
		const RectangleF& rectangle = **it_intersectedModels;
		Segment topSegment(rectangle.GetTopLeft(), Vector2F(rectangle.GetBottomRight().X(), rectangle.GetTopLeft().Y()));
		modelTopLine.push_back(topSegment);
		++it_intersectedModels;
	}

	Segment topSegment(Vector2F(pRectangle->GetTopLeft().X(), pRectangle->GetBottomRight().Y()), pRectangle->GetBottomRight());
	LinesCalibrate(topSegment, modelTopLine);

	return HoleSquad(topSegment, modelTopLine);
}
Exemple #4
0
void QuadList::addQuad(float *quadvertices, float *quadtexcoords)
{
	// Allocate more memory and copy data
	float *newvertices = new float[vertexcount * 3 + 12];
	memcpy(newvertices, vertices, vertexcount * 3 * sizeof(float));
	if (vertices)
		delete[] vertices;
	vertices = newvertices;
	newvertices = &vertices[vertexcount * 3];
	memcpy(newvertices, quadvertices, 12 * sizeof(float));
	float *newtexcoords = new float[vertexcount * 2 + 8];
	memcpy(newtexcoords, texcoords, vertexcount * 2 * sizeof(float));
	if (texcoords)
		delete[] texcoords;
	texcoords = newtexcoords;
	newtexcoords = &texcoords[vertexcount * 2];
	memcpy(newtexcoords, quadtexcoords, 8 * sizeof(float));
	vertexcount += 4;
	// Set initial bounding rectangle if this is the first quad
	if (vertexcount == 4)
	{
		boundingrect.x = newvertices[0];
		boundingrect.y = newvertices[1];
	}
	// Increase bounding rectangle
	boundingrect.insertPoint(Vector2F(newvertices[0], newvertices[1]));
	boundingrect.insertPoint(Vector2F(newvertices[3], newvertices[4]));
	boundingrect.insertPoint(Vector2F(newvertices[6], newvertices[7]));
	boundingrect.insertPoint(Vector2F(newvertices[9], newvertices[10]));
}
Exemple #5
0
RectangleF* DB::ParseLineToRectangle( std::string& line )
{
	RectangleF* pRectangle = NULL;
	int separator_pos = 0, separator_next_pos = 0;
	while (true)
	{
		separator_next_pos = line.find(';', separator_pos);

		// if end of the line we go out
		if (separator_next_pos == -1)
			break;

		// get the format like that 'xx,xx' here
		std::string str_coord = line.substr(separator_pos + 1, separator_next_pos - separator_pos - 2);

		int coma_pos = str_coord.find(',');

		std::string str_x = str_coord.substr(0, coma_pos);
		std::string str_y = str_coord.substr(coma_pos + 1);

		float X = atof(str_x.c_str());
		float Y = atof(str_y.c_str());

		float halfX = X / 2.f;
		float halfY = Y / 2.f;

		pRectangle = new RectangleF(Vector2F(-halfX, -halfY), Vector2F(halfX, halfY));

		separator_pos = separator_next_pos + 1;
	}


	return pRectangle;
}
Exemple #6
0
Vector2F Vector2F::Normalize()
{
	double mag = sqrt(x*x + y*y);
	if (mag < 1.e-8)
		return Vector2F(x*1.e-8, y*1.e-8);

	float mul = (float)(1.0/mag);
	return Vector2F(x*mul, y*mul);
}
void FieldController::LinesCalibrate( const Segment& topSegment, std::vector<Segment>& modelTopLine )
{
	std::vector<Segment>::iterator  it_modelTopLine = modelTopLine.begin();
	while (it_modelTopLine != modelTopLine.end())
	{
		if (it_modelTopLine->start().X() < topSegment.start().X())
			it_modelTopLine->start().X() = topSegment.start().X();
		if (it_modelTopLine->end().X() > topSegment.end().X())
			it_modelTopLine->end().X() = topSegment.end().X();
		++it_modelTopLine;
	}
	SortSegmetnsByY(modelTopLine);


	Segment temp(Vector2F(1.f, 1.f), Vector2F(5.f, 1.f));
	bool res = temp.inside(Vector2F(1.f, 1.f));
	res = temp.inside(Vector2F(5.f, 1.f));
	res = temp.inside(Vector2F(4.f, 1.f));
	res = temp.inside(Vector2F(5.1f, 1.f));
	res = temp.inside(Vector2F(0.9f, 1.f));

	for (int i = 0, i_end = modelTopLine.size(); i < i_end; ++i)
	{
		for (int j = i + 1, j_end = modelTopLine.size(); j < j_end; ++j)
		{
			bool startInside = (modelTopLine[i].start().X() <= modelTopLine[j].start().X()) && (modelTopLine[j].start().X() <= modelTopLine[i].end().X());
			bool endInside = (modelTopLine[i].start().X() <= modelTopLine[j].end().X()) && (modelTopLine[j].end().X() <= modelTopLine[i].end().X());
			if (startInside && endInside)
			{
				it_modelTopLine = modelTopLine.begin();
				std::advance(it_modelTopLine, j);
				modelTopLine.erase(it_modelTopLine);
				i_end = j_end = modelTopLine.size();
				i = j = 0;
			}
			else if (startInside)
			{
				modelTopLine[j].start().X() = modelTopLine[i].end().X();
			}
			else if (endInside)
			{
				modelTopLine[j].end().X() = modelTopLine[i].start().X();
			}
			else if (modelTopLine[i].start().X() > modelTopLine[j].start().X() && modelTopLine[i].end().X() < modelTopLine[j].end().X())
			{
				modelTopLine.push_back(Segment(modelTopLine[j].start(), Vector2F(modelTopLine[i].start().X(), modelTopLine[j].start().Y())));
				modelTopLine.push_back(Segment(Vector2F(modelTopLine[i].end().X(), modelTopLine[j].end().Y()), modelTopLine[j].end()));
				it_modelTopLine = modelTopLine.begin();
				std::advance(it_modelTopLine, j);
				modelTopLine.erase(it_modelTopLine);
				i_end = j_end = modelTopLine.size();
			}
		}
	}
}
Exemple #8
0
void BaseFeather::computeTexcoord()
{
	Vector2F puv = m_uv;
	float *q = quilly();
	int i, j;
	for(i=0; i <= numSegment(); i++) {
		*segmentQuillTexcoord(i) = puv;
		if(i < numSegment()) {
			puv += Vector2F(0.f, *q);
			q++;
		}
	}
	
	q = quilly();
	puv = m_uv;
	
	Vector2F pvane;
	for(i=0; i <= numSegment(); i++) {
		
		pvane = puv;
		Vector2F * vanes = uvDisplaceAt(i, 0);
		
		for(j = 0; j < 3; j++) {
			pvane += vanes[j];
			*segmentVaneTexcoord(i, 0, j) = pvane;
		}

		pvane = puv;
		vanes = getUvDisplaceAt(i, 1);
		
		for(j = 0; j < 3; j++) {
			pvane += vanes[j];
			*segmentVaneTexcoord(i, 1, j) = pvane;
		}
		
		if(i < numSegment()) {
			puv += Vector2F(0.f, *q);
			q++;
		}
	}
	
	for(i = 0; i < numWorldP(); i++) {

		texcoord()[i] /= 32.f;
	}
		
	computeBounding();
	computeLength();
}
Exemple #9
0
  void CreatureMotionSys::UpdatePursuit(const PursuitObjTarget& target, TimeStep dt)
  {
    const MotionTaskState targetState = CheckPursuitPredState(target);
    if(targetState == MotionTaskState::SEEKING)
    {
      PursuitObjSeekingVRes pursuitResult;
      PursuitObjMethodV::Seek(m_Creature, target, PursuitObjSettingsV(), pursuitResult);
      SeekTargetVel(pursuitResult.velocity, dt);
    }
    else
    {
      const Vector2F currentPosition = m_Creature.GetPosition();
      const Vector2F targetPosition = target.target->GetPosition();
      const AnglePi targetAngle = (targetPosition - currentPosition).GetAngle();
      const Float targetSpeed = target.target->GetTotalLinVelocity().Length();
      if(targetSpeed == 0.0f)
      {
        const Vector2F targetLinVelocity = Vector2F(targetSpeed, 0.0f).Rotate(targetAngle);
        SeekTargetVel(targetLinVelocity, dt);
      }
      else
      {
        UpdateAngleSeeking(SeekAngleTarget(targetAngle), dt);
      }
    }

    UpdateMotionTargetState(targetState);
  }
Exemple #10
0
Vector2F MutableMatrix44D::project(const Vector3F& point,
                                   const int vpLeft,
                                   const int vpTop,
                                   const int vpWidth,
                                   const int vpHeight) const {
  const float x = point._x;
  const float y = point._y;
  const float z = point._z;
  //  const float w = 1.0;

  //Transformating point
  float out0 = (float) _m00 * x + (float) _m01 * y + (float) _m02 * z + (float) _m03 /* * w */;
  float out1 = (float) _m10 * x + (float) _m11 * y + (float) _m12 * z + (float) _m13 /* * w */;
  //float out2 = _m20 * x + _m21 * y + _m22 * z + _m23 * w;
  const float out3 = (float) _m30 * x + (float) _m31 * y + (float) _m32 * z + (float) _m33 /* * w */;

  if (out3 == 0.0) {
    return Vector2F::nan();
  }

  out0 /= out3;
  out1 /= out3;
  //out2 /= out3;

  const float winx = vpLeft + (1.0f + out0) * vpWidth / 2.0f;
  const float winy = vpTop  + (1.0f + out1) * vpHeight / 2.0f;
  //float winz = (1.0 + in2) / 2.0;
  return Vector2F(winx, winy);
}
void Rekd2D::Core::RunnableWindow::Render(unsigned int time)
{
	m_DefaultShader->Bind();
	MouseState state = Mouse::GetState();
	KeyboardState ks = Keyboard::GetState();
	bool hit = false;
	for (std::vector<IComponent*>::iterator it = m_Components.begin(); it != m_Components.end(); ++it)
	{
		if ((*it)->GetBounds().Collides(Vector2F(state.X, state.Y)))
		{
			if (!state.MouseButtons[1] && m_OldState.MouseButtons[1])
			{
				(*it)->Click(1);
				if ((ComponentFlag::Focusable & (*it)->GetFlags()) == ComponentFlag::Focusable)
				{
					Unfocus();
					(*it)->SetFlag(ComponentFlag::Focusable, 1);
				}
				else hit = true;
			}
		}
		if ((ComponentFlag::Pushable & (*it)->GetFlags()) == ComponentFlag::Pushable) (*it)->SetFlag(ComponentFlag::Pushable, (*it)->GetBounds().Collides(Vector2F(state.X, state.Y)) && state.MouseButtons[1]);
		if ((ComponentFlag::Hoverable & (*it)->GetFlags()) == ComponentFlag::Hoverable) (*it)->SetFlag(ComponentFlag::Hoverable, (*it)->GetBounds().Collides(Vector2F(state.X, state.Y)));
		if ((ComponentFlag::HookKeyboard & (*it)->GetFlags()) == ComponentFlag::HookKeyboard)
		{
			(*it)->OnKeyboard(ks, m_OldKeyState);
		}
		(*it)->Render(m_Renderer);
	}
	if (hit) Unfocus();
	m_OldKeyState = ks;
	m_OldState = state;
}
///Evaluates the gradient at the point pX, pY
Vector2F BaseExpression::gradient(F32 pX, F32 pY)
{
	BaseExpression* t = derivative(XVAR);
    return Vector2F(
                    derivative(XVAR)->evaluate(pX, pY), 
                    derivative(YVAR)->evaluate(pX, pY)
                    );
}
bool FieldController::Intersect(const RectangleF* m0, const RectangleF* m1, bool bDirection)
{
	Vector2F dir;

	if (bDirection && (m0->GetBottomRight().Y() > m1->GetTopLeft().Y()))
		return false;


	if (bDirection)
		dir = Vector2F(0, 1);
	else
		dir = Vector2F(1, 0);

	Vector2F min0, max0, min1, max1;
	GetProjection(m0, dir, min0, max0);
	GetProjection(m1, dir, min1, max1);

	//if (max0.X() > min1.X() || max0.Y() > min1.Y())
	//	return true;

	if (bDirection)
	{
		if ((max0.X() > min1.X() && max0.X() < max1.X()) ||
			(min0.X() > min1.X() && min0.X() < max1.X()) ||
			(max1.X() > min0.X() && max1.X() < max0.X()) ||
			(min1.X() > min0.X() && min1.X() < max0.X()) ||
			min0.X() == min1.X() || max0.X() == max1.X())
			return true;
	}
	else
	{
		if ((max0.Y() > min1.Y() && max0.Y() < max1.Y()) ||
			(min0.Y() > min1.Y() && min0.Y() < max1.Y()) ||
			(max1.Y() > min0.Y() && max1.Y() < max0.Y()) ||
			(min1.Y() > min0.Y() && min1.Y() < max0.Y()) ||
			min0.Y() == min1.Y() || max0.Y() == max1.Y())
			return true;
	}

	return false;
}
float FieldController::HoleSquad( const Segment& topSegment, const std::vector<Segment>& modelTopLine )
{
	double holeSquad = 0;
	for (int i = 0, i_end = modelTopLine.size(); i < i_end; ++i)
	{
		double a_length = modelTopLine[i].length();
		double b_length = Segment(modelTopLine[i].start(), Vector2F(modelTopLine[i].start().X(), topSegment.start().Y())).length();
		holeSquad += a_length * b_length;
	}

	return (float)holeSquad;
}
SpriteAnimator::SpriteAnimator(string file, int numberOfSprites, float fps)
{
	nSprites = numberOfSprites;
	loadSprites(file);

	Sprite* sprite = new Sprite();
	sprite->initWithTexture(sprites[0]);
	image = new CentSprite(sprite, 0, 0, 0, 0);

	internalTimer = CatacombTimer(1 / fps);

	initialPosition = Vector2F(0, 0);
}
Exemple #16
0
void Game1::Init()
{
	{
		world = new Physics::World(Vector2F(0, 9.8f));
		b2PolygonShape shape;
		shape.SetAsBox(40, 10);

		b2BodyDef groundBodyDef;
		groundBodyDef.position.Set(40, 50);
		groundBodyDef.type = b2_staticBody;
		ground = world->AddRigidBody(&groundBodyDef);
		ground->CreateFixture(&shape, 0.0f);
	}
}
Exemple #17
0
Rekd2D::Core::Vector2F Rekd2D::Core::Shader::GetVec2(const std::string &location)
{
    std::map<std::string, unsigned int>::iterator it = m_Locations.find(location);
    int uniform;
    if (it == m_Locations.end())
    {
        uniform = glGetUniformLocation(m_Program, location.c_str());
        m_Locations.insert(std::pair<std::string, unsigned int>(location, uniform));
    }
    else
    {
        uniform = m_Locations[location];
    }
    float out[2];
    glGetUniformfv(m_Program, uniform, out);
    return Vector2F(out[0], out[1]);
}
Vector2F GEORasterProjection::project(const Geodetic2D* position) const {
  const Vector2D uvCoordinates = _sector.getUVCoordinates(*position);

  double v;
  if (_mercator) {
    const double linearV = uvCoordinates._y;
    const Angle latitude = _sector.getInnerPointLatitude(linearV);
    const double mercatorGlobalV = MercatorUtils::getMercatorV(latitude);
    const double mercatorLocalV  = (mercatorGlobalV - _mercatorUpperGlobalV) / _mercatorDeltaGlobalV;
    v = mercatorLocalV;
  }
  else {
    v = uvCoordinates._y;
  }

  return Vector2F((float) (uvCoordinates._x * _imageWidth),
                  (float) (v * _imageHeight));
  
}
Exemple #19
0
	void Entity::update()
	{
		// Move entity
		if (positionproperty && speed != Vector2F(0, 0))
		{
			Vector2F position = positionproperty->getVector2F();
			MapPointer map = Server::get().getMap();
			float currentheight = map->getHeight(position);
			position += speed / 50;
			RectangleF area(position.x - 0.35, position.y - 0.35, 0.7, 0.7);
			float maxheight = map->getMaximumHeight(area);
			if (maxheight <= currentheight + 0.5)
			{
				positionproperty->setVector2F(position);
			}
		}
		// Call frame callback
		if (script->isFunction("on_update"))
			script->callFunction("on_update");
	}
Exemple #20
0
namespace engine {
	// Mathlib.hpp
	const float Math::Pi = 3.14159265f;
	const float Math::HalfPi = 1.570796325f;
	const float Math::Epsilon = std::numeric_limits<float>::epsilon();

	// Vector2.hpp
	template<> const Vector2I Vector2I::ZERO = Vector2I(0,0);
	template<> const Vector2F Vector2F::ZERO = Vector2F(0.f, 0.f);

	// Vector3.hpp
	template<> const Vector3I Vector3I::ZERO = Vector3I(0,0,0);
	template<> const Vector3F Vector3F::ZERO = Vector3F(0.f,0.f,0.f);

	template<> const Vector3F Vector3F::UNIT_Z = Vector3F(0.f,0.f,1.f);
	template<> const Vector3F Vector3F::UNIT_X = Vector3F(1.f,0.f,0.f);
	template<> const Vector3F Vector3F::UNIT_Y = Vector3F(0.f,1.f,0.f);
	template<> const Vector3F Vector3F::NEGUNIT_Z = Vector3F(0.f,0.f,-1.f);
	template<> const Vector3F Vector3F::NEGUNIT_X = Vector3F(-1.f,0.f,0.f);
	template<> const Vector3F Vector3F::NEGUNIT_Y = Vector3F(0.f,-1.f,0.f);

	// Matrix4.hpp
	const Matrix4 Matrix4::IDENTITY = Matrix4();

	void Matrix4::SetOrientation(const Quaternion &pQuat){
		Matrix4 tempMat = pQuat.ToMatrix();
		tempMat.SetTranslation(this->GetTranslation());
		*this = tempMat;
	}

	void Matrix4::Rotate(const Quaternion &pQuat){
		Quaternion oldOrient, newOrient;
		oldOrient.FromMatrix(*this);
		newOrient = oldOrient * pQuat;
		this->SetOrientation(newOrient);
	}
}
Exemple #21
0
	// :[
	void Entity::MakeSphere(const std::string &pMeshName, Shader &pShader, s32 pSlices){
		std::vector<Vector3F> vertices;
		std::vector<Vector2F> texcoords;
		std::vector<Vector3F> normals;
		std::vector<Index> indices;
		Vector3F v;

		f32 angleStep = 2.f * Math::Pi / (f32)pSlices;
		int midP = pSlices;

		for(int i = 0; i < pSlices; ++i)
			for(int j = 0; j < pSlices; ++j){
				v.x = Math::Sin(angleStep * (f32)i) * Math::Sin(angleStep * (f32)j);
				v.y = Math::Cos(angleStep * (f32)i);
				v.z = Math::Sin(angleStep * (f32)i) * Math::Cos(angleStep * (f32)j);

				vertices.push_back(v);
				normals.push_back(v);

				texcoords.push_back(Vector2F((f32)j / (f32)pSlices, (1.f - (f32)i) / (f32)(pSlices - 1)));
			}
			
		for(int i = 0; i < pSlices; ++i)
			for(int j = 0; j < pSlices; ++j){
				indices.push_back( i    * (pSlices + 1) +  j);
				indices.push_back((i+1) * (pSlices + 1) +  j);
				indices.push_back((i+1) * (pSlices + 1) + (j + 1));
				
				indices.push_back( i    * (pSlices + 1) +  j);
				indices.push_back((i+1) * (pSlices + 1) + (j + 1));
				indices.push_back( i    * (pSlices + 1) + (j + 1));
			}

		CreateVAO(pMeshName, pShader, &vertices[0], vertices.size() * sizeof(Vector3F), &indices[0], indices.size() * sizeof(Index));
		Make(&normals[0]);
	}
Exemple #22
0
	Vector2F Entity::getPosition()
	{
		if (positionproperty)
			return positionproperty->getVector2F();
		return Vector2F();
	}
Exemple #23
0
void CubesGame::LoadContent()
{
	Game::LoadContent();

	World *m_pWorld = NEW_AO World();
	GameInfo::Instance().SetWorld(m_pWorld);

	m_pProgram = Program::loadProgram("vs_mesh", "fs_mesh");

	//Camera 3D
	BaseEntity *pCamera = NEW_AO BaseEntity();
	Camera3DComponent *m_pCamera3D = NEW_AO Camera3DComponent(pCamera);
	ArcBallCameraController *pArcBall = NEW_AO ArcBallCameraController(m_pCamera3D);
	pArcBall->SetCamera(Vector3F(0, 20.0f, -50.0f), Vector3F::Zero(), Vector3F::Up());
	pArcBall->Distance(15.0f);
	m_pCamera3D->CameraController(pArcBall);
	pCamera->GetComponentMgr()->AddComponent(m_pCamera3D);	
	pCamera->Initialize();
	m_pWorld->AddEntity(pCamera);
	GameInfo::Instance().SetActiveCamera(m_pCamera3D);

	const float delta = 3.0f;

	//Box
	BaseEntity* pEntity = NEW_AO BaseEntity();
	pEntity->SetName("box");
	Transform3DComponent *pTransform = NEW_AO Transform3DComponent(pEntity);
	pTransform->SetLocalPosition(Vector3F(0.0f, 0.5f, delta));
	pTransform->SetLocalRotation(0.0f);
	pTransform->SetLocalScale(Vector3F::One());
	pEntity->GetComponentMgr()->AddComponent(pTransform);
	MeshComponent *pModelCpt = NEW_AO MeshComponent(pEntity);
	IPrimitive3D *pPrimitive = NEW_AO BoxPrimitive();
	Mesh *pModel = pPrimitive->CreateModel();
	//ResourceManager::Instance().Add("boxModel", pModel);
	//DELETE_AO pPrimitive;
	pModelCpt->SetModel(pModel);
	pModelCpt->SetProgram(m_pProgram);
	pEntity->GetComponentMgr()->AddComponent(pModelCpt);
	pEntity->Initialize();

	m_pWorld->AddEntity(pEntity);

	//Sphere
	pEntity = NEW_AO BaseEntity();
	pEntity->SetName("sphere");
	pTransform = NEW_AO Transform3DComponent(pEntity);
	pTransform->SetLocalPosition(Vector3F(delta, 0.5f, 0.0f));
	pTransform->SetLocalRotation(0.0f);
	pTransform->SetLocalScale(Vector3F::One());
	pEntity->GetComponentMgr()->AddComponent(pTransform);
	pModelCpt = NEW_AO MeshComponent(pEntity);
	pPrimitive = NEW_AO SpherePrimitive();
	pModel = pPrimitive->CreateModel();
	//ResourceManager::Instance().Add("sphereModel", pModel);
	pModelCpt->SetModel(pModel);
	pModelCpt->SetProgram(m_pProgram);
	//DELETE_AO pPrimitive;
	pEntity->GetComponentMgr()->AddComponent(pModelCpt);
	pEntity->Initialize();

	m_pWorld->AddEntity(pEntity);

	//Cylinder
	pEntity = NEW_AO BaseEntity();
	pEntity->SetName("cylinder");
	pTransform = NEW_AO Transform3DComponent(pEntity);
	pTransform->SetLocalPosition(Vector3F(-delta, 0.5f, 0.0f));
	pTransform->SetLocalRotation(0.0f);
	pTransform->SetLocalScale(Vector3F::One());
	pEntity->GetComponentMgr()->AddComponent(pTransform);
	pModelCpt = NEW_AO MeshComponent(pEntity);
	pPrimitive = NEW_AO CylinderPrimitive();
	pModel = pPrimitive->CreateModel();
	//ResourceManager::Instance().Add("cylinderModel", pModel);
	pModelCpt->SetModel(pModel);
	pModelCpt->SetProgram(m_pProgram);
	//DELETE_AO pPrimitive;
	pEntity->GetComponentMgr()->AddComponent(pModelCpt);
	pEntity->Initialize();

	m_pWorld->AddEntity(pEntity);

	//ground
	pEntity = NEW_AO BaseEntity();
	pEntity->SetName("ground");
	pTransform = NEW_AO Transform3DComponent(pEntity);
	pTransform->SetLocalPosition(Vector3F(0.0f, 0.0f, 0.0f));
	pTransform->SetLocalRotation(0.0f);
	pTransform->SetLocalScale(Vector3F::One());
	pEntity->GetComponentMgr()->AddComponent(pTransform);
	pModelCpt = NEW_AO MeshComponent(pEntity);
	pPrimitive = NEW_AO PlanePrimitive(100.0f, 100.0f);
	pModel = pPrimitive->CreateModel();
	//ResourceManager::Instance().Add("groundModel", pModel);
	//DELETE_AO pPrimitive;
	//new material
	Material* pMat = pModel->GetMaterial()->Clone();
	//ResourceManager::Instance().Add("groundMaterial", pMat);
	pModel->SetMaterial(pMat);
	pMat->Texture0(Texture::loadTexture("ceilingMain_DIF.dds", BGFX_TEXTURE_MIN_ANISOTROPIC | BGFX_TEXTURE_MAG_ANISOTROPIC));
	pMat->Texture0Repeat(Vector2F(50, 50));
	//
	pModelCpt->SetModel(pModel);
	pModelCpt->SetProgram(m_pProgram);
	pEntity->GetComponentMgr()->AddComponent(pModelCpt);
	pEntity->Initialize();

	m_pWorld->AddEntity(pEntity);
}
Exemple #24
0
	inline Vector2F SFMLToRedVector2F(const sf::Vector2<T> &pVec){
		return Vector2F(static_cast<f32>(pVec.x), static_cast<f32>(pVec.y));
	}
Exemple #25
0
inline Vector2F Vector2F::operator* (float const scalar) const
{
	return Vector2F(m_components[0] * scalar, m_components[1] * scalar);
}
Exemple #26
0
inline Vector2F Vector2F::operator- (Vector2F const& other) const
{
	return Vector2F(m_components[0] - other.m_components[0], m_components[1] - other.m_components[1]);
}
Exemple #27
0
	void Entity::MakeCube(const std::string &pMeshName, Shader &pShader){
		Vector3F position[] = { Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,-1.f,1.f), Vector3F(1.f,-1.f,1.f), Vector3F(1.f,-1.f,-1.f),
								Vector3F(-1.f,1.f,-1.f), Vector3F(-1.f,1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,1.f,-1.f), 
								Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,1.f,-1.f), Vector3F(1.f,1.f,-1.f), Vector3F(1.f,-1.f,-1.f),
								Vector3F(-1.f,-1.f,1.f), Vector3F(-1.f,1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,-1.f,1.f), 
								Vector3F(-1.f,-1.f,-1.f), Vector3F(-1.f,-1.f,1.f), Vector3F(-1.f,1.f,1.f), Vector3F(-1.f,1.f,-1.f), 
								Vector3F(1.f,-1.f,-1.f), Vector3F(1.f,-1.f,1.f), Vector3F(1.f,1.f,1.f), Vector3F(1.f,1.f,-1.f)
							  };

		Index indices[] =	  { 0, 2, 1, 0, 3, 2, 
								4, 5, 6, 4, 6, 7,
								8, 9, 10, 8, 10, 11, 
								12, 15, 14, 12, 14, 13, 
								16, 17, 18, 16, 18, 19, 
								20, 23, 22, 20, 22, 21
							  };

		Vector2F texcoords[] = {Vector2F(1.f, 1.f), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
								Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
								Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
								Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
								Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f),
								Vector2F(1.f, 1.F), Vector2F(1.f, 0.f), Vector2F(0.f, 0.f), Vector2F(0.f, 1.f)
		};

		Vector3F normals[] = {	Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y, Vector3F::NEGUNIT_Y,
								Vector3F::UNIT_Y, Vector3F::UNIT_Y, Vector3F::UNIT_Y, Vector3F::UNIT_Y, 
								Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z, Vector3F::NEGUNIT_Z,
								Vector3F::UNIT_Z, Vector3F::UNIT_Z, Vector3F::UNIT_Z, Vector3F::UNIT_Z, 
								Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X, Vector3F::NEGUNIT_X,
								Vector3F::UNIT_X, Vector3F::UNIT_X, Vector3F::UNIT_X, Vector3F::UNIT_X 
							 };

		
		CreateVAO(pMeshName, pShader, position, sizeof(position), indices, sizeof(indices));

		switch(mType){
		case ET_MESH:
			Make(normals,texcoords);break;
		case ET_OBJECT:
			Make(normals);break;
		case ET_DEBUGOBJECT:
			Make(texcoords);break;
		}
	}
Exemple #28
0
  static Vector2F nan() {
    const IMathUtils* mu = IMathUtils::instance();

    return Vector2F(mu->NanF(),
                    mu->NanF());
  }
Vector2F InverseBilinearInterpolate::solve(Vector2F M1, Vector2F M2, Vector2F b, bool safeInvert)
{
	float det = M1.cross(M2);
	if(safeInvert || det != 0.f) det = 1.f/det;
	return Vector2F(b.cross(M2), -b.cross(M1)) * det;
}
Exemple #30
0
TEST(Matrix3x3, Transform)
{
    Matrix3x3 position;
    position.transform(Vector2F(2.0f, 3.0f),
                       Vector2F(1.0f, 1.0f),
                       0.0,
                       Vector2F());
    Matrix3x3 exPosition(1.0f, 0.0f, 2.0f,
                         0.0f, 1.0f, 3.0f,
                         0.0f, 0.0f, 1.0f);
    EXPECT_EQ(exPosition, position);

    Matrix3x3 pivot;
    pivot.transform(Vector2F(),
                    Vector2F(1.0f, 1.0f),
                    0.0,
                    Vector2F(2.0f, 3.0f));
    EXPECT_EQ(exPosition, pivot);

    Matrix3x3 rotation;
    rotation.transform(Vector2F(),
                       Vector2F(1.0f, 1.0f),
                       180.0,
                       Vector2F());
    Matrix3x3 exRotation(-1.0f, 0.0f, 0.0f,
                         0.0f, -1.0f, 0.0f,
                         0.0f,  0.0f, 1.0f);
    EXPECT_EQ(exRotation, rotation);

    Matrix3x3 scale;
    scale.transform(Vector2F(),
                    Vector2F(2.0f, 3.0f),
                    0.0,
                    Vector2F());
    Matrix3x3 exScale(2.0f, 0.0f, 0.0f,
                      0.0f, 3.0f, 0.0f,
                      0.0f, 0.0f, 1.0f);
    EXPECT_EQ(exScale, scale);

    // NOTE: Matrix equality checks if the values are close. Because this
    // uses trig the rotation values do not line up to 0.0.
    Matrix3x3 all;
    all.transform(Vector2F(5.0f, 6.0f),
                  Vector2F(2.0f, 3.0f),
                  180.0,
                  Vector2F(10.0f, 20.0f));
    Matrix3x3 exAll(-2.0f, 0.0f,  -15.0f,
                    0.0f,  -3.0f, -54.0f,
                    0.0f,  0.0f,  1.0f);
    EXPECT_EQ(exAll, all);
}