Esempio n. 1
0
void CClientModule::init( IModuleManager* modulemanager ) {
    //graphics->setCursorVisible(false);
    test = graphics->loadFont("DroidSans.ttf", 12);
    
    /*IEntity* entD = entitymanager->createEntity("base_entity");
    entD->spawn();
    entD->setOrigin(Vector2Df(0,0));
    entD->setZIndex(-2);*/
    
    p = new Panel();
    p->setOrigin( Vector2Df(5, 5) );
    p->setWidth( 100 );
    p->setHeight( 100 );
    
    Panel *z = new Panel();
    z->setParent( p );
    z->setOrigin(Vector2Df(60, 10));
    z->setWidth( 50 );
    z->setHeight( 50 );
    
    Panel *a = new Panel();
    a->setParent( p );
    a->setOrigin(Vector2Df(3, 3));
    a->setWidth( 10 );
    a->setHeight( 10 );
}
// constructor and default values
InteractiveCamera::InteractiveCamera()
{
	centerPosition = Vector3Df(0, 0, 0);
	yaw = 0;
	pitch = 0.3;
	radius = 4;
	apertureRadius = 0.01; // 0.04
	focalDistance = 4.0f;

	resolution = Vector2Df(512, 512);  // width, height
	fov = Vector2Df(40, 40);
}
void InteractiveCamera::buildRenderCamera(Camera* renderCamera){
	float xDirection = sin(yaw) * cos(pitch);
	float yDirection = sin(pitch);
	float zDirection = cos(yaw) * cos(pitch);
	Vector3Df directionToCamera = Vector3Df(xDirection, yDirection, zDirection);
	viewDirection = directionToCamera * (-1.0);
	Vector3Df eyePosition = centerPosition + directionToCamera * radius;
	//Vector3Df eyePosition = centerPosition; // rotate camera from stationary viewpoint

	renderCamera->position = eyePosition;
	renderCamera->view = viewDirection;
	renderCamera->up = Vector3Df(0, 1, 0);
	renderCamera->resolution = Vector2Df(resolution.x, resolution.y);
	renderCamera->fov = Vector2Df(fov.x, fov.y);
	renderCamera->apertureRadius = apertureRadius;
	renderCamera->focalDistance = focalDistance;
}
Esempio n. 4
0
File: math.cpp Progetto: qwook/spine
Vector2Df Vector2Df::getRotated( float angle ) {
    float rad = degtorad(angle);
    
    float c = cos(rad);
    float s = sin(rad);
    
    return Vector2Df( x*c - y*s, x*s + y*c );
}
	void CollisionSystem::AddActorToBuckets(Actor* actor)
	{
		Vector2Df pos = actor->Get2DPos();
		float radius = actor->GetRadius();

		if(radius >= BUCKET_SIZE)
		{
			ComplexAddTobuckets(actor);
			return;
		}

		const int maxBucketSize = m_numBucketsHeight * m_numBucketsWidth; 

		int center = GetPositionBucketID(pos);
		int a = GetPositionBucketID(Vector2Df(pos.x_ - radius + 312.5f, pos.y_ - radius + 312.5f));
		int b = GetPositionBucketID(Vector2Df(pos.x_ + radius + 312.5f, pos.y_ - radius + 312.5f));
		int c = GetPositionBucketID(Vector2Df(pos.x_ + radius + 312.5f, pos.y_ + radius + 312.5f));
		int d = GetPositionBucketID(Vector2Df(pos.x_ - radius + 312.5f, pos.y_ + radius + 312.5f));

		if (center > -1 && center < maxBucketSize)
		{
			m_buckets[center].push_back(actor);
		}

		if(a > -1 && a < maxBucketSize && a != center)
		{
			m_buckets[a].push_back(actor);
		}

		if(b > -1 && b != a && b < maxBucketSize && b != center)
		{
			m_buckets[b].push_back(actor);
		}

		if(c > -1 && c != a && c != b && c < maxBucketSize && c != center)
		{
			m_buckets[c].push_back(actor);
		}

		if(d > -1 && d != b && d != c && d < maxBucketSize && d  != center)
		{
			m_buckets[d].push_back(actor);
		}
	}
Esempio n. 6
0
void CClientModule::render() {
    entitymanager->render();
    
    graphics->useProgram("default");
    graphics->setColor(0, 0, 0, 255);
    graphics->drawText(test, "hello! 10 bitches suck dick </>", Vector2Df(0,150));
    graphics->drawQuad(0,200,128, 128);
    
    p->recursiveDraw();
}
	void DrawFilledCircle(const Vector2Df& pos, float spaceing, float radius)
	{
		float radSpacing = DegreesToRadians(spaceing);

		std::vector<Vector2Df> verts;
		verts.push_back(pos);

		for(float i = 0; i <= 2 * 3.1415f; i += radSpacing)
		{
			verts.push_back(Vector2Df(pos.x + cos(i) * radius,				pos.y + sin(i) * radius));
			verts.push_back(Vector2Df(pos.x + cos(i + radSpacing) * radius,	pos.y + sin(i + radSpacing) * radius));
		}

		//g_currentShader->SetModelViewProjection();
		//g_currentShader->SetUniform("color", 4, &g_CurrentColor[0]);
		//g_currentShader->UseProgram();

		static int vl = 0;////g_currentShader->GetAttributeLocation("vertex");

		glEnableVertexAttribArray(vl);
		glVertexAttribPointer(vl, 2, GL_FLOAT, GL_FALSE, 0, verts.data());
		glDrawArrays(GL_TRIANGLE_FAN, 0, verts.size());
		glDisableVertexAttribArray(vl);
	}
Esempio n. 8
0
	void Lights::AddLight(const Vector3Df& pos, const Vector3Df& color)
	{
		if(m_numLights >= MAX_NUM_LIGHTS)
			return;

		m_pos.push_back(pos);
		m_color.push_back(color);
		m_radius.push_back(1.0f);
		m_dir.push_back(Vector3Df());
		m_angleInnerCone.push_back(0.0f);
		m_angleOuterCone.push_back(-1.0f);
		m_startAndEndAtten.push_back(Vector2Df(1.0f, 1.0f));

		++m_numLights;
	}
Esempio n. 9
0
void CChildView::OnRButtonUp(UINT nFlags, CPoint point)
{
	switch (_LMBState)
	{
	case ELMBState::AddCircleObstacle:
	case ELMBState::AddOBBObstacle:
		RemoveObstacle(point);
		break;
	case ELMBState::IntersectSegment:
		{
			_intersectsegment.ChangeDestination(Vector2Df(point));
			CheckIntersect();
			Invalidate();
			break;
		}
	}

	__super::OnRButtonUp(nFlags, point);
}
	void CollisionSystem::ComplexAddTobuckets(Actor* actor)
	{
		Vector2Df pos = (actor->Get2DPos() + Vector2Df(312.5f, 312.5f)) / BUCKET_SIZE;
		float radius = actor->GetRadius() / BUCKET_SIZE;

		Vector2Df start(pos.x_ - radius, pos.y_ - radius);
		Vector2Df end(pos.x_ + radius, pos.y_ + radius);

		const int maxBucketSize = m_numBucketsHeight * m_numBucketsWidth; 

		for(int i = start.x_; i < end.x_; ++i)
		{
			for(int j = start.y_; j < end.y_; ++j)
			{
				int bucket = GetBucketIndex(i, j);
				m_buckets[bucket].push_back(actor);
			}
		}
	}
Esempio n. 11
0
const GuiEvent& GUI::update() {
	// Update events

	static GuiEvent currentEvent;
	static SDL_Event event;

	currentEvent.click = false;

	if(currentEvent.buttonState == BTN_PRESSED)
		currentEvent.buttonState = BTN_HOLD;
	else if(currentEvent.buttonState == BTN_RELEASED)
		currentEvent.buttonState = BTN_NONE;
	
	if(SDL_PollEvent(&event)){
		if(event.type == SDL_QUIT)
			currentEvent.quitEvent = true;
		else if(event.type == SDL_MOUSEBUTTONDOWN) {
			currentEvent.buttonState = BTN_PRESSED;
			currentEvent.clickStart = converter.deconvert(Vector2df(event.button.x, event.button.y));
		} else if(event.type == SDL_MOUSEBUTTONUP) {
			currentEvent.buttonState = BTN_RELEASED;
			currentEvent.click = true;
			currentEvent.clickEnd = converter.deconvert(Vector2df(event.button.x, event.button.y));
			//cout << Vector2df(event.button.x, event.button.y) << '\t' << convert(currentEvent.clickEnd) << endl;
			//cout << currentEvent.clickEnd << endl;
		}
	}

	// Draw force vector
	/*if(currentEvent.buttonState == BTN_HOLD)
		lineRGBA(display, convert(currentEvent.clickStart).x(), convert(currentEvent.clickStart).y(), event.button.x, event.button.y,
				255, 255, 255, 255);*/
	if(currentEvent.buttonState == BTN_HOLD)
		forceMeter.drawForceVector(display, converter.convert(currentEvent.clickStart) , Vector2Df(event.button.x , event.button.y));


	// Flip the screen
	SDL_Flip(display);

	return currentEvent;
}
Esempio n. 12
0
Vector2Df CGraphicsModule::getCursorPos() {
    int x, y;
    glfwGetMousePos(&x, &y);
    return Vector2Df((float)x, (float)y);
}
void InitPhysics()
{

  LOGI("InitPhysics() called\n");
	m_world = new b2World(b2Vec2(0.0f, -9.81f), true);

  //  float *boxGeometry = new float[8];
  //  boxGeometry[0] = 1.0f; boxGeometry[1] = 0.0f; boxGeometry[2] = 1.0f;
  //  boxGeometry[3] = 1.0f;
  //  boxGeometry[4] = 0.0f; boxGeometry[5] = 1.0f; boxGeometry[6] = 0.0f;
  //  boxGeometry[7] = 0.0f;


  // ground
  {
    b2BodyDef groundBodyDef;
    groundBodyDef.position = b2Vec2(0.0, 1.0f);

    Sprite* sprite = new Sprite();
    sprite->vertex.push_back(Vector2Df(50.0f, 0.0f));
    sprite->vertex.push_back(Vector2Df(50.0f, 1.0f));
    sprite->vertex.push_back(Vector2Df(-50.0f, 1.0f));
    sprite->vertex.push_back(Vector2Df(-50.0f, 0.0f));

    sprite->texture_coords.push_back(Vector2Df(1.0f, 0.0f));
    sprite->texture_coords.push_back(Vector2Df(1.0f, 1.0f));
    sprite->texture_coords.push_back(Vector2Df(0.0f, 1.0f));
    sprite->texture_coords.push_back(Vector2Df(0.0f, 0.0f));

    groundBodyDef.userData = sprite;

    b2Body* ground = m_world->CreateBody(&groundBodyDef);

    //ground geometry
    b2PolygonShape shape;
    shape.SetAsBox(50.0f, 1.0f);
    //shape.SetAsEdge(b2Vec2(-12.0f, -7.0f), b2Vec2(12.0f, -7.0f));
    ground->CreateFixture(&shape, 0.0f);

  }

  // box
  {

    b2Vec2 vertices[] = { b2Vec2(2.0f, 0.0f), b2Vec2(2.0f, 2.0f),
      b2Vec2(0.0f, 2.0f), b2Vec2(0.0f, 0.0f) };
    b2PolygonShape shape;
    shape.Set(vertices, 4);

    b2BodyDef bd;
    bd.type = b2_dynamicBody;
    bd.userData = NULL;

    for (int i = 0; i < 5; i++)
    {

      Sprite* sprite = new Sprite();
      sprite->vertex.push_back(Vector2Df(2.0f, 0.0f));
      sprite->vertex.push_back(Vector2Df(2.0f, 2.0f));
      sprite->vertex.push_back(Vector2Df(0.0f, 2.0f));
      sprite->vertex.push_back(Vector2Df(0.0f, 0.0f));

      sprite->texture_coords.push_back(Vector2Df(1.0f, 0.0f));
      sprite->texture_coords.push_back(Vector2Df(1.0f, 1.0f));
      sprite->texture_coords.push_back(Vector2Df(0.0f, 1.0f));
      sprite->texture_coords.push_back(Vector2Df(0.0f, 0.0f));

      // Save our custom sprite in Box2D body definition
      bd.userData = sprite;


      bd.position = b2Vec2(1.0f * i, 20.0f+ .2f*i);
      //bd.position = b2Vec2(-5.0f + i * 2, 30.0f);
      //bd.position.Set(5.0f + 4 * 0.5f, 4.0f + 3*4);
      //bd.position = b2Vec2(5.0f + i * 0.5f, 4.0f + 3*i);
      //bd.position = b2Vec2(5.0f + i * 0.5f, 4.0f + 3*i);
      bd.angle = M_PI / (float)(i + 1);
      b2Body *box = m_world->CreateBody(&bd);
      box->CreateFixture(&shape, 1.0f);

    }

  }

}
void InteractiveCamera::setResolution(float x, float y){
	resolution = Vector2Df(x, y);
	setFOVX(fov.x);
}
Esempio n. 15
0
File: math.cpp Progetto: qwook/spine
Vector2Df Vector2Df::operator-(Vector2Df rhs) {
    return Vector2Df( x - rhs.x, y - rhs.y );
}
Esempio n. 16
0
File: math.cpp Progetto: qwook/spine
Vector2Df Vector2Df::operator+(Vector2Df rhs) {
    return Vector2Df( x + rhs.x, y + rhs.y );
}
Esempio n. 17
0
File: math.cpp Progetto: qwook/spine
Vector2Df Vector2Df::operator*(float scalar) {
    return Vector2Df( x * scalar, y * scalar );
}
Esempio n. 18
0
File: math.cpp Progetto: qwook/spine
Vector2Df Vector2Df::operator/(float scalar) {
    return Vector2Df( x / scalar, y / scalar );
}