Beispiel #1
0
void Game::draw() const
{
	drawEnvironment(this);

	drawGameField(false);
	sgoBall.drawGameBall();

	switch (mGameState) {
	case STATE_MENU:
		break;
	case STATE_COUNTDOWN:
		glPushMatrix();
		{
			const Vector3 x = rotateVector(Vector3(1.0f, 0.0f, 0.0f));
			const Vector3 y = rotateVector(Vector3(0.0f, 1.0f, 0.0f));
			const Vector3 z = rotateVector(Vector3(0.0f, 0.0f, 1.0f));

			const Vector3& pos = sgoBall.pos();

			Matrix m;

			m[0][0] = x.x;
			m[0][1] = x.y;
			m[0][2] = x.z;
			m[0][3] = 0.0f;

			m[1][0] = y.x;
			m[1][1] = y.y;
			m[1][2] = y.z;
			m[1][3] = 0.0f;

			m[2][0] = z.x;
			m[2][1] = z.y;
			m[2][2] = z.z;
			m[2][3] = 0.0f;

			m[3][0] = pos.x;
			m[3][1] = pos.y;
			m[3][2] = pos.z;
			m[3][3] = 1.0f;

			glMultMatrixf((GLfloat*) m);

			drawRingStrip(100, mCounter / COUNTDOWN_TIME, mTextureRing);
		}
		glPopMatrix();
		break;
	default:
		break;
	}
}
Beispiel #2
0
double F10::compute(double*x){
  int i;
  double result=0.0;

  if(Ovector==NULL)
    {
      Ovector = readOvector();
      Pvector = readPermVector();
      r25 = readR(25);
      r50 = readR(50);
      r100 = readR(100);
      s = readS(s_size);
      w = readW(s_size);
    }
  for(i=0;i<dimension;i++)
    {
      anotherz[i]=x[i]-Ovector[i];
    }
  
  // s_size non-separable part with rotation
  int c = 0;
  for (i = 0; i < s_size; i++)
    {
      // cout<<"c="<<c<<", i="<<i<<endl;
      anotherz1 = rotateVector(i, c);
      // cout<<"done rot"<<endl;
      result += w[i] * ackley(anotherz1, s[i]);
      delete []anotherz1;
      // cout<<result<<endl;
    }

  update(result);
  return(result);
}
int main()
{
    std::cout << "vector:\n";
    rotateVector();
    std::cout << "\narray:\n";
    rotateArray();
    return 0;
}
/*! Rotates the upVector by the current upVector angle
 * \param lookDir
 * \param plump
 */
SbVec3f kCamera::calcUpVector(const SbVec3f lookDir, const SbVec3f plump)
{
	SbVec3f upVec;
	upVec = calcPerfectUpVector(lookDir, plump);
	upVec.normalize();
	rotateVector(upVec,lookDir,currentUpVecAngle);
	upVec.normalize();
	return upVec;
}
Beispiel #5
0
double F4::compute(double*x){
  int    i;
  double result = 0.0;

  if(Ovector == NULL) {
    Ovector = readOvector();
    Pvector = readPermVector();
    r25 = readR(25);
    r50 = readR(50);
    r100 = readR(100);
    s = readS(s_size);
    w = readW(s_size);
  }
  
  for(i = 0; i < dimension; i++) {
    anotherz[i] = x[i] - Ovector[i];
  }

  // for (int i = 0; i < dimension; ++i)
  //   {
  //     cout<<anotherz[i]<<endl;
  //   }
  // cout<<endl;

  // // T_{osz}
  // transform_osz(anotherz);
  
  // s_size non-separable part with rotation
  int c = 0;
  for (i = 0; i < s_size; i++)
    {
      // cout<<"c="<<c<<", i="<<i<<endl;
      anotherz1 = rotateVector(i, c);
      // cout<<"done rot"<<endl;
      result += w[i] * elliptic(anotherz1, s[i]);
      delete []anotherz1;
      // cout<<result<<endl;
    }
  
  // one separable part without rotation
  double* z = new double[dimension-c];
  for (i = c; i < dimension; i++)
    {
      // cout<<i-c<<" "<<Pvector[i]<<" "<<anotherz[Pvector[i]]<<endl;
      z[i-c] = anotherz[Pvector[i]];
    }
  
  // cout<<"sep\n"<<elliptic(z, dimension-c)<<endl;
  
  result += elliptic(z, dimension-c);
  delete[] z;

//  printf("Rotated Part = %1.16E\n", rot_elliptic(anotherz1,nonSeparableGroupSize) * 1e6);
//  printf("Separable Part = %1.16E\n", elliptic(anotherz2,dimension - nonSeparableGroupSize));

  return(result);
}
Beispiel #6
0
void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) {
    btVector3 velocity = _rigidBody->getLinearVelocity() - _parentVelocity;
    computeNewVelocity(dt, velocity);
    _rigidBody->setLinearVelocity(velocity + _parentVelocity);

    // Dynamicaly compute a follow velocity to move this body toward the _followDesiredBodyTransform.
    // Rather than add this velocity to velocity the RigidBody, we explicitly teleport the RigidBody towards its goal.
    // This mirrors the computation done in MyAvatar::FollowHelper::postPhysicsUpdate().

    const float MINIMUM_TIME_REMAINING = 0.005f;
    const float MAX_DISPLACEMENT = 0.5f * _radius;
    _followTimeRemaining -= dt;
    if (_followTimeRemaining >= MINIMUM_TIME_REMAINING) {
        btTransform bodyTransform = _rigidBody->getWorldTransform();

        btVector3 startPos = bodyTransform.getOrigin();
        btVector3 deltaPos = _followDesiredBodyTransform.getOrigin() - startPos;
        btVector3 vel = deltaPos / _followTimeRemaining;
        btVector3 linearDisplacement = clampLength(vel * dt, MAX_DISPLACEMENT);  // clamp displacement to prevent tunneling.
        btVector3 endPos = startPos + linearDisplacement;

        btQuaternion startRot = bodyTransform.getRotation();
        glm::vec2 currentFacing = getFacingDir2D(bulletToGLM(startRot));
        glm::vec2 currentRight(currentFacing.y, -currentFacing.x);
        glm::vec2 desiredFacing = getFacingDir2D(bulletToGLM(_followDesiredBodyTransform.getRotation()));
        float deltaAngle = acosf(glm::clamp(glm::dot(currentFacing, desiredFacing), -1.0f, 1.0f));
        float angularSpeed = deltaAngle / _followTimeRemaining;
        float sign = copysignf(1.0f, glm::dot(desiredFacing, currentRight));
        btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularSpeed * dt);
        btQuaternion endRot = angularDisplacement * startRot;

        // in order to accumulate displacement of avatar position, we need to take _shapeLocalOffset into account.
        btVector3 shapeLocalOffset = glmToBullet(_shapeLocalOffset);
        btVector3 swingDisplacement = rotateVector(endRot, -shapeLocalOffset) - rotateVector(startRot, -shapeLocalOffset);

        _followLinearDisplacement = linearDisplacement + swingDisplacement + _followLinearDisplacement;
        _followAngularDisplacement = angularDisplacement * _followAngularDisplacement;

        _rigidBody->setWorldTransform(btTransform(endRot, endPos));
    }
    _followTime += dt;
}
bool ParallelCoordsAxisBoxPlot::eventFilter(QObject *widget, QEvent *e) {

  GlMainWidget *glWidget = dynamic_cast<GlMainWidget *>(widget);

  if(!glWidget)
    return false;

  initOrUpdateBoxPlots();

  if (e->type() == QEvent::MouseMove) {
    QMouseEvent *me = (QMouseEvent *) e;
    int x = glWidget->width() - me->x();
    int y = me->y();
    Coord screenCoords(x, y, 0.0f);
    Coord sceneCoords(glWidget->getScene()->getLayer("Main")->getCamera().viewportTo3DWorld(glWidget->screenToViewport(screenCoords)));
    selectedAxis = parallelView->getAxisUnderPointer(me->x(), me->y());

    if (selectedAxis != NULL && dynamic_cast<QuantitativeParallelAxis *>(selectedAxis)) {
      if (axisBoxPlotMap.find(static_cast<QuantitativeParallelAxis *>(selectedAxis)) != axisBoxPlotMap.end())
        if (parallelView->getLayoutType() == ParallelCoordinatesDrawing::CIRCULAR) {
          rotateVector(sceneCoords, -(selectedAxis->getRotationAngle()), Z_ROT);
        }

      axisBoxPlotMap[static_cast<QuantitativeParallelAxis *>(selectedAxis)]->setHighlightRangeIfAny(sceneCoords);
    }

    parallelView->refresh();
    return true;
  }

  if (e->type() == QEvent::MouseButtonPress) {
    return false;
  }

  if (e->type() == QEvent::MouseButtonRelease) {
    if (selectedAxis != NULL && dynamic_cast<QuantitativeParallelAxis *>(selectedAxis)) {
      Observable::holdObservers();

      if (axisBoxPlotMap.find(static_cast<QuantitativeParallelAxis *>(selectedAxis)) != axisBoxPlotMap.end())
        parallelView->highlightDataInAxisBoxPlotRange(static_cast<QuantitativeParallelAxis *>(selectedAxis));

      Observable::unholdObservers();
      selectedAxis = NULL;
      parallelView->refresh();
      return true;
    }
  }

  return false;
}
/*! \param angle */
void kCamera::rotateCam(double angle)
{
	// UpVec rotieren - bisher nur um die Sichtachse, also kein Kippen gegenüber der Sichtrichtung
	// Bei anderen Rotationen müssten dann sowohl UpVec wie auch lookDir gedreht werden

	currentUpVecAngle = currentUpVecAngle + angle;

	SbVec3f perfectUpVec = calcPerfectUpVector(currentLookDir,NormPlump);
	perfectUpVec.normalize();
	rotateVector(perfectUpVec,currentLookDir, currentUpVecAngle);
	currentUpVec = perfectUpVec;

	currentOrientation = calcOrientation(currentUpVec,currentLookDir); //! Berechnet neue orientation
	//writeOrientation(currentOrientation); //! Schreibt orientation in ObjMgr
}
void FlowBox::rotate(float da)
{
	if (ROTATION_OFFSET)
	{
		cv::Point2f mean = cv::Point2f(x, y);
		cv::Point2f COR = getRotationCenter();
	
		mean = rotateVector(mean - COR, da) + COR;

		x = mean.x;
		y = mean.y;	
	}

	phi = static_cast<float>(fmod(phi + da + 720, 360));

}
Beispiel #10
0
double F7::compute(double*x){
  int    i;
  double result = 0.0;

  if(Ovector == NULL) {
    Ovector = readOvector();
    Pvector = readPermVector();
    r25 = readR(25);
    r50 = readR(50);
    r100 = readR(100);
    s = readS(s_size);
    w = readW(s_size);
  }

  for(i = 0; i < dimension; i++) {
    anotherz[i] = x[i] - Ovector[i];
  }

  // s_size non-separable part with rotation
  int c = 0;
  for (i = 0; i < s_size; i++)
    {
      // cout<<"c="<<c<<", i="<<i<<endl;
      anotherz1 = rotateVector(i, c);
      // cout<<"done rot"<<endl;
      result += w[i] * schwefel(anotherz1, s[i]);
      delete []anotherz1;
      // cout<<result<<endl;
    }
  
  // one separable part without rotation
  double* z = new double[dimension-c];
  for (i = c; i < dimension; i++)
    {
      // cout<<i-c<<" "<<Pvector[i]<<" "<<anotherz[Pvector[i]]<<endl;
      z[i-c] = anotherz[Pvector[i]];
    }
  
  result += sphere(z, dimension-c);
  delete []z;

  return(result);
}
Beispiel #11
0
cv::Point2f FlowBox::getRotationCenter() const
{
	return rotateVector(cv::Point2f(ROTATION_OFFSET * ROTATION_OFFSET / 2, 0), -phi) + cv::Point2f(x, y);
}
Beispiel #12
0
void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) {

    const btScalar MIN_SPEED = 0.001f;

    btVector3 actualVelocity = _rigidBody->getLinearVelocity();
    if (actualVelocity.length() < MIN_SPEED) {
        actualVelocity = btVector3(0.0f, 0.0f, 0.0f);
    }

    btVector3 desiredVelocity = _walkVelocity;
    if (desiredVelocity.length() < MIN_SPEED) {
        desiredVelocity = btVector3(0.0f, 0.0f, 0.0f);
    }

    // decompose into horizontal and vertical components.
    btVector3 actualVertVelocity = actualVelocity.dot(_currentUp) * _currentUp;
    btVector3 actualHorizVelocity = actualVelocity - actualVertVelocity;
    btVector3 desiredVertVelocity = desiredVelocity.dot(_currentUp) * _currentUp;
    btVector3 desiredHorizVelocity = desiredVelocity - desiredVertVelocity;

    btVector3 finalVelocity;

    switch (_state) {
    case State::Ground:
    case State::Takeoff:
        {
            // horizontal ground control
            const btScalar WALK_ACCELERATION_TIMESCALE = 0.1f;
            btScalar tau = dt / WALK_ACCELERATION_TIMESCALE;
            finalVelocity = tau * desiredHorizVelocity + (1.0f - tau) * actualHorizVelocity + actualVertVelocity;
        }
        break;
    case State::InAir:
        {
            // horizontal air control
            const btScalar IN_AIR_ACCELERATION_TIMESCALE = 2.0f;
            btScalar tau = dt / IN_AIR_ACCELERATION_TIMESCALE;
            finalVelocity = tau * desiredHorizVelocity + (1.0f - tau) * actualHorizVelocity + actualVertVelocity;
        }
        break;
    case State::Hover:
        {
            // vertical and horizontal air control
            const btScalar FLY_ACCELERATION_TIMESCALE = 0.2f;
            btScalar tau = dt / FLY_ACCELERATION_TIMESCALE;
            finalVelocity = tau * desiredVelocity + (1.0f - tau) * actualVelocity;
        }
        break;
    }

    _rigidBody->setLinearVelocity(finalVelocity);

    // Dynamicaly compute a follow velocity to move this body toward the _followDesiredBodyTransform.
    // Rather then add this velocity to velocity the RigidBody, we explicitly teleport the RigidBody towards its goal.
    // This mirrors the computation done in MyAvatar::FollowHelper::postPhysicsUpdate().

    const float MINIMUM_TIME_REMAINING = 0.005f;
    const float MAX_DISPLACEMENT = 0.5f * _radius;
    _followTimeRemaining -= dt;
    if (_followTimeRemaining >= MINIMUM_TIME_REMAINING) {
        btTransform bodyTransform = _rigidBody->getWorldTransform();

        btVector3 startPos = bodyTransform.getOrigin();
        btVector3 deltaPos = _followDesiredBodyTransform.getOrigin() - startPos;
        btVector3 vel = deltaPos / _followTimeRemaining;
        btVector3 linearDisplacement = clampLength(vel * dt, MAX_DISPLACEMENT);  // clamp displacement to prevent tunneling.
        btVector3 endPos = startPos + linearDisplacement;

        btQuaternion startRot = bodyTransform.getRotation();
        glm::vec2 currentFacing = getFacingDir2D(bulletToGLM(startRot));
        glm::vec2 currentRight(currentFacing.y, -currentFacing.x);
        glm::vec2 desiredFacing = getFacingDir2D(bulletToGLM(_followDesiredBodyTransform.getRotation()));
        float deltaAngle = acosf(glm::clamp(glm::dot(currentFacing, desiredFacing), -1.0f, 1.0f));
        float angularSpeed = deltaAngle / _followTimeRemaining;
        float sign = copysignf(1.0f, glm::dot(desiredFacing, currentRight));
        btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularSpeed * dt);
        btQuaternion endRot = angularDisplacement * startRot;

        // in order to accumulate displacement of avatar position, we need to take _shapeLocalOffset into account.
        btVector3 shapeLocalOffset = glmToBullet(_shapeLocalOffset);
        btVector3 swingDisplacement = rotateVector(endRot, -shapeLocalOffset) - rotateVector(startRot, -shapeLocalOffset);

        _followLinearDisplacement = linearDisplacement + swingDisplacement + _followLinearDisplacement;
        _followAngularDisplacement = angularDisplacement * _followAngularDisplacement;

        _rigidBody->setWorldTransform(btTransform(endRot, endPos));
    }
    _followTime += dt;
}
Beispiel #13
0
bool CollisionModel3D::rayCollision(RayCollisionTest *test) const
{
    if (test == NULL)
        return false;

    float mintparm = 9e9f, tparm;
    Vector3D col_point;
    Vector3D O;
    Vector3D D;
    float segmin = test->raySegmentMin();
    float segmax = test->raySegmentMax();

    test->m_collides = false;
    test->m_iColTri = -1;

    if (d->m_isStatic) {
        O = Transform(Vector3D::asConstRef(test->rayOrigin()), d->m_invTransform);
        D = rotateVector(Vector3D::asConstRef(test->rayDirection()), d->m_invTransform);
    }
    else {
        const Matrix3D inv = d->m_transform.Inverse();
        O = Transform(Vector3D::asConstRef(test->rayOrigin()), inv);
        D = rotateVector(Vector3D::asConstRef(test->rayDirection()), inv);
    }

    if (!fuzzyIsNull(segmin)) { // Normalize ray
        O += segmin * D;
        segmax -= segmin;
        segmin = 0.0f;
    }
    if (segmax < segmin)
    {
        D = -D;
        segmax = -segmax;
    }
    std::vector<const BoxTreeNode*> checks;
    checks.push_back(&d->m_root);
    while (!checks.empty()) {
        const BoxTreeNode* b = checks.back();
        checks.pop_back();
        if (b->intersect(O, D, segmax)) {
            int sons = b->getSonsNumber();
            if (sons) {
                while (sons--)
                    checks.push_back(b->getSon(sons));
            }
            else {
                std::size_t tri = b->getTrianglesNumber();
                while (tri--) {
                    const BoxedTriangle* bt = b->getTriangle(tri);
                    const Triangle* t = static_cast<const Triangle*>(bt);
                    if (t->intersect(O, D, col_point, tparm, segmax))  {
                        if (test->raySearch() == RayCollisionTest::SearchClosestTriangle) {
                            if (tparm < mintparm) {
                                mintparm = tparm;
                                bt->copyCoords(test->m_colTri);
                                test->m_iColTri = d->getTriangleIndex(bt);
                                Vector3D::asRef(test->m_colPnt) = col_point;
                            }
                        }
                        else {
                            bt->copyCoords(test->m_colTri);
                            test->m_iColTri = d->getTriangleIndex(bt);
                            Vector3D::asRef(test->m_colPnt) = col_point;
                            test->m_collides = true;
                            return true;
                        }
                    }
                }
            }
        }
    }
    if (test->raySearch() == RayCollisionTest::SearchClosestTriangle && mintparm < 9e9f) {
        test->m_collides = true;
        return true;
    }
    return false;
}
State collideObjects(PhysicsObject* a, PhysicsObject* b){
	State state;
	state.deltaAngVel = 0;
	state.deltaPosition = pointMake(0, 0);
	state.deltaVel = pointMake(0, 0);
	
	CollisionPair pairs[2*PHYSICS_OBJECT_MAXIMUM_POINTS];
	if(!coarseCollision(a, b)){
		return state;
	}
	
	//if a coarse collision happened, we will search for a refined one in each of A's edges.
	//in this step we try to find every point where B has hitted A and A has hitted B
	int Acurrent, Anext, Abefore, Bcurrent, Bnext, pairCount=0;
	
	//first case---------------------------------------------------------------------------
	/* 
	 PA1     PA3
	 \      /
	  \    /
  PB2---------PB1
	    \/
		PA2
	 
	V=A --=B
	*/
	for (Acurrent=0; Acurrent<a->format.polygonInfo.count; Acurrent++) {
		/*Given 3 sequenced vertex, we create two vectors, one from the
		 first to the second vertex and other from the second to the
		 third vertex.*/
		Anext = Acurrent==a->format.polygonInfo.count-1?0:Acurrent+1;
		Abefore = Acurrent==0?a->format.polygonInfo.count-1:Acurrent-1;
		Point PA1 = worldPosition(a->format.polygonInfo.points[Abefore],*a);
		Point PA2 = worldPosition(a->format.polygonInfo.points[Acurrent],*a);
		Point PA3 = worldPosition(a->format.polygonInfo.points[Anext],*a);
		Vector A1 = pointMake(PA2.x-PA1.x, PA2.y-PA1.y);
		Vector A2 = pointMake(PA3.x-PA2.x, PA3.y-PA2.y);

		pairs[pairCount].depth = 0;
		pairs[pairCount].normal = pointMake(0, 0);
		for (Bcurrent = 0; Bcurrent<b->format.polygonInfo.count; Bcurrent++) {
			/*for each edge of B, we will find if any of the edges are hitted by both
			 edges defined before, if thats the case, then A hitted B on that point
			 If both edges of A hitted more than one edge of B, we will keep the highest
			 depth*/
			Bnext = Bcurrent==b->format.polygonInfo.count-1?0:Bcurrent+1;
			Point PB1 = worldPosition(b->format.polygonInfo.points[Bcurrent], *b);
			Point PB2 = worldPosition(b->format.polygonInfo.points[Bnext], *b);
			Vector B = pointMake(PB2.x-PB1.x, PB2.y-PB1.y);
			Vector I1 = pointMake(PB1.x-PA1.x, PB1.y-PA1.y);
			Vector I2 = pointMake(PB1.x-PA2.x, PB1.y-PA2.y);
			
			float crossBI1 = B.x*I1.y-B.y*I1.x;
			float crossBI2 = B.x*I2.y-B.y*I2.x;
			float crossAI1 = A1.x*I1.y-A1.y*I1.x;
			float crossAI2 = A2.x*I2.y-A2.y*I2.x;
			float crossBA1 = B.x*A1.y-B.y*A1.x;
			float crossBA2 = B.x*A2.y-B.y*A2.x;
			
			crossBA1=crossBA1==0?0.0001:crossBA1;
			crossBA2=crossBA2==0?0.0001:crossBA2;
			
			float t1 = crossAI1/crossBA1;
			float w1 = crossBI1/crossBA1;
			float t2 = crossAI2/crossBA2;
			float w2 = crossBI2/crossBA2;
			
			if(t1>0 && t1<1 && w1>0 && w1<1 && t2>0 && t2<1 && w2>0 && w2<1){
				//we do have a collision
				
				Vector normal = rotateVector(B, -PI*0.5); //rotate the edge by -90 degrees, so that it points outside
				normalizePoint(&normal);
				Point collisionPoint=pointMake(((PA1.x+w1*A1.x)+(PA2.x+w2*A2.x))*0.5, ((PA1.y+w1*A1.y)+(PA2.y+w2*A2.y))*0.5);
				float depth = (PA2.x-collisionPoint.x)*normal.x+(PA2.y-collisionPoint.y)*normal.y;
				depth = -depth;
				if(Fabs(depth)>Fabs(pairs[pairCount].depth)){
					pairs[pairCount].depth = depth;
					pairs[pairCount].normal = normal;
					pairs[pairCount].location=collisionPoint;
				}
			}
		}
		if(Fabs(pairs[pairCount].depth)>0){
			pairCount++;
		}
	}
	
	//second case---------------------------------------------------------------------------
	/*
	 PA1     PA3
	 \      /
	  \    /
  PB2---------PB1
	    \/
		PA2
	 
	 V=B --=A
	 */
	//Although we did not change the names, A variables now refers to B while B variables refer to A
	for (Acurrent=0; Acurrent<b->format.polygonInfo.count; Acurrent++) {
		/*Given 3 sequenced vertex, we create two vectors, one from the
		 first to the second vertex and other from the second to the
		 third vertex.*/
		Anext = Acurrent==b->format.polygonInfo.count-1?0:Acurrent+1;
		Abefore = Acurrent==0?b->format.polygonInfo.count-1:Acurrent-1;
		Point PA1 = worldPosition(b->format.polygonInfo.points[Abefore],*b);
		Point PA2 = worldPosition(b->format.polygonInfo.points[Acurrent],*b);
		Point PA3 = worldPosition(b->format.polygonInfo.points[Anext],*b);
		Vector A1 = pointMake(PA2.x-PA1.x, PA2.y-PA1.y);
		Vector A2 = pointMake(PA3.x-PA2.x, PA3.y-PA2.y);
		
		pairs[pairCount].depth = 0;
		pairs[pairCount].normal = pointMake(0, 0);
		for (Bcurrent = 0; Bcurrent<a->format.polygonInfo.count; Bcurrent++) {
			/*for each edge of A, we will find if any of the edges are hitted by both
			 edges defined before, if thats the case, then A hitted B on that point
			 If both edges of B hitted more than one edge of A, we will keep the highest
			 depth*/
			Bnext = Bcurrent==a->format.polygonInfo.count-1?0:Bcurrent+1;
			Point PB1 = worldPosition(a->format.polygonInfo.points[Bcurrent], *a);
			Point PB2 = worldPosition(a->format.polygonInfo.points[Bnext], *a);
			Vector B = pointMake(PB2.x-PB1.x, PB2.y-PB1.y);
			Vector I1 = pointMake(PB1.x-PA1.x, PB1.y-PA1.y);
			Vector I2 = pointMake(PB1.x-PA2.x, PB1.y-PA2.y);
			
			float crossBI1 = B.x*I1.y-B.y*I1.x;
			float crossBI2 = B.x*I2.y-B.y*I2.x;
			float crossAI1 = A1.x*I1.y-A1.y*I1.x;
			float crossAI2 = A2.x*I2.y-A2.y*I2.x;
			float crossBA1 = B.x*A1.y-B.y*A1.x;
			float crossBA2 = B.x*A2.y-B.y*A2.x;
			
			crossBA1=crossBA1==0?0.0001:crossBA1;
			crossBA2=crossBA2==0?0.0001:crossBA2;
			
			float t1 = crossAI1/crossBA1;
			float w1 = crossBI1/crossBA1;
			float t2 = crossAI2/crossBA2;
			float w2 = crossBI2/crossBA2;
			
			if(t1>0 && t1<1 && w1>0 && w1<1 && t2>0 && t2<1 && w2>0 && w2<1){
				//we do have a collision
				
				Vector normal = rotateVector(B, -PI*0.5); //rotate the edge by -90 degrees, so that it points outside
				normalizePoint(&normal);
				Point collisionPoint=pointMake(((PA1.x+w1*A1.x)+(PA2.x+w2*A2.x))*0.5, ((PA1.y+w1*A1.y)+(PA2.y+w2*A2.y))*0.5);
				float depth = (PA2.x-collisionPoint.x)*normal.x+(PA2.y-collisionPoint.y)*normal.y;
				if(Fabs(depth)>Fabs(pairs[pairCount].depth)){
					pairs[pairCount].depth = depth;
					pairs[pairCount].normal = normal;
					pairs[pairCount].location=collisionPoint;
				}
			}
		}
		if(Fabs(pairs[pairCount].depth)>0){
			pairCount++;
		}
	}
	
	//third case---------------------------------------------------------------------------
	/*
	PA1     PA3
	 \  PB2 /
	  \ /\ /
       X  X
	  / \/ \
	 /  PA2 \
   PB3      PB1
	 
	 V=A /\=B
	 */
	int Bbefore;
	for (Acurrent=0; Acurrent<a->format.polygonInfo.count; Acurrent++) {
		/*Given 3 sequenced vertex, we create two vectors, one from the
		 first to the second vertex and other from the second to the
		 third vertex.*/
		Anext = Acurrent==a->format.polygonInfo.count-1?0:Acurrent+1;
		Abefore = Acurrent==0?a->format.polygonInfo.count-1:Acurrent-1;
		Point PA1 = worldPosition(a->format.polygonInfo.points[Abefore],*a);
		Point PA2 = worldPosition(a->format.polygonInfo.points[Acurrent],*a);
		Point PA3 = worldPosition(a->format.polygonInfo.points[Anext],*a);
		Vector A12 = pointMake(PA2.x-PA1.x, PA2.y-PA1.y);
		Vector A23 = pointMake(PA3.x-PA2.x, PA3.y-PA2.y);
		
		pairs[pairCount].depth = 0;
		pairs[pairCount].normal = pointMake(0, 0);
		for (Bcurrent = 0; Bcurrent<b->format.polygonInfo.count; Bcurrent++) {
			/*for each pair of edge of B, we will find if any of the edges are hitted as shown above*/
			Bnext = Bcurrent==b->format.polygonInfo.count-1?0:Bcurrent+1;
			Bbefore = Bcurrent==0?b->format.polygonInfo.count-1:Bcurrent-1;
			Point PB1 = worldPosition(b->format.polygonInfo.points[Bbefore], *b);
			Point PB2 = worldPosition(b->format.polygonInfo.points[Bcurrent], *b);
			Point PB3 = worldPosition(b->format.polygonInfo.points[Bnext], *b);
			Vector B12 = pointMake(PB2.x-PB1.x, PB2.y-PB1.y);
			Vector B23 = pointMake(PB3.x-PB2.x, PB3.y-PB2.y);
			Vector IA12B23 = pointMake(PB2.x-PA1.x, PB2.y-PA1.y);
			Vector IA23B12 = pointMake(PB1.x-PA2.x, PB1.y-PA2.y);
			
			float crossB12I = B12.x*IA23B12.y-B12.y*IA23B12.x;
			float crossB23I = B23.x*IA12B23.y-B23.y*IA12B23.x;
			float crossA12I = A12.x*IA12B23.y-A12.y*IA12B23.x;
			float crossA23I = A23.x*IA23B12.y-A23.y*IA23B12.x;
			float crossB12A23 = B12.x*A23.y-B12.y*A23.x;
			float crossB23A12 = B23.x*A12.y-B23.y*A12.x;
			
			crossB23A12=crossB23A12==0?0.0001:crossB23A12;
			crossB12A23=crossB12A23==0?0.0001:crossB12A23;
			
			float t1 = crossA12I/crossB23A12;
			float w1 = crossB23I/crossB23A12;
			float t2 = crossA23I/crossB12A23;
			float w2 = crossB12I/crossB12A23;
			
			if(t1>0 && t1<1 && w1>0 && w1<1 && t2>0 && t2<1 && w2>0 && w2<1){
				//we do have a collision
				Point collision1 = pointMake((PA1.x+w1*A12.x), (PA1.y+w1*A12.y));
				Point collision2 = pointMake((PA2.x+w2*A23.x), (PA2.y+w2*A23.y));
				Vector c12 = pointMake(collision2.x-collision1.x, collision2.y-collision1.y);
				Vector normal = rotateVector(c12, -PI*0.5); //rotate the edge by -90 degrees, so that it points outside
				normalizePoint(&normal);
				Point collisionPoint=pointMake((collision1.x+collision2.x)*0.5, (collision1.y+collision2.y)*0.5);
				float depth = (PA2.x-PB2.x)*normal.x+(PA2.y-PB2.y)*normal.y;
				depth = -depth;
				pairs[pairCount].depth = depth;
				pairs[pairCount].normal = normal;
				pairs[pairCount].location=collisionPoint;
				pairCount++;
			}
		}
	}
	
	int currentCollision;
	//solves the physics part ot the collision for each collision that has happened

	for (currentCollision =0; currentCollision<pairCount; currentCollision++) {
		State st = physicsResolution(a,b,pairs[currentCollision]);
		state.deltaAngVel += st.deltaAngVel;
		state.deltaPosition=pointMake(st.deltaPosition.x+state.deltaPosition.x, st.deltaPosition.y+state.deltaPosition.y);
		state.deltaVel=pointMake(st.deltaVel.x+state.deltaVel.x, st.deltaVel.y+state.deltaVel.y);
	}
	state.deltaAngVel += a->angularVelocity;
	state.deltaVel = pointMake(a->linearVelocity.x+state.deltaVel.x, a->linearVelocity.y+state.deltaVel.y);
	state.deltaPosition = pointMake(a->position.x+state.deltaPosition.x, a->position.y+state.deltaPosition.y);
	
	return state;
}
Beispiel #15
0
MeshDataStat *PeriodicRotMesh::getRotatedMesh(int timeStepNo,
                                              double angle)
{
    MeshDataStat *origDat = _originalData->getMeshDataStat(timeStepNo);
    int noOfPoints = 0;
    int noOfElements = 0;
    int noOfVertices = 0;
    int *elementsArr = NULL;
    int *verticesArr = NULL;
    int *typesArr = NULL;
    float *xPointsArr = NULL;
    float *yPointsArr = NULL;
    float *zPointsArr = NULL;
    origDat->getMeshData(&noOfElements, &noOfVertices, &noOfPoints,
                         &elementsArr, &verticesArr,
                         &xPointsArr, &yPointsArr, &zPointsArr,
                         &typesArr);
    // copy arrays
    float *xPointsCopy = new float[noOfPoints];
    float *yPointsCopy = new float[noOfPoints];
    float *zPointsCopy = new float[noOfPoints];
    int i;
    for (i = 0; i < noOfPoints; i++)
    {
        xPointsCopy[i] = xPointsArr[i];
        yPointsCopy[i] = yPointsArr[i];
        zPointsCopy[i] = zPointsArr[i];
    }
    //    int* verticesCopy = new int[noOfVertices];    // crashes if out of mem
    //    int* elementsCopy = new int[noOfElements];
    //    int* typesCopy = new int[noOfElements];
    int *verticesCopy = (int *)malloc(sizeof(int) * noOfVertices);
    int *elementsCopy = (int *)malloc(sizeof(int) * noOfElements);
    int *typesCopy = (int *)malloc(sizeof(int) * noOfElements);
    ASSERT0(verticesCopy != NULL && elementsCopy != NULL && typesCopy != NULL, "error: out of memory.", _outputHandler);

    for (i = 0; i < noOfVertices; i++)
    {
        verticesCopy[i] = verticesArr[i];
    }

    for (i = 0; i < noOfElements; i++)
    {
        elementsCopy[i] = elementsArr[i];
        typesCopy[i] = typesArr[i];
    }

    // rotate grid
    for (i = 0; i < noOfPoints; i++)
    {
        PointCC r = { xPointsCopy[i], yPointsCopy[i], zPointsCopy[i] };
        r = rotateVector(r, angle);
        xPointsCopy[i] = r.x;
        yPointsCopy[i] = r.y;
        zPointsCopy[i] = r.z;
    }

    // copy mapper array
    int maxNodeNoMesh = _originalData->getMaxNodeNo(timeStepNo);
    int *mesh2internal = new int[maxNodeNoMesh + 1];
    for (i = 0; i <= maxNodeNoMesh; i++)
    {
        mesh2internal[i] = origDat->getInternalNodeNo(i);
    }

    MeshDataStat *retval = new MeshDataStatBinary(noOfElements, noOfVertices, noOfPoints, elementsCopy,
                                                  verticesCopy, xPointsCopy, yPointsCopy, zPointsCopy,
                                                  typesCopy, mesh2internal, maxNodeNoMesh, _outputHandler);
    return retval;
}
Beispiel #16
0
bool CollisionModel3DImpl::rayCollision(float origin[3], 
                                        float direction[3],
                                        bool closest,
                                        float segmin, 
                                        float segmax)
{
  float mintparm=9e9f,tparm;
  Vector3D col_point;
  m_ColType=Ray;
  Vector3D O;
  Vector3D D;
  if (m_Static)
  {
    O=Transform(*(Vector3D*)origin,m_InvTransform);
    D=rotateVector(*(Vector3D*)direction,m_InvTransform);
  }
  else
  {
    Matrix3D inv=m_Transform.Inverse();
    O=Transform(*(Vector3D*)origin,inv);
    D=rotateVector(*(Vector3D*)direction,inv);
  }
  if (segmin!=0.0f) // normalize ray
  {
    O+=segmin*D;
    segmax-=segmin;
    segmin=0.0f;
  }
  if (segmax<segmin) 
  {
    D=-D;
    segmax=-segmax;
  }
  std::vector<BoxTreeNode*> checks;
  checks.push_back(&m_Root);
  while (!checks.empty())
  {
    BoxTreeNode* b=checks.back();
    checks.pop_back();
    if (b->intersect(O,D,segmax))
    {
      int sons=b->getSonsNumber();
      if (sons)
        while (sons--) checks.push_back(b->getSon(sons));
      else
      {
        int tri=b->getTrianglesNumber();
        while (tri--)
        {
          BoxedTriangle* bt=b->getTriangle(tri);
          Triangle* t=static_cast<Triangle*>(bt);
          if (t->intersect(O,D,col_point,tparm,segmax)) 
          {
            if (closest)
            {
              if (tparm<mintparm)
              {
                mintparm=tparm;
                m_ColTri1=*bt;
                m_iColTri1=getTriangleIndex(bt);
                m_ColPoint=col_point;
              }
            }
            else
            {
              m_ColTri1=*bt;
              m_iColTri1=getTriangleIndex(bt);
              m_ColPoint=col_point;
              return true;
            }
          }
        }
      }
    }
  }
  if (closest && mintparm<9e9f) return true;
  return false;
}
Beispiel #17
0
	inline Vector4f rotatedVector(const Vector4f& v) const { Vector4f result(v); rotateVector(result); return result; }
	void ProgressBar::doRender(const RenderState &rs)
	{
		if (_progress == 0)
			return;
		if (((_direction != __dir_radial_ccw) && (_direction != dir_radial_cw)) || (_progress == 1.0f))
		{
			Sprite::doRender(rs);
			return;
		}

		_vstyle._apply(rs);
		const Diffuse &df = _frame.getDiffuse();
		if (df.base)
		{
			rs.renderer->setDiffuse(df);

			unsigned int rgba = rs.renderer->getPrimaryColor().rgba();

			RectF destRect = Sprite::getDestRect();

			RectF srcRect = _frame.getSrcRect();
			float u = srcRect.pos.x;
			float v = srcRect.pos.y;

			float du = srcRect.size.x;
			float dv = srcRect.size.y;	

			u += du / 2.f;
			v += dv / 2.f;

			Vector2 pos = destRect.pos;
			const Vector2 &size = destRect.size;
			pos += size / 2.f;				

			float maxSide = std::max( size.x, size.y );

			Vector2 vecCenter( pos.x, pos.y );
			Vector2 vdiag = Vector2( pos.x + size.x / 2.f, pos.y - size.y / 2.f ) - vecCenter;
			Vector2 vdiag2 = Vector2( pos.x + size.x / 2.f, pos.y + size.y / 2.f ) - vecCenter;
			float lenDiag = vdiag.length();
			Vector2 vecCircle( pos.x, pos.y - lenDiag );

			Vector2 vecRad = vecCircle - vecCenter;

			float progress = _progress;

			float fP = MATH_PI * 2.f * progress;

			rotateVector( vecRad, fP );

			Vector2 p1(0.f, 0.f);
			Vector2 p2(0.f, 0.f);
			Vector2 p3(0.f, 0.f);

			Vector2 vert( 0.f, -1.f );
			float fA1 = Angle( vdiag, &vert );
			float fA2 = Angle( vdiag2, &vdiag );

			const int MAX_TRI = 6;

			float u1,v1,u2,v2,u3,v3;
			float result = 0.f;

			float angles[ 6 ];
			angles[ 0 ] = fA1;
			angles[ 1 ] = fA2;
			angles[ 2 ] = fA1;
			angles[ 3 ] = fA1;
			angles[ 4 ] = fA2;
			angles[ 5 ] = fA1;

			for ( int i = 0; i < MAX_TRI; i++ )
			{
				float limitLo = 0.f;
				float limitHi = 0.f;
				for (int j = 0; j < i; j++)				
					limitLo += angles[ j ];

				limitHi = limitLo + angles[ i ];

				bool bOverHi = fP > limitHi;
				bool bOverLo = fP < limitLo;
				if ( i && bOverLo )				
					continue;

				vertexPCT2 vertices[4];
				vertexPCT2* pv = vertices;

				switch (i)
				{
				case 0:
					{
						result = bOverHi ? size.x / 2.f : vecRad.x;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x, pos.y - size.y / 2.f);
						p3 = Vector2(pos.x + result, pos.y - size.y / 2.f);
						float fPercent = result / size.x;
						float fDU = du * fPercent;	

						u1 = u;
						v1 = v;
						u2 = u;
						v2 = ( v - dv / 2.f );
						u3 = ( u + fDU );
						v3 = ( v - dv / 2.f );
					}
					break;
				case 1:
					{					
						result = bOverHi ? size.y / 2.f : ( vecRad.y ) ;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x + size.x / 2.f, pos.y - size.y / 2.f);
						p3 = Vector2(pos.x + size.x / 2.f, pos.y + result );
						float fPercent = result /size.y;
						float fDV = dv * fPercent;	

						u2 = u + du / 2.f;
						v2 = ( v - dv / 2.f );
						u3 = u + du / 2.f;
						v3 = ( v + fDV );
					}
					break;
				case 2:
					{					
						result = bOverHi ? 0.f : vecRad.x ;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x + size.x / 2.f, pos.y + size.y / 2.f);
						p3 = Vector2(pos.x + result, pos.y + size.y / 2.f );
						float fPercent = result/size.x;
						float fDU = du * fPercent;	
						
						u2 = u + du / 2.f;
						v2 = ( v + dv / 2.f );
						u3 = u + fDU;
						v3 = ( v + dv / 2.f );
					}
					break;
				case 3:
					{					
						result = bOverHi ? ( -size.x / 2.f ) : vecRad.x ;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x , pos.y + size.y / 2.f);
						p3 = Vector2(pos.x + result, pos.y + size.y / 2.f );
						float fPercent = result / size.x;
						float fDU = du * fPercent;	

						u2 = u;
						v2 = ( v + dv / 2.f );
						u3 = u + fDU;
						v3 = ( v + dv / 2.f );
					}
					break;
				case 4:
					{					
						result = bOverHi ? ( -size.y / 2.f ) : vecRad.y ;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x - ( size.x / 2.f ) , pos.y + size.y / 2.f);
						p3 = Vector2(pos.x - ( size.x / 2.f ), pos.y + result );
						float fPercent = result / size.y;
						float fDV = dv * fPercent;	

						u2 = u - du / 2.f;
						v2 = ( v + dv / 2.f );
						u3 = u - du / 2.f;
						v3 = ( v + fDV );
					}
					break;
				case 5:
					{					
						result = bOverHi ? ( 0.f ) : vecRad.x ;
						p1 = Vector2(pos.x, pos.y);
						p2 = Vector2(pos.x - ( size.x / 2.f ), pos.y - ( size.y / 2.f ));
						p3 = Vector2(pos.x + result, pos.y - ( size.y / 2.f ) );
						float fPercent = result / size.x;
						float fDU = du * fPercent;	

						u2 = u - du / 2.f;
						v2 = ( v - dv / 2.f );
						u3 = u + fDU;
						v3 = ( v - dv / 2.f );
					}
					break;
				default:
					continue;
				}

				u1 = u;
				v1 = v;


				p1 = rs.transform.transform(p1);
				p2 = rs.transform.transform(p2);
				p3 = rs.transform.transform(p3);


				fill_tex_coord(*pv, rgba, p1, u1, v1);
				pv++;
				fill_tex_coord(*pv, rgba, p2, u2, v2);
				pv++;
				fill_tex_coord(*pv, rgba, p3, u3, v3);
				pv++;
				fill_tex_coord(*pv, rgba, p2, u2, v2);			
				pv++;

				rs.renderer->draw(vertices, sizeof(vertices), VERTEX_PCT2);			
			}
		}
	}
Beispiel #19
0
void statisticSource::drawStatisticsImage(QPixmap *img, StatisticsItemList statsList, StatisticsType statsType)
{
	QPainter painter(img);

	StatisticsItemList::iterator it;
	for (it = statsList.begin(); it != statsList.end(); ++it)
	{
		StatisticsItem anItem = *it;

		switch (anItem.type)
		{
		case arrowType:
		{
			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			int x, y;

			// start vector at center of the block
			x = displayRect.left() + displayRect.width() / 2;
			y = displayRect.top() + displayRect.height() / 2;

			QPoint startPoint = QPoint(x, y);

			float vx = anItem.vector[0];
			float vy = anItem.vector[1];

			QPoint arrowBase = QPoint(x + p_internalScaleFactor*vx, y + p_internalScaleFactor*vy);
			QColor arrowColor = anItem.color;
			//arrowColor.setAlpha( arrowColor.alpha()*((float)statsType.alphaFactor / 100.0) );

			QPen arrowPen(arrowColor);
			painter.setPen(arrowPen);
			painter.drawLine(startPoint, arrowBase);

			if (vx == 0 && vy == 0)
			{
				// nothing to draw...
			}
			else
			{
				// draw an arrow
				float nx, ny;

				// TODO: scale arrow head with
				float a = p_internalScaleFactor * 4;    // length of arrow
				float b = p_internalScaleFactor * 2;    // base width of arrow

				float n_abs = sqrtf(vx*vx + vy*vy);
				float vxf = (float)vx / n_abs;
				float vyf = (float)vy / n_abs;

				QPoint arrowTip = arrowBase + QPoint(vxf*a + 0.5, vyf*a + 0.5);

				// arrow head right
				rotateVector((float)-M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetRight = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadRight = arrowBase + offsetRight;

				// arrow head left
				rotateVector((float)M_PI_2, -vx, -vy, nx, ny);
				QPoint offsetLeft = QPoint(nx*b + 0.5, ny*b + 0.5);
				QPoint arrowHeadLeft = arrowBase + offsetLeft;

				// draw arrow head
				QPoint points[3] = { arrowTip, arrowHeadRight, arrowHeadLeft };
				painter.setBrush(arrowColor);
				painter.drawPolygon(points, 3);
			}

			break;
		}
		case blockType:
		{
			//draw a rectangle
			QColor rectColor = anItem.color;
			rectColor.setAlpha(rectColor.alpha()*((float)statsType.alphaFactor / 100.0));
			painter.setBrush(rectColor);

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.fillRect(displayRect, rectColor);

			break;
		}
		}

		// optionally, draw a grid around the region
		if (statsType.renderGrid) {
			//draw a rectangle
			QColor gridColor = anItem.gridColor;
			QPen gridPen(gridColor);
			gridPen.setWidth(1);
			painter.setPen(gridPen);
			painter.setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush));  // no fill color

			QRect aRect = anItem.positionRect;
			QRect displayRect = QRect(aRect.left()*p_internalScaleFactor, aRect.top()*p_internalScaleFactor, aRect.width()*p_internalScaleFactor, aRect.height()*p_internalScaleFactor);

			painter.drawRect(displayRect);
		}
	}
}
Beispiel #20
0
/* Interpret commands from game controller */
void control_pilot (int plr) {
    struct Pilot *pilot = &players[plr].pilot;
    pilot->lock = players[plr].controller.weapon2;
    /* Horizontal axis */
    if (players[plr].controller.axis[1] > 0) {
        /* Walk/glide left */
        if(!pilot->lock)
            pilot->walker.walking = -1;
        if(pilot->attack_vector.x > 0 && pilot->crosshair_color==col_white) {
            pilot->attack_vector.x = -pilot->attack_vector.x;
        }
    } else if (players[plr].controller.axis[1] < 0) {
        /* Walk/glide right */
        if(!pilot->lock)
            pilot->walker.walking = 1;
        if(pilot->attack_vector.x < 0 && pilot->crosshair_color==col_white) {
            pilot->attack_vector.x = -pilot->attack_vector.x;
        }
    } else {
        pilot->walker.walking = 0;
    }
    /* Vertical axis */
    if (players[plr].controller.axis[0] > 0) {
        /* Jump/swim/climb up/aim up/shoot rope at a 45 degree angle */
        if(pilot->lock || pilot->parachuting) {
            rotateVector(&pilot->attack_vector,
                    pilot->attack_vector.x>0?-0.5:0.5);
        } else if(pilot->rope) {
            pilot->ropectrl = -1;
        } else {
            if(pilot->walker.physics.hitground==0 &&
                    pilot->walker.physics.underwater==0 &&
                    pilot->parachuting==0)
            {
                pilot_shoot_rope(pilot,makeVector(pilot->attack_vector.x>0?1:-1,-1));
            } else {
                walker_jump(&pilot->walker);
            }
        }
    } else if (players[plr].controller.axis[0] < 0) {
        /* Swim/climb down, shoot rope straight up/aim down */
        if(pilot->lock || pilot->parachuting) {
            rotateVector(&pilot->attack_vector,pilot->attack_vector.x<0?-0.5:0.5);
        } else if(pilot->rope) {
                pilot->ropectrl = 1;
        } else {
            if(pilot->walker.physics.underwater==0)
                pilot_shoot_rope(pilot,makeVector(0,-1));
            else
                walker_dive(&pilot->walker);
        }
    } else {
        pilot->walker.dive = 0;
        pilot->walker.jump = 0;
        pilot->ropectrl = 0;
    }

    /* Weapon1 button */
    if (players[plr].controller.weapon1) {
        /* Shoot / Board another players ship by force */
#if 0 /* TODO take over ship */
        if (pilot->updown == -1 && pilot->rope_ship
            && abs (pilot->rope_ship->physics.x - Round(pilot->x)) < 8
            && abs (pilot->rope_ship->physics.y - Round(pilot->y) + 4) < 8) {
            int targ = find_player (pilot->rope_ship);
            if (targ < 0)
                return;
            players[plr].ship = pilot->rope_ship;
            pilot->rope_ship = NULL;
            players[targ].ship = NULL;
            players[targ].pilot.x = pilot->x;
            players[targ].pilot.y = pilot->y;
            players[targ].pilot.rope = 0;
            return;
        }
#endif
        if(pilot->weap_cooloff==0)
            pilot_shoot(&players[plr].pilot);
    }

    /* Weapon2 button */
    if (players[plr].controller.weapon2) {
        /* Open parachute / Get off the rope / Recall ship */
        if (pilot->rope)
            pilot_detach_rope(pilot);
        else if (pilot->walker.physics.hitground==0 && pilot->parachuting == 0)
            deploy_parachute(pilot);
        else if (pilot->walker.physics.hitground == TER_BASE &&
                game_settings.recall)
            recall_ship (plr);
    }
}