Polygon::Polygon(vec2* aVertices, unsigned int aCount) : GameObject("Polygon"),
     m_Shader(nullptr),
     m_AnchorPoint(0.0f, 0.0f),
     m_AnchorLocation(0.0f, 0.0f),
     m_Color(Color::BlueColor()),
     m_RenderMode(GL_TRIANGLE_FAN),
     m_IsFilled(true),
     m_PointSize(1.0f),
     m_TweenAnchorX(),
     m_TweenAnchorY(),
     m_TweenAlpha(),
     m_VertexArrayObject(0),
     m_VertexBufferObject(0)
 {
     //Set the shader as the default passthrough shader
     SetShader(ServiceLocator::GetShaderManager()->GetPassthroughShader());
     
     //Set the vertices
     SetVertices(aVertices, aCount);
     
     //Intialize the position and angle
     SetLocalPosition(vec2(0.0f, 0.0f));
     SetLocalAngle(0.0f);
     
     //Set the model matrix to dirty
     ModelMatrixIsDirty(true);
 }
void GuiElement::Center(bool x, bool y)
{
	if (x || y)
	{
		int fw, fh;
		if (parent)
		{
			fw = parent->GetLocalRect().w;
			fh = parent->GetLocalRect().h;
		}
		else
		{
			fw = App->render->camera.w;
			fh = App->render->camera.h;
		}
		int w, h;
		SDL_Rect rect = GetLocalRect();
		if (x)
			w = fw / 2 - rect.w / 2;
		else
			w = rect.x;

		if (y)
			h = fh / 2 - rect.h / 2;
		else
			h = rect.y;

		SetLocalPosition({ w, h });
	}
}
//Moves accordingly to the mouse
void GuiItem::Move()
{ 
	iPoint tmp = App->input->GetMousePosition();
	tmp.x -= GetLocalRect().w / 2;
	tmp.y -= GetLocalRect().h / 2;

	SetLocalPosition(tmp);
}
Beispiel #4
0
//Moves accordingly to the mouse
void GuiItem::Move()
{ 
	//TODO 4: Fill Move() function so, the item movement is exactly like the cursor (hint: not using the draggable property or mouse motion)
	//and also make that the item is centered at the cursor (is at the middle not at the vertex)
	iPoint tmp = App->input->GetMousePosition();
	tmp.x -= GetLocalRect().w / 2;
	tmp.y -= GetLocalRect().h / 2;

	SetLocalPosition(tmp);
}
Beispiel #5
0
//-----------------------------------------------------------------------------------------------------------------------------------
void GameMouse::Update(float elapsedSeconds)
{
	UIObject::Update(elapsedSeconds);

	// Update mouse states
	m_currentMouseState = m_mouse->GetState();
	m_mouseButtonState->Update(m_currentMouseState);

	// Update mouse position
	SetLocalPosition(Vector2((float)m_currentMouseState.x, (float)m_currentMouseState.y));
}
 Tile::Tile(const string& aTileName, SubSection* aSubSection, uvec2 aCoordinates) : GameObject(aTileName),
     m_SubSection(aSubSection),
     m_Pickup(nullptr),
     m_IsWalkable(false),
     m_IsDestination(false),
     m_IsHeroSpawnPoint(false),
     m_IsEnemySpawnPoint(false),
     m_Variant(0)
 {
     //Set the local position based on the coordinates that were passed in
     SetLocalPosition((float)(aCoordinates.x * GetSize()), (float)(aCoordinates.y * GetSize()));
 }
	//
	// 设置世界位置
	//
	VOID CSceneNode::SetWorldPosition(FLOAT x, FLOAT y, FLOAT z)
	{
		if (m_pParentNode) {
			// 算法:
			// worldPosition = localPosition * parentMatrix;
			// localPosition = worldPosition * parentMatrixInv;

			MATRIX4 mtxParentInv;
			MtxInverse(&mtxParentInv, m_pParentNode->GetWorldMatrix());

			VEC3 localPosition;
			VEC3 worldPosition;
			Vec3Set(&worldPosition, x, y, z);
			Vec3MulMtx4x4(&localPosition, &worldPosition, &mtxParentInv);

			x = localPosition[0];
			y = localPosition[1];
			z = localPosition[2];
		}

		SetLocalPosition(x, y, z);
	}
 Polygon::Polygon(vec2* aVertices, unsigned int aCount, Shader* aShader) : GameObject("Polygon"),
     m_Shader(aShader),
     m_AnchorPoint(0.0f, 0.0f),
     m_AnchorLocation(0.0f, 0.0f),
     m_Color(Color::BlackColor()),
     m_RenderMode(GL_TRIANGLE_FAN),
     m_IsFilled(true),
     m_PointSize(1.0f),
     m_TweenAnchorX(),
     m_TweenAnchorY(),
     m_TweenAlpha(),
     m_VertexArrayObject(0),
     m_VertexBufferObject(0)
 {
     //Set the vertices
     SetVertices(aVertices, aCount);
 
     //Intialize the position and angle
     SetLocalPosition(vec2(0.0f, 0.0f));
     SetLocalAngle(0.0f);
     
     //Set the model matrix to dirty
     ModelMatrixIsDirty();
 }
 Polygon::Polygon(const string& aType) : GameObject(aType == "" ? "Polygon" : aType),
     m_Shader(nullptr),
     m_AnchorPoint(0.0f, 0.0f),
     m_AnchorLocation(0.0f, 0.0f),
     m_Color(Color::BlueColor()),
     m_RenderMode(GL_TRIANGLE_FAN),
     m_IsFilled(true),
     m_PointSize(1.0f),
     m_TweenAnchorX(),
     m_TweenAnchorY(),
     m_TweenAlpha(),
     m_VertexArrayObject(0),
     m_VertexBufferObject(0)
 {
     //Set the shader as the default passthrough shader
     SetShader(ServiceLocator::GetShaderManager()->GetPassthroughShader());
     
     //Intialize the position and angle
     SetLocalPosition(0.0f, 0.0f);
     SetLocalAngle(0.0f);
     
     //Set the model matrix to dirty
     ModelMatrixIsDirty();
 }
Beispiel #10
0
UILabel::UILabel(char* newName, iPoint newPosition, char* newText)
{
	name = newName;
	SetLocalPosition(newPosition.x, newPosition.y);
	text = newText;
}
Beispiel #11
0
	//--------------------------------------------------------------------------------------------------------------------------------------
	Emitter::Emitter(const vector3f& pos,
		const vector3f& posNoise,
		const vector3f& dir,
		const vector3f& acce,
		const vector2f& speedPmill,
		float endspeed,
		const vector3f& angle,
		const Color& begin1,
		const Color& begin2,
		const Color& end1,
		const Color& end2,
		const vector2f& clrpow,
		const vector2d& life,
		const vector2f& alphaPow,
		const vector2f& sizebegin,
		const vector2f& sizeend,
		const vector2f& sizepow,
		const vector2d& countSec,
		const int emitterlife,
		std::string texName)
		:ISceneNode( ISceneNode::RS_TRANSPARENT ),
		LocatableObject( this ),
		m_PositionNoise(posNoise),
		m_Speed(speedPmill),
		m_Direction(dir),
		m_Acceleration(acce),
		m_Angle(angle),
		m_BeginColorA(begin1),
		m_BeginColorB(begin2),
		m_EndColorA(end1),
		m_EndColorB(end2),
		m_LifeSpan(life),
		m_BeginSize(sizebegin),
		m_EndSize(sizeend),
		m_CountSec(countSec),
		m_uTimeSpan(0),
		m_uLifedTime(0),
		m_ActiveTime(0),
		m_EmitterLife(emitterlife),
		m_isEmit(true),
		m_isForceStop(false),
		m_isInview(false),
		m_ColorPow(clrpow),
		m_AlphaPow(alphaPow),
		m_SizePow(sizepow),
		m_EndSpeed(endspeed),
		m_fResistance(((endspeed / speedPmill.m_y) - 1.0f )/static_cast<float>(life.m_y))
	{
		SetLocalPosition( pos );
		m_Direction.NormalizeSelf();
		float maxlife = Math::GetMax(life.m_x, life.m_y);
		float maxcount = Math::GetMax(countSec.m_x, countSec.m_y);
		//int maxParticle = static_cast<int>( ( ceil(TO_SEC( maxlife )) ) * maxcount );
		int maxParticle = 0;
		if ( -1 != emitterlife )
		{
			maxParticle = static_cast<int>(  ( TO_SEC( emitterlife ) ) * ( TO_SEC( maxlife ) ) * maxcount );
		}
		else
		{
			maxParticle = static_cast<int>( ( TO_SEC( maxlife ) ) * maxcount );
		}
		m_ArraySize = maxParticle;
		m_Index.SetMax(maxParticle);
		m_pParticle = NEW Particle_ColorSizeForce[maxParticle+1];//此处分配的时候一定要多分配一个,防止glEnableVertexAttribArray越界访问,造成堆栈损坏
		m_pRendBuffer = NEW RendBuffer( Device::RM_POINTS );
		m_pVertexBuffer = NEW VertexBuffer( Device::MU_DYNAMIC );
		m_pRendBuffer->SetVertexBuffer( m_pVertexBuffer );
		m_pVertexBuffer->FlushVertexBuffer( m_ArraySize, &m_pParticle[0] );

		//ushort* indies = NEW ushort[maxParticle];
		//for ( int i = 0;i < maxParticle ; i ++ )
		//{
		//	indies[i] = i;
		//}
		//m_pRendBuffer->MakeIndiesBuffer(indies, maxParticle, Device::MU_STATIC);
		//SAFE_DELETE_ARRAY(indies);
		//m_Tex = NEW Texture2D();
		//m_Tex->LoadTexture( Device::PF_A8, texName);
		m_isBeginChangeColor = m_BeginColorA == m_BeginColorB ? false : true;
		m_isEndChangeColor = m_EndColorA == m_EndColorB ? false : true;

		//材质
		m_pMaterial = NEW Material;
		m_pMaterial->SetNode( this );
		m_pMaterial->SetShader( Pipeline::PT_LIGHTING, ShaderManage::ParticleShader );
		m_pMaterial->LoadTexture( Material::ATT_TEX_DIFFUSE, Device::PF_R8G8B8A8, texName );
		m_pMaterial->GetDrawState( Pipeline::PT_LIGHTING ).m_isDepthMask = false;
		m_pMaterial->GetAlpahState( Pipeline::PT_LIGHTING ).m_isAlphaEnable = true;

		//计算绑定盒子
		//由于喷射角度关系,绑定盒子很难精确计算,将采用随机测试的方法在编辑器中输出

	}
Beispiel #12
0
	//--------------------------------------------------------------------------------------------------------------------------------------
	void Emitter::Move(const vector3f& dir)
	{
		SetLocalPosition( GetLocalPosition() + dir );
		m_BindBox.SetCenter( GetLocalPosition() );
	}
void UIElement::SetCollider(int x, int y, int w, int h)
{
	SetLocalPosition(x, y);
	collider.w = w;	 collider.h = h;
}
bool GuiElement::CheckEvent(GuiElement* hover, GuiElement* focus)
{
	bool inside = (hover == this);
	bool focused = (focus == this);
	

		if (inside != mouseIn)
		{
			if (listener)
			{
				if (inside)
					listener->OnEvent(this, EVENT_MOUSE_ENTER);
				else
					listener->OnEvent(this, EVENT_MOUSE_EXIT);
			}
			mouseIn = inside;
		}
		
		if (inside)
		{
			if (listener)
			{
				if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN)
					listener->OnEvent(this, EVENT_MOUSE_LEFTCLICK_DOWN);
				if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_UP)
					listener->OnEvent(this, EVENT_MOUSE_LEFTCLICK_UP);
				if (App->input->GetMouseButtonDown(SDL_BUTTON_RIGHT) == KEY_DOWN)
					listener->OnEvent(this, EVENT_MOUSE_RIGHTCLICK_DOWN);
				if (App->input->GetMouseButtonDown(SDL_BUTTON_RIGHT) == KEY_UP)
					listener->OnEvent(this, EVENT_MOUSE_RIGHTCLICK_UP);
			}

			if (draggable && App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_REPEAT)
			{
				iPoint p = GetLocalPosition();
				iPoint m = App->input->GetMouseMotion();
				SetLocalPosition(p + m);
			}
		}

		if (focusIn != focused)
		{
			if (listener)
			{
				if (focused)
					listener->OnEvent(this, EVENT_FOCUS_DOWN);
				else
					listener->OnEvent(this, EVENT_FOCUS_UP);
			}
			focusIn = focused;
		}

		if (focused)
		{
			if (listener)
			{
				if(App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN)
					listener->OnEvent(this, EVENT_MOUSE_LEFTCLICK_DOWN);
				if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_UP)
					listener->OnEvent(this, EVENT_MOUSE_LEFTCLICK_UP);
			}
		}
	
	return true;
}
Beispiel #15
0
 Point::Point() : Polygon("Point")
 {
     SetLocalPosition(vec2(0.0f, 0.0f));
     ResetPolygonData();
 }
Beispiel #16
0
void CGuiWidget::ReapplyXform()
{
    RotateReset();
    SetLocalPosition(zeus::CVector3f::skZero);
    MultiplyO2P(x80_transform);
}
Beispiel #17
0
	//-----------------------------------------------------------------------
	Transform::Ptr Transform::SetLocalPosition(float x, float y, float z)
	{
		Vector3 v(x, y, z);
		SetLocalPosition(v);
		return ThisPtr();
	}
Beispiel #18
0
 Point::Point(float aX, float aY) : Polygon("Point")
 {
     SetLocalPosition(vec2(aX, aY));
     ResetPolygonData();
 }
Beispiel #19
0
 Point::Point(vec2 aPosition) : Polygon("Point")
 {
     SetLocalPosition(aPosition);
     ResetPolygonData();
 }