void MainWindow::mouseMoved(int x, int y)
{

	// Get number the number of pixel between the last
	// und current mouse position
	int dx = x - m_mouseX;
	int dy = y - m_mouseY;

	// Check which button was pressend and apply action
	if(m_button == GLUT_LEFT_BUTTON)
	{
		moveXY(dx, dy);
	}

	if(m_button == GLUT_RIGHT_BUTTON)
	{
		moveHead(dx, dy);
	}

	if(m_button == GLUT_MIDDLE_BUTTON)
	{
		moveZ(dy);
	}

	// Transform viewport
	m_cam.apply();

	// Save new coodinates
	m_mouseX = x;
	m_mouseY = y;

}
示例#2
0
文件: events.c 项目: silasb/cse581
void
moveDown()
{
  if(face == 0 && flip == 1) {
    moveZ(1);
  }
  else if(face == 0 &&  flip == -1) {
    moveZ(-1);
  }
  else if(face == 2 && flip == 1) {
    moveX(-1);
  }
  else if(face == 2 && flip == -1) {
    moveX(1);
  }
}
示例#3
0
文件: events.c 项目: silasb/cse581
void
moveUp()
{
  if(face == 0 && flip == 1) {
    if(!moveZ(-1))
      coi[1] += 5;
  }
  else if(face == 0 && flip == -1) {
    if(!moveZ(1))
      coi[1] += 5;
  }
  else if(face == 2 && flip == 1) {
    if(!moveX(1))
      coi[1] += 5;
  }
  else if(face == 2 && flip == -1) {
    if(!moveX(-1))
      coi[1] += 5;
  }
}
示例#4
0
	void FpsCamera::updateCameraView(float dt)
	{
		if(isKeyLeftPressed)
		{
			moveX(dt*speed);
		}
		
		if(isKeyRightPressed)
		{
			moveX(-dt*speed);
		}
		
		if(isKeyFrontPressed)
		{
			moveZ(dt*speed);
		}
		
		if(isKeyBackPressed)
		{
			moveZ(-dt*speed);
		}
	}
示例#5
0
	void FpsCamera::updateCameraView(float invFrameRate)
	{
		if(isKeyLeftPressed)
		{
			moveX(invFrameRate*speed);
		}
		
		if(isKeyRightPressed)
		{
			moveX(-invFrameRate*speed);
		}
		
		if(isKeyFrontPressed)
		{
			moveZ(invFrameRate*speed);
		}
		
		if(isKeyBackPressed)
		{
			moveZ(-invFrameRate*speed);
		}
	}
示例#6
0
void Controller::frame()
{
	if (move[dirY] != 0.0) moveY(move[dirY]);
	if (move[dirZ] != 0.0) moveZ(move[dirZ]);
	
	if (look[dirX] != 0.0) lookX(look[dirX]);
	if (look[dirY] != 0.0) lookY(look[dirY]);
	if (look[dirZ] != 0.0) lookZ(look[dirZ]);
	
	if (move[dirY] != 0.0)
	{
		if ((move[dirX] < 0.0 && move[dirY] > 0.0)
		||  (move[dirX] > 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(-0.05,Vd(0,0,1));
		else if ((move[dirX] > 0.0 && move[dirY] > 0.0)
		     ||  (move[dirX] < 0.0 && move[dirY] < 0.0))
			player->rotation = player->rotation * Rd(0.05,Vd(0,0,1));
		else
		{
            Vd camv = camAngle*Vd(0,1,0);
            Vd plav = player->rotation*Vd(0,1,0);
            camv.z = 0; camv = ~camv;
            plav.z = 0; plav = ~plav;
            double angle = atan2(camv.y - plav.y, camv.x - plav.x);
            double angle2 = (angle < 0? -angle : angle);
            double axis = angle2 >  0.5*Pi ^ angle > 0? 1 : -1;
            angle2 = angle2 > 0.5*Pi ? Pi - angle2 : angle2;
            angle2 = angle2 < 0.05? angle2 : 0.05;
			if (axis != 0)
                player->rotation = player->rotation * Rd(-angle2,Vd(0,0,axis));
		}
	}
	Vector<double> vec = (-player->rotation * Vector<double>(0,1,0));
	vec.z = 0;
	vec = ~vec;
	double yaw = atan2(vec.x, vec.y);
	target = player->origin + Pd(.75 * sin(yaw - .25*Pi), .75 * cos(yaw-.25*Pi), 2);
	vec = ~(camAngle * Vector<double>(0,1,0));
	if (firstPerson)
	{
		camera.lookAt(camera.origin + (vec * 5.0));
	}
	else
	{
		camera.lookAt(target);
	}
	Objects::Player * p = TO(Objects::Player,player);
	p->velocity = Vd(0,MoveSpeed,0);
}
示例#7
0
void Gib::act(std::vector< Object * > * others, World * world, std::vector< Object * > * add){
    if (fade > 0){
        fade += 2;
        if (fade > 255){
            setHealth(-1);
        }
    } else {

        moveX(dx);
        moveY(dy);
        moveZ(dz);

        dy -= 0.1;
        if ( getY() <= 0 ){
            dy = -dy / 2;
            dx = dx / 2;
            dz = dz / 2;
            if ( fade == 0 && fabs( dy ) < 0.1 ){
                fade = 1;
            }
        }

        double gibAmount = Configuration::getProperty(GibProperty, 5) / 5.0;
        for (int i = 0; i < Util::rnd((int)(2 * gibAmount)) + 2; i++){
            int x = getRX() + Util::rnd(5) - 2;
            int y = getRY() + Util::rnd(5) - 2;
            blood.push_back(Point(x, y, Util::rnd(10) + 5));
        }

        for (std::vector< Point >::iterator it = blood.begin(); it != blood.end(); /**/){
            Point & p = *it;
            p.life -= 1;
            if (p.life <= 0){
                it = blood.erase(it);
            } else {
                it++;
            }
        }

        angle += (int) sqrt(dx * dx + dy * dy) * 3;
    }
}
示例#8
0
void BuddyPlayer::act( vector< Object * > * others, World * world, vector< Object * > * add ){
    Character::act(others, world, add);

    if (show_life > getHealth()){
        show_life--;
    }

    if (show_life < getHealth()){
        show_life++;
    }

    vector<Object *> enemies;

    if (getStatus() != Status_Ground && getStatus() != Status_Jumping){
        return;
    }

    filterEnemies(enemies, others);

    if (animation_current->Act()){
        animation_current->reset();
        // nextTicket();
        // animation_current = movements[ "idle" ];
        animation_current = getMovement("idle");
        animation_current->reset();
    }

    if (animation_current == getMovement("idle") ||
        animation_current == getMovement("walk") ){
        if (enemies.empty() && want_x == -1 && want_z == -1 && Util::rnd(15) == 0){
            // want_x = Util::rnd( 100 ) - 50 + furthestFriend( others, getAlliance(), this );
            want_x = Util::rnd(100) - 50 + (int) leader->getX();
            want_z = Util::rnd(world->getMinimumZ(), world->getMaximumZ());
        } else if (! enemies.empty()){
            const Object * main_enemy = findClosest(enemies);
            if ( main_enemy->getX() > getX() ){
                want_x = (int)(main_enemy->getX() - 20 - Util::rnd(20));
            } else {
                want_x = (int)(main_enemy->getX() + 20 + Util::rnd(20));
            }
            if (want_x < 1){
                want_x = Util::rnd(100) - 50 + (int) leader->getX();
            }
            want_z = (int)(Util::rnd(3) - 1 + main_enemy->getZ());
            faceObject(main_enemy);

            if (Util::rnd(35) == 0){
                vector<Util::ReferenceCount<Animation> > attacks;
                for (map<string, Util::ReferenceCount<Animation> >::const_iterator it = getMovements().begin(); it != getMovements().end(); it++){
                    Util::ReferenceCount<Animation> maybe = (*it).second;
                    if (maybe->isAttack() && maybe->getStatus() == Status_Ground && maybe->getName() != "special"){
                        attacks.push_back(maybe);
                    }
                }

                double attack_range = fabs( getX() - main_enemy->getX() );
                double zdistance = ZDistance( main_enemy );
                for (vector<Util::ReferenceCount<Animation> >::iterator it = attacks.begin(); it != attacks.end(); /**/){
                    Util::ReferenceCount<Animation> maybe = *it;
                    if (attack_range > maybe->getRange() || zdistance > maybe->getMinZDistance()){
                        it = attacks.erase(it);
                    } else {
                        it++;
                    }
                }

                if (!attacks.empty()){
                    animation_current = attacks[Util::rnd(attacks.size())];
                    world->addMessage(animationMessage());
                    nextTicket();
                    animation_current->reset();
                    return;
                } else {
                }
            }
        }

        if (want_x != -1 && want_z != -1){
            bool walk = false;
            if (want_x < 1){
                want_x = 1;
            }
            if (want_z < world->getMinimumZ()){
                want_z = world->getMinimumZ() + 1;
            }
            if (want_z >= world->getMaximumZ()){
                want_z = world->getMaximumZ() - 1;
            }
            if (getX() - want_x < -2){
                moveX(getSpeed());
                setFacing(FACING_RIGHT);
                walk = true;
            } else if (getX() - want_x > 2){
                setFacing(FACING_LEFT);
                moveX(getSpeed());
                walk = true;
            }

            if (getZ() < want_z){
                moveZ(getSpeed());
                walk = true;
            } else if (getZ() > want_z){
                moveZ(-getSpeed());
                walk = true;
            }

            if (walk){
                animation_current = getMovement("walk");
            }

            if (fabs(getX() - want_x) <= 2 &&
                fabs(getZ() - want_z) <= 2){
                want_x = -1;
                want_z = -1;
                animation_current = getMovement("idle");
            }
        }
    }
}
示例#9
0
void Cat::act( vector< Object * > * others, World * world, vector< Object * > * add ){
	switch ( state ){
		case WALK : {
			moveX( -0.8 );
			if ( Util::rnd( 5 ) == 0 ){
				moveZ( -0.2 );
			}
			if ( Util::rnd( 5 ) == 0 ){
				moveZ( 0.2 );
			}
			break;
		}
		case RUN : {
			moveX( -2.2 );
			if ( Util::rnd( 5 ) == 0 ){
				moveZ( -0.2 );
			}
			if ( Util::rnd( 5 ) == 0 ){
				moveZ( 0.2 );
			}
			break;
		}
		default : {
			break;
		}
	}

	if ( current_animation->Act() ){
		switch ( state ){
			case IDLE1 :
			case IDLE2 : {
				switch ( Util::rnd( 5 ) ){
					case 0 : {
						state = IDLE1;
						current_animation = animations[ "idle1" ];
						break;
					}
					case 1 : {
						state = IDLE2;
						current_animation = animations[ "idle2" ];
						break;
					}
					case 2 :
					case 3 :
					case 4 : {
						state = YAWN;
						current_animation = animations[ "yawn" ];
						if ( Util::rnd( 2 ) == 0 ){
							setFacing( getOppositeFacing() );
						}
						break;
					}
					default : {
						break;
					}
				}
				break;
			}
			case YAWN : {
				switch ( Util::rnd( 6 ) ){
					case 0 :
					case 1 : {
						state = SIT;
						current_animation = animations[ "sit" ];
						break;
					}
					case 2 :
					case 3 :
					case 4 :
					case 5 : {
						state = WALK;
						current_animation = animations[ "walk" ];
						break;
					}
				}
				break;
			}
			case WALK : {
				switch ( Util::rnd( 12 ) ){
					case 0 : {
						state = SIT;
						current_animation = animations[ "sit" ];
						break;
					}
					case 1 :
					case 2 :
					case 3 : {
						state = TURN;
						current_animation = animations[ "turn" ];
						break;
					}
					case 4 :
					case 5 : {
						state = RUN;
						current_animation = animations[ "run" ];
					}
					default : {
					}
				}
				break;
			}
			case SIT : {
				switch ( Util::rnd( 2 ) ){
					case 0 : {
						state = IDLE1;
						current_animation = animations[ "idle1" ];
						break;
					}
					case 1 : {
						state = IDLE2;
						current_animation = animations[ "idle2" ];
						break;
					}
				}
				break;
			}
			case TURN : {
				setFacing( getOppositeFacing() );
				state = WALK;
				current_animation = animations[ "walk" ];
				break;
			}
			case RUN : {
				switch ( Util::rnd( 4 ) ){
					case 0 : {
						state = WALK;
						current_animation = animations[ "walk" ];
						break;
					}
					default : {
					}
				}
				break;
			}
		}
		current_animation->reset();
	}
}