コード例 #1
0
void calcNewTarget(float newTarget[], float target[]) {
    float magMe, meToTarget[3], normal[3], theta, rotationMatrix[3][3], test1[3], test2[3];
    magMe = mathVecMagnitude(me, 3);
    mathVecSubtract(meToTarget, target, me, 3);
    mathVecCross(normal, me, meToTarget);
    // normal to the plane containing Me, target, and origin
    mathVecNormalize(normal, 3);
    // normalize the normal
    theta = asinf((0.33 - minDistanceFromOrigin(target)) / sqrtf(magMe * magMe - 0.33 * 0.33));
    // angle between meToTarget and "me to tangent point"
    DEBUG(("theta = %f radians\n", theta)); // THIS IS THE ERROR!!!
    mathVecRotate(rotationMatrix, normal, theta);
    DEBUG(("rotationMatrix = {{%f, %f, %f}, {%f, %f, %f}, {%f, %f, %f}}\n", 
    rotationMatrix[0][0], rotationMatrix[0][1], rotationMatrix[0][2], 
    rotationMatrix[1][0], rotationMatrix[1][1], rotationMatrix[1][2],
    rotationMatrix[2][0], rotationMatrix[2][1], rotationMatrix[2][2]));
    // creates the rotation matrix about the normal by an angle of theta
    mathMatVecMult(test1, rotationMatrix, meToTarget);
    // rotates meToTarget by an angle theta
    mathVecAdd(test1, test1, me, 3);
    mathVecRotate(rotationMatrix, normal, -theta);
    // creates the rotation matrix about the normal by the opposite angle
    mathMatVecMult(test2, rotationMatrix, meToTarget);
    // rotates meToTarget by an angle theta
    mathVecAdd(test2, test2, me, 3);
    if (minDistanceFromOrigin(test1) > 0.32) {
        for (int i = 0; i < 3; i++) newTarget[i] = test1[i];
    }
    else {
        for (int i = 0; i < 3; i++) newTarget[i] = test2[i];
    }
}
コード例 #2
0
ファイル: finals.c プロジェクト: fgiobergia/ZeroRobotics
static int revDir (float state[12], float c[3])
{
//BEGIN::PROC::revDir
/*
 * revDir () returns a value
 * between -1, 0 and 1:
 * if 0 is returned, our
 * opponent is not revolving,
 * otherwise the number returned
 * is related to the direction
 * of the revolving (clockwise
 * or counterclockwise)
 */
float asse[3];
float direction[3];
float result[3];
float directionAsteroid[3];
PgetAsteroidNormal(asse);
mathVecCross(direction, state+3, asse);
mathVecNormalize(direction,3);
mathVecSubtract(directionAsteroid, c, state,3);
mathVecNormalize(directionAsteroid,3);
mathVecAdd(result, direction, directionAsteroid,3);
if(mathVecMagnitude(result, 3) > 1.85) {
	return 1;
}
else if(mathVecMagnitude(result, 3) < 0.15){
	return -1;
}
else
	return 0;
//END::PROC::revDir
}
コード例 #3
0
void moveTo(float target[3]){
    float cross[3]; 
    float sub[3];
    float o = zrstate[0] * target[0] + zrstate[1] * target[1] + zrstate[2] * target[2];
    mathVecCross(cross,zrstate,target);
    mathVecSubtract(sub,zrstate,target,3);
    float d = mathVecMagnitude(cross,3) / mathVecMagnitude(sub,3);
    if (d > 0.33 || o > 0.1){ //change o > _ to get difference tolerances
        api.setPositionTarget(target);
    }else{
        float tmp[3];
        float loc[3];
        loc[0] = zrstate[0];
        loc[1] = zrstate[1];
        loc[2] = zrstate[2];
        //mathVecAdd(tmp,target,?,3);
        findTangPoint(tmp,loc,target,0.33);
        DEBUG(("COLLISION COURSE -> NEW COURSE (%f, %f, %f)\n",tmp[0],tmp[1],tmp[2]));
        mathVecNormalize(sub,3);
        int i = 0;
        for (;i < 3;i++){
            sub[i] = 0.2 * sub[i];
        }
        mathVecAdd(tmp,tmp,sub,3);
        api.setPositionTarget(tmp);
    }
}
コード例 #4
0
float minDistanceIfDilated(float p1[], float p2[]) {
    //returns the smallest possible distance between p2 and a dilation of p1
    //this is actually just the distance from a point to a line in 3-space
    float cross[3];
    mathVecCross(cross,p2,p1);
    if (mathVecMagnitude(p1,3) / 10 == 0) {
        DEBUG(("DIVISION BY ZERO WHILE DILATING!"));
    }
    return mathVecMagnitude(cross,3) / mathVecMagnitude(p1,3);
}