Пример #1
0
void Hero::checkEvent()
{
	if (0 < App::getEvent( CTRL ))	fixCamera( true );
	else							fixCamera( false );
	if (0 < App::getEvent( LEFT  ))	move( LEFT );
	if (0 < App::getEvent( RIGHT ))	move( RIGHT );
	if (0 < App::getEvent( UP    ))	move( UP );
	if (0 < App::getEvent( DOWN  ))	move( DOWN );
	//if (App::getEvent( ATACK ) >= 1 )	charge(); 
	//if (state == H_CHARGE && App::getEvent( ATACK ) == 0 ) atack();
	if ( phase < keyNum &&  doorRound() && App::getEvent( ATACK ) == 1 && state == H_NONE ) 
	{
		phase ++;
		GameScene::generateEnemies( phase );
		field->openDoor( keyNum-1 ); 
	}
	else if ( App::getEvent( ATACK ) == 1 && state == H_NONE && step < H_MAX_STEP )
	{
		if ( (step == 1 && H_JUST_ATACK_1_LOWER <= stateManager && stateManager <= H_JUST_ATACK_1_UPPER)
			|| (step == 2 && H_JUST_ATACK_2_LOWER <= stateManager && stateManager <= H_JUST_ATACK_2_UPPER) )
		{
			justAtack = true;
			GameScene::addScript( "just_v", Point2D( 0.94, 0.65 ), H_FRAME_SPAN_STEP, Color( 0, 1, 0.5), 0.4 );
		}
		setState( H_ATACK ); 
	}

	if (0 < App::getEvent( GUARD ) && state == H_NONE ) setState( H_GUARD );
	if (state == H_GUARD && App::getEvent( GUARD ) == 0 ) setState( H_NONE );
}
Пример #2
0
MainWindow::MainWindow()
{
    setupUi(this); 

    connect(action_Load_Model, SIGNAL(triggered()), this, SLOT(loadModel()));
    connect(action_Snap_Shot, SIGNAL(triggered()), this, SLOT(snapShot()));
    connect(action_Fix_Camera, SIGNAL(triggered()), this, SLOT(fixCamera()));
    connect(action_Reset_Screen, SIGNAL(triggered()), this, SLOT(resetScreen()));
    connect(action_Update_Geometry, SIGNAL(triggered()), this, SLOT(updateGeometry()));
    connect(action_Export_OBJ, SIGNAL(triggered()), this, SLOT(exportOBJ()));
    connect(action_Render, SIGNAL(triggered()), this, SLOT(renderTexture()));
    connect(action_Vector_Field, SIGNAL(triggered()), this, SLOT(setVectorField()));
    connect(action_Load_2D_3D_points, SIGNAL(triggered()), this, SLOT(loadPoints()));
    connect(action_Tool_Box, SIGNAL(triggered()), this, SLOT(showToolBox()));
    connect(action_Delete_Last_Line_Of_Source, SIGNAL(triggered()), this, SLOT(deleteLastLine_Source()));
    connect(action_Delete_Last_Line_Of_Target, SIGNAL(triggered()), this, SLOT(deleteLastLine_Target()));

    disp_modules.reset(new DispModuleHandler(centralwidget));
    this->setCentralWidget(centralwidget);

    parameter_dock.reset(new ParameterDock);
    parameter_dock->setFixedWidth(250);
    this->addDockWidget(Qt::LeftDockWidgetArea, parameter_dock.get());
    parameter_dock->setDispModules(disp_modules);
    parameter_dock->hide();

    this->show();

	//pointsSelect = false;
	//isCompute = false;
}
Пример #3
0
void CharacterGame::update(long elapsedTime)
{
    // Update character animation and movement
    if (keyFlags == 0)
    {
        _character->play("idle", PhysicsCharacter::ANIMATION_REPEAT, 1.0f, BLEND_DURATION);
    }
    else
    {
        // Forward motion
        if (keyFlags & 1)
        {
			if (moveBall)
			{
				static_cast<PhysicsRigidBody*>(_scene->findNode("Basketball")->getCollisionObject())->applyForce(Vector3(0, 0, -WALK_SPEED));
			}
			else
			{
				_character->play("walk", PhysicsCharacter::ANIMATION_REPEAT, ANIM_SPEED, BLEND_DURATION);
				_character->setForwardVelocity(1.0f);
			}
        }
        else if (keyFlags & 2)
        {
			if (moveBall)
			{
				static_cast<PhysicsRigidBody*>(_scene->findNode("Basketball")->getCollisionObject())->applyForce(Vector3(0, 0, WALK_SPEED));
			}
			else
			{
				_character->play("walk", PhysicsCharacter::ANIMATION_REPEAT, -ANIM_SPEED, BLEND_DURATION);
				_character->setForwardVelocity(-1.0f);
			}
        }
        else
        {
            // Cancel forward movement
            _character->setForwardVelocity(0.0f);
        }

        // Strafing
        if (keyFlags & 4)
        {
			if (moveBall)
			{
				static_cast<PhysicsRigidBody*>(_scene->findNode("Basketball")->getCollisionObject())->applyForce(Vector3(-WALK_SPEED, 0, 0));
			}
			else
			{
				_character->play("walk", PhysicsCharacter::ANIMATION_REPEAT, ANIM_SPEED, BLEND_DURATION);
				_character->setRightVelocity(1.0f);
			}
        }
        else if (keyFlags & 8)
        {
			if (moveBall)
			{
				static_cast<PhysicsRigidBody*>(_scene->findNode("Basketball")->getCollisionObject())->applyForce(Vector3(WALK_SPEED, 0, 0));
			}
			else
			{
				_character->play("walk", PhysicsCharacter::ANIMATION_REPEAT, -ANIM_SPEED, BLEND_DURATION);
				_character->setRightVelocity(-1.0f);
			}
        }
        else
        {
            // Cancel right movement
            _character->setRightVelocity(0.0f);
        }
    }

	if (!moveBall)
	{
		fixCamera(elapsedTime);
	}
}
Пример #4
0
void CharacterGame::fixCamera(long elapsedTime)
{
    static float cameraOffset = 0.0f;

#define RAY_STEP_SIZE 0.1f

    Node* node = _scene->getActiveCamera()->getNode();
    
    Vector3 cameraForward = node->getForwardVectorWorld();
    cameraForward.normalize();

    Vector3 cameraPosition = node->getTranslationWorld();
    Vector3 focalPoint = cameraPosition + (cameraForward * CAMERA_FOCUS_RANGE);

    Ray cameraRay(cameraPosition, cameraPosition - focalPoint);

    float d = cameraRay.getOrigin().distanceSquared(focalPoint);

    Vector3 collisionPoint;
    PhysicsCollisionObject* cameraOcclusion = Game::getInstance()->getPhysicsController()->rayTest(cameraRay, CAMERA_FOCUS_RANGE, &collisionPoint);
    bool cameraCollision = false;
    if (cameraOcclusion)
    {
        Vector3 rayStep = cameraRay.getDirection() * RAY_STEP_SIZE;
        do
        {
            float d2 = cameraRay.getOrigin().distanceSquared(collisionPoint);
            if (d2 > d)
                break; // collision point is past the character (not obstructing the view)

            cameraCollision = true;

            // Step along the camera ray closer to the character
            cameraRay.setOrigin(cameraRay.getOrigin() - rayStep);

            // Prevent camera from moving past character
            if (cameraRay.getOrigin().distanceSquared(focalPoint) < (RAY_STEP_SIZE*RAY_STEP_SIZE))
                break;
        }
        while ((cameraOcclusion = Game::getInstance()->getPhysicsController()->rayTest(cameraRay, CAMERA_FOCUS_RANGE, &collisionPoint)));
    }

    if (cameraCollision)
    {
        // Move camera
        float moveDistance = cameraPosition.distance(cameraRay.getOrigin());
        //node->setTranslation(0, 0, 0);
        node->translateForward(moveDistance);
        cameraOffset += moveDistance;
    }
    else
    {
        // Reset camera
        if (cameraOffset != 0.0f)
        {
            node->translateForward(-cameraOffset);
            cameraOffset = 0.0f;

            // Call updateCamera again to ensure that moving back didn't cause a different
            // object to obstruct the view.
            fixCamera(elapsedTime);
        }
    }
}