コード例 #1
0
ファイル: VectorMath.cpp プロジェクト: ESHughes/GameEngine
void vectorNormalize(float* v1)								// changes the magnitude to 1
{
	float mag = vectorMagnitude(v1);
	v1[0]/=mag;
	v1[1]/=mag;
	v1[2]/=mag;
}
void SceneDelegate::animate(float time) {
	shape_[1].rotation.z = cos(time);
	shape_[3].position.z = 3.f + 2.f * abs(cos(0.2f * time) * cos(time));
	light_[0].position = Float3(25.f * cos(time), 25.f * sin(time), 10.f);
	light_[0].direction = scaleVector(light_[0].position,
		-1.f / vectorMagnitude(light_[0].position));
}
コード例 #3
0
Vector Biot_Savart_SingleLineSeg(LineSeg seg,Vector fieldpoint)
{

    Vector result,r,Seg_Cross_r;
    Vector SegMidPoint,SegVector,SegDirection;
    Vector BDirection;
    double SegLength,x,z,constval;
    double Bmag;


    SegMidPoint=linesegCenter(seg);
    SegLength=linesegLength(seg);
    SegVector=linesegVector(seg);
    SegDirection=vectorUnitVector(SegVector);


    r=linesegVector(linesegGenerate(SegMidPoint,fieldpoint));
    Seg_Cross_r=vectorCross(SegVector,r);
    BDirection=vectorUnitVector(Seg_Cross_r);
    z=vectorMagnitude(Seg_Cross_r)/SegLength;
    constval=mu_0/(4*M_PI*z);
    x=vectorDot(SegDirection,r);
    if(z == 0)
    {
	Bmag=0;
    }
    else
    {
	Bmag=constval*((SegLength-2*x)/sqrt((SegLength-2*x)*(SegLength-2*x)+4*z*z)+(SegLength+2*x)/sqrt((SegLength+2*x)*(SegLength+2*x)+4*z*z));
    }
    //printf("Bmag %g\n",Bmag);
    result=vectorScale(BDirection,Bmag);
    //printf("result.x,result.y,result.z %g,%g,%g\n",result.x,result.y,result.z);
    return result;
}
コード例 #4
0
ファイル: SkeletonState.cpp プロジェクト: TACC/DisplayCluster
void SkeletonState::renderLimb(SkeletonPoint& pt1, SkeletonPoint& pt2)
{
    if(pt1.confidence <= 0.5 || pt2.confidence <= 0.5)
        return;

    float a[3] = {pt1.x, pt1.y, pt1.z};
    float b[3] = {pt2.x, pt2.y, pt2.z};

    // vector formed by the two joints
    float c[3];
    vectorSubtraction(a, b, c);

    // glu cylinder vector
    float z[3] = {0,0,1};

    // r is axis of rotation about z
    float r[3];
    vectorCrossProduct(z, c, r);

    // get angle of rotation in degrees
    float angle = 180./M_PI * acos((vectorDotProduct(z, c)/vectorMagnitude(c)));

    glPushMatrix();

    // translate to second joint
    glTranslatef(pt2.x, pt2.y, pt2.z);
    glRotatef(angle, r[0], r[1], r[2]);

    // set up quadric object
    GLUquadricObj* quadObj = gluNewQuadric();

    gluCylinder(quadObj, 10, 10, vectorMagnitude(c), 10, 10);

    glPopMatrix();

    // delete used quadric
    gluDeleteQuadric(quadObj);
}
コード例 #5
0
struct Vector3 vectorNormalise(struct Vector3 in)
{
    int vectorMagnitudeReciprocal = fp_reciprocal(vectorMagnitude(in));

    if (vectorMagnitudeReciprocal>(1<<16))
    {
        struct Vector3 result = {   fp_mult(in.x,vectorMagnitudeReciprocal),
                                    fp_mult(in.y,vectorMagnitudeReciprocal),
                                    fp_mult(in.z,vectorMagnitudeReciprocal) };
        return result;
    }
    else
    {
        struct Vector3 result = {   fp_frac(in.x,vectorMagnitudeReciprocal),
                                    fp_frac(in.y,vectorMagnitudeReciprocal),
                                    fp_frac(in.z,vectorMagnitudeReciprocal) };
        return result;
    }
}
// helper to correct normals and winding order
static void normalizeMesh(bool invertNormals, Mesh* mesh) {

	// unitize normal vectors
	for (std::vector<Float3>::iterator it = mesh->normalArray.begin();
		it != mesh->normalArray.end(); it++) {
			const float length = invertNormals ? -1.f : 1.f * vectorMagnitude(*it);
			*it = scaleVector(*it, 1.f / length);
	}

	// change winding order if necessary
	if (invertNormals) {
		const unsigned int numberOfTriangles = mesh->indexArray.size() / 3;
		for (unsigned int i=0; i<numberOfTriangles; ++i) {
			const unsigned int idx = 3 * i;
			const unsigned int tmp = mesh->indexArray[idx];
			mesh->indexArray[idx] = mesh->indexArray[idx + 1];
			mesh->indexArray[idx + 1] = tmp;
		}
	}
}
コード例 #7
0
ファイル: texture.c プロジェクト: xaphiriron/beyond
void textureDrawLine (TEXTURE t, VECTOR3 start, VECTOR3 end)
{
	VECTOR3
		diff = vectorSubtract (&end, &start),
		norm = vectorNormalize (&diff),
		current = start;
	/* i'm using i/max as a counter since due to floating point rounding error
	 * it's not feasible to use vector_cmp (&current, &end), which is the only
	 * other way i can think of to check for when the line is actually done
	 *  - xph 2011 08 27
	 */
	int
		i = 0,
		max = vectorMagnitude (&diff) + 1;
	/* if start is out of bounds skip ahead until it isn't (if it isn't), and
	 * if it goes out of bounds again then it's not coming back. this is
	 * important if start is out of bounds but end isn't (or if they're both
	 * oob but they cross the image edge at some point); the start of the line
	 * won't be drawn but stopping after the first oob coordiante would be
	 * wrong
	 * (there's a better way to do this: if either value is oob, calculate the
	 * intersection of the line w/ the screen edges and jump to that point
	 * without needing to loop)
	 *  - xph 2011 08 27
	 */
	while (textureOOB (t, current) && i < max)
	{
		current = vectorAdd (&current, &norm);
		i++;
	}
	while (i < max)
	{
		if (textureOOB (t, current))
			break;
		textureDrawPixel (t, current);
		current = vectorAdd (&current, &norm);
		i++;
	}
}
コード例 #8
0
ファイル: rcmnd.c プロジェクト: dwinner/CppAppdev
int performART1( void )
{
  int andresult[MAX_ITEMS];
  int pvec, magPE, magP, magE;
  float result, test;
  int index, done = 0;
  int count = 50;

  while (!done) {

    done = 1;

    for (index = 0 ; index < MAX_CUSTOMERS ; index++) {

#ifdef DEBUG
      printf("\nExample %d (currently in %d)\n", index, membership[index]);
#endif

      /* Step 3 */
      for (pvec = 0 ; pvec < TOTAL_PROTOTYPE_VECTORS ; pvec++) {

        if (members[pvec]) {

#ifdef DEBUG
          printf("Test vector %d (members %d)\n", pvec, members[pvec]);
#endif

          vectorBitwiseAnd( andresult, 
                             &database[index][0], &prototypeVector[pvec][0] );

          magPE = vectorMagnitude( andresult );
          magP  = vectorMagnitude( &prototypeVector[pvec][0] );
          magE  = vectorMagnitude( &database[index][0] );

          result = (float)magPE / (beta + (float)magP);

          test = (float)magE / (beta + (float)MAX_ITEMS);

#ifdef DEBUG
          printf("step 3 : %f > %f ?\n", result, test);
#endif

          if (result > test) {

            /* Test for vigilance acceptability */

#ifdef DEBUG
            printf("step 4 : testing vigilance %f < %f\n", 
                   ((float)magPE/(float)magE), vigilance);
#endif

            if (((float)magPE/(float)magE) < vigilance) {

              int old;

              /* Ensure this is a different cluster */
              if (membership[index] != pvec) {

                old = membership[index];
                membership[index] = pvec;

#ifdef DEBUG
                printf("Moved example %d from cluster %d to %d\n", 
                        index, old, pvec);
#endif

                if (old >= 0) {
                  members[old]--;
                  if (members[old] == 0) numPrototypeVectors--;
                }
                members[pvec]++;

                /* Recalculate the prototype vectors for the old and new 
                 * clusters.
                 */
                if ((old >= 0) && (old < TOTAL_PROTOTYPE_VECTORS)) {
                  updatePrototypeVectors( old );
                }

                updatePrototypeVectors( pvec );

                done = 0;
                break;

              } else {
                /* Already in this cluster */
              }

            } /* vigilance test */

          }

        }

      } /* for vector loop */

      /* Check to see if the current vector was processed */
      if (membership[index] == -1) {
        /* No prototype vector was found to be close to the example 
         * vector.  Create a new prototype vector for this example.
         */
        membership[index] = createNewPrototypeVector( &database[index][0] );
        done = 0;
      }

    } /* customers loop */

#ifdef DEBUG
    printf("\n");
#endif

    if (!count--) break;

  } /* !done */

  return 0;
}