void AnimController::setBonePose( PyramidObject *node )
{
	PyramidObject *childNode = (PyramidObject *)node;
	PyramidObject *parentNode = (PyramidObject *)node->getParent();

	if( parentNode == GraphicsObjMan::getMainTree()->getRoot() )
		return;

	if (parentNode != 0 && childNode != 0)	{
		// Now get the world matrices
		Vect start(0.0f,0.0f,0.0f);

		parentNode->transform();
		Vect ptA = start * parentNode->getWorld();

		childNode->transform();
		Vect ptB = start * childNode->getWorld();

		// direction between the anchor points of the respective bones
		Vect dir = -(ptB - ptA);

		// length of the bone 0
		float mag = dir.mag();

		// Set the orientation and length for bone 0
		Matrix S( SCALE, BONE_WIDTH, BONE_WIDTH, mag);
		Quat Q( ROT_ORIENT, dir.getNorm(), Vect( 0.0f, 1.0f, 0.0f) );
		Matrix T( TRANS, ptB );

		Matrix BoneOrient = S * Q * T;

		childNode->setBoneOrientation( BoneOrient );
	}
}
예제 #2
0
const float Vect::getAngle(const Vect &t)const
{
	// T = theta
	// cosT = (a.dot(b)/a.mag()*b.mag())
	// T = acosf(a.dot(b)/a.mag()*b.mag());

	return (acosf((this->dot(t)/(this->mag() * t.mag()))));
};
예제 #3
0
void Teddy::setBonePose(GameObject *node)
{

	MyGameObjectAnim *childNode = (MyGameObjectAnim *)node;
	
	///GameObject *parentNode = (GameObject *)node->getParent();
	MyGameObjectAnim *parentNode;
	if( node->getParent()->getParent()->getParent() != 0)
	parentNode = (MyGameObjectAnim *)node->getParent();
	else
	parentNode = 0;

	
	if( parentNode == root )
		return;

	if( parentNode != 0 && childNode != 0 )
	{
		// starting point
		Vect start(0.0f,0.0f,0.0f);

	   //  At this point, Find the two bones initial positions in world space
	   //  Now get the length and directions

		Vect ptA = start * parentNode->getWorld();

		Vect ptB = start * childNode->getWorld();

		// direction between the anchor points of the respective bones
		Vect dir = -(ptB - ptA);

		// length of the bone 0
		float mag = dir.mag();

		Matrix S( SCALE, boneWidth, boneWidth, mag);
		Quat Q( ROT_ORIENT, dir.getNorm(), Vect( 0.0f, 1.0f, 0.0f) );
		Matrix T( TRANS, ptB);

		/*Matrix Sp( SCALE, BONE_WIDTH, BONE_WIDTH, mag);
		Quat Qp( ROT_ORIENT, dir.getNorm(), Vect( 0.0f, 1.0f, 0.0f) );
		Matrix Tp( TRANS, ptA);*/

		Matrix BoneOrient = S * Q * T;
		//Matrix BoneOrientp  =Sp * Qp * Tp;
		//parentNode->setBoneOrientation(BoneOrientp);
		childNode->setBoneOrientation(BoneOrient); 
	}
}
예제 #4
0
void Ready::Enter(Bird* pBird)
{
	pBird;
	RubberBand* pBack = (RubberBand*)GameObjectMan::Find(GameObjectName::RubberBandBack);
	RubberBand* pFront = (RubberBand*)GameObjectMan::Find(GameObjectName::RubberBandFront);
	Vect A(pBack->anchorX, pBack->anchorY, 0);
	Vect B(pFront->anchorX, pFront->anchorY, 0);
	Vect C = B - A;
	float len = C.mag();
	C.norm();
	C = C* 0.5 * len;
	C = A + C;

	//firstPos.Set(pBird->posX, pBird->posY);
	//lastPos.Set(C[x], C[y]);
	JumpToSling *pJump = new JumpToSling(pBird, C[x], C[y], pBird->posX, pBird->posY,0);
	TimerMan::AddEvent(0.0f, pJump);
	//pBird->SetPosition(C[x], C[y]);
	//pBird->pBody->SetActive(false);
	TimerMan::CleanObjectEvents(pBird, EventName::JUMP);
}
예제 #5
0
void Skeleton::setBonePose(GraphicsObject * node, FrameBucket* pResult)
{
    // need this value for Scale Vector - would it change in derived classes?
    const float BONE_WIDTH = 2.0f;
	// Now get the world matrices - we know nodes are PyramidObjects for Skeleton
    // this casting may not be needed if we create a new AnimationObject to pass in instead of GraphicsObject
    PyramidObject *childNode = (PyramidObject *)node;
    PyramidObject *parentNode = (PyramidObject *)node->getParent();

    // Get the manager
    GraphicsObjectManager *goMgr = GraphicsObjectManager::getInstance();
    PCSTree* tree = goMgr->getTree();
	PCSNode* root = tree->getRoot();

    // for bone Bip01 - it is the anchor point, no need to set its pose when its parent is dummy root node
    if(parentNode == root)
        return;

	if( parentNode != 0 && childNode != 0 )
	{
        // starting point
	    Vect start(0.0f,0.0f,0.0f);

        // calling transform first to evaluate an up-to-date world, then get starting point in World coords
        // ***ORDER*** do this for parent first, then child - in transform, p1 will get parent's world matrix
        parentNode->transform(pResult);
	    Vect ptA = start * parentNode->getWorld();

        childNode->transform(pResult);
	    Vect ptB = start * childNode->getWorld();

        // At this point, we have the two bones initial positions in world space
        // Now get the direction between two anchor points of respective bones, and direction
		Vect dir = -(ptB- ptA);
		float mag = dir.mag();

        // used to flip pyramids to point outward
        Matrix T_flip(TRANS, 0.0f, 0.0f, 1.0f);
		// rotates it to Z axis
		Matrix R_flip( ROT_X, 180.0f * MATH_PI_180);

        Matrix S( SCALE, BONE_WIDTH, BONE_WIDTH, mag);
		Quat Q( ROT_ORIENT, dir.getNorm(), Vect( 0.0f, 1.0f, 0.0f) );
        Matrix T(TRANS, ptB);

        
        Matrix BoneOrient = S * Q * T;
        // Matrix BoneOrient = R_flip * T_flip * S * Q * T ;
        // Matrix BoneOrient = S * Q ;
        // Matrix BoneOrient = S;

        childNode->setBoneOrientation(BoneOrient);
    }

    /* deal with last node, when there isn't a terminal node - does this help in any way? 
    // copy orientation matrix from grandparent to set Parent's orientation 
	if( parentNode != 0 && childNode == 0 )
    {
		// get the parent's parent  -> grandParent
		GraphicsObject *grandParentNode = (GraphicsObject *)parentNode->getParent();
		Matrix BoneOrient = grandParentNode->getBoneOrientation();

		parentNode->setBoneOrientation( BoneOrient );
        // should be childNode now???
	} */
}
예제 #6
0
void MouseTest( GLFWwindow* window, GameObjectBird *pBird, ScreenLine* pLine1, ScreenLine* pLine2, std::list<GameObject *>  gameObjectList  )
{

	// Quick and dirty test, if these work the rest do.
	// --> try move the mouse inside the window, click right, click left
	if (!pBird)
		return;
	
	if (pBird->bState==SLING)
	{
		pBird->pBody->SetActive(false);
		b2Vec2 newPos( PixelToMeter((float)slingX), PixelToMeter((float)slingY) );
		pBird->pBody->SetTransform( newPos, 0.0f );
	}

	double xpos;
	double ypos;

	static float lastXPos;
	static float lastYPos;
	// get mouse position
	glfwGetCursorPos( window, &xpos, &ypos);
	Camera *pCam = Camera::Instance();
	pCam;
	// correct for origin
	double t = ypos / 600.0;
	ypos = 600.0 + t * (-600.0);


	MouseState			mState = NONE;
	PositionState		pState = UNKNOWN;

	GameObject* b = pBird;
	Matrix viewMatrix = pCam->getViewMatrix();
	Matrix projMatrix = pCam->getProjMatrix();
	Matrix worldMatrix = b->pGameSprite->returnWorld();
	Vect vout = Vect(0.0f,0.0f,0.0f) * worldMatrix * viewMatrix * projMatrix; 
	float zoom = vout[w];
	
	vout[x] = vout[x]/vout[w];
	vout[y] = vout[y]/vout[w];

	float X = (vout[x]+1.0f)*(pCam->viewport_width/2.0f);
	float Y= (vout[y]+1.0f)*(pCam->viewport_height/2.0f);

	Vect birdPos(pBird->pos.x, pBird->pos.y,0.0f);
	Vect mousePos((float ) xpos,(float ) ypos, 0.0f);
	
	Vect local( X, Y, 0.0f);
	Vect Dist = mousePos - local;
	
	if ( Dist.mag() < (10.0f / zoom) )
	{
		pState = INSIDE;
	}
	else
	{
		pState = OUTSIDE;
	}
	//printf("%f - %f", Dist[x],Dist[y] );
	//printf("  |  %f - %f", X, Y );
	//xpos = xpos + Dist[x]*zoom;
	//ypos = ypos + Dist[y]*zoom;
	//printf("%f - %f ",xpos, ypos);
	mState = NONE;
	if( glfwGetMouseButton (window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS)
	{
		mState = RIGHT;
	}

	if( glfwGetMouseButton (window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS)
	{
		
		mState = LEFT;
	}

	if (mState == LEFT && pBird->bState == NORMAL1)
	{
		pBird->bState = NORMAL2;
		pBird->onMouseAction();
		
	}

// Enter MOVING state
	if( mState == LEFT && pState == INSIDE)
	{
		;
		pBird->bState = MOVING;
		pBird->pBody->SetActive(false);
	}
	
	// small sublty here, once moving, left dictates mode
	if ( pBird->bState == MOVING)
	{
		if( mState == LEFT )//this drags the bird around
		{
			/*b2Vec2 newPos( PixelToMeter((float)xpos), PixelToMeter((float)ypos) );
			pBird->pBody->SetTransform( newPos, 0.0f );
			
			pLine1->posB=B;
			pLine2->posB=B;*/
			b2Vec2 slingPos(PixelToMeter((float)slingX), PixelToMeter((float)slingY));
			b2Vec2 newPos(PixelToMeter((float)pBird->pos.x+Dist[x]*zoom), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom));
			
			b2Vec2 check(PixelToMeter((float)pBird->pos.x+Dist[x]*zoom-slingX), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom - slingY));
			if (check.Length() > 2)
			{
				check.Normalize();
				newPos = slingPos + 2*check;
			}
			else
			{
				newPos.Set( PixelToMeter((float)pBird->pos.x+Dist[x]*zoom), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom) );
			}
			//printf("%f - %f ",newPos.x, newPos.y);
			pBird->pBody->SetTransform( newPos, 0.0f );
			Vect2D B(MeterToPixel((float)newPos.x), MeterToPixel((float)newPos.y));
			pLine1->posB=B;
			pLine2->posB=B;	
		}
		else//this fires bird from the slingshot
		{	
			
			b2Vec2 slingshot(PixelToMeter(slingX-pBird->pos.x), PixelToMeter(slingY-pBird->pos.y));
			pBird->bState = NORMAL1;
			pBird->pBody->SetActive(true);
			float32 mag = slingshot.Length();
			if (mag>2)
				mag=2;
			slingshot.Normalize();
			if (pBird->pBody->GetMass()<10)
				mag*=20;
			else
				mag*=200;
			b2Vec2 vel;
			vel = mag * slingshot;
			pBird->pBody->ApplyLinearImpulse( vel, pBird->pBody->GetWorldCenter(), true );
			pBird->pBody->SetActive(true);
			Vect2D B(slingX, slingY) ;
			pLine1->posB=B;
			pLine2->posB=B;
			pBird->launch();
			AzulCore::clearTrails();
			std::list< GameObject *>::iterator it=gameObjectList.begin();
			while( it!=gameObjectList.end() )
			{
				GameObject *pGameObj = *it++;
				
				pGameObj->damageActive=true;
			}
		}
	}
	if (pBird->bState==SLING)
	{
		pBird->pBody->SetActive(false);
		b2Vec2 newPos( PixelToMeter((float)slingX), PixelToMeter((float)slingY) );
		pBird->pBody->SetTransform( newPos, 0.0f );
	}

	if (pBird->bState==SLING||pBird->bState==MOVING)
	{
		AzulCore::setTargetAndSpeed((slingX), (slingY), -0.2f,0.01f);
	}
	else 
	{
		AzulCore::setTargetAndSpeed(pBird->pos.x, pBird->pos.y, 0.1f,10.0f);
	}
		
}
예제 #7
0
const float Vect::getAngle( const Vect &vIn ) const
{
	return acos( this->dot(vIn)/ (this->mag()*vIn.mag()) );
}