示例#1
0
static void ENTITY_ComputeMinMaxNode(scene_node_t * node) {
    unsigned int i;

    /* Figure out the min/max if it's a mesh */
    if (node->type == NODE_TYPE_STATIC_MESH) {
        ENTITY_ComputeMinMaxMesh(node->object.mesh);

        node->bounding_box.min[0] = node->object.mesh->bounding_box.min[0];
        node->bounding_box.min[1] = node->object.mesh->bounding_box.min[1];
        node->bounding_box.min[2] = node->object.mesh->bounding_box.min[2];

        node->bounding_box.max[0] = node->object.mesh->bounding_box.max[0];
        node->bounding_box.max[1] = node->object.mesh->bounding_box.max[1];
        node->bounding_box.max[2] = node->object.mesh->bounding_box.max[2];
    } else {
        /* Reset self */
        vectorSet(node->bounding_box.min, 0, 0, 0);
        vectorSet(node->bounding_box.max, 0, 0, 0);
    }

    /* Compute child first */
    for (i = 0; i < node->num_children; i++) {
        ENTITY_ComputeMinMaxNode(node->child[i]);

        node->bounding_box.min[0] = MIN(node->bounding_box.min[0], node->child[i]->bounding_box.min[0]);
        node->bounding_box.min[1] = MIN(node->bounding_box.min[1], node->child[i]->bounding_box.min[1]);
        node->bounding_box.min[2] = MIN(node->bounding_box.min[2], node->child[i]->bounding_box.min[2]);

        node->bounding_box.max[0] = MAX(node->bounding_box.max[0], node->child[i]->bounding_box.max[0]);
        node->bounding_box.max[1] = MAX(node->bounding_box.max[1], node->child[i]->bounding_box.max[1]);
        node->bounding_box.max[2] = MAX(node->bounding_box.max[2], node->child[i]->bounding_box.max[2]);
    }
}
示例#2
0
void Camera::reset(void){
	cameraSpeed = 0.005f;
	cameraTurnSpeed = 0.01f;
	vectorSet(position, 0.764331460f, -1.66760659f, 0.642456770);
	vectorSet(forwardVec, -0.398769796f, 0.763009906f, -0.508720219f);
	vectorSet(rightVec, 0.886262059f, 0.463184059f, 0.000000000f);
	vectorSet(upVec, -0.235630989f, 0.450859368f, 0.860931039f);
}
示例#3
0
/*--------------------------------------------------------------------*/
static MATRIX uFromAngles(double om, double sgu, double sgl){
  MATRIX u;

  u = makeVector();
  if(u == NULL){
    return NULL;
  }
  vectorSet(u,0,-Cosd(sgl)*Cosd(om));
  vectorSet(u,1,Cosd(sgu)*Sind(om) - Sind(sgu)*Sind(sgl)*Cosd(om));
  vectorSet(u,2,-Sind(sgu)*Sind(om) - Cosd(sgu)*Sind(sgl)*Cosd(om));
  
  return u;	    
}
示例#4
0
/*-----------------------------------------------------------------------------*/
static MATRIX tasReflectionToQC(tasQEPosition r, MATRIX UB){
  MATRIX Q, QC;

  Q = makeVector();
  if(Q == NULL){
    return NULL;
  }
  vectorSet(Q,0,r.qh);
  vectorSet(Q,1,r.qk);
  vectorSet(Q,2,r.ql);
  QC = mat_mul(UB,Q);
  killVector(Q);
  return QC;
}
示例#5
0
/*==================== reciprocal space ==============================*/
static MATRIX tasReflectionToHC(tasQEPosition r, MATRIX B){
  MATRIX h = NULL, hc = NULL;

  h = makeVector();
  if(h == NULL){
    return NULL;
  }
  vectorSet(h,0,r.qh);
  vectorSet(h,1,r.qk);
  vectorSet(h,2,r.ql);

  hc = mat_mul(B,h);
  killVector(h);
  return hc;
}
示例#6
0
//*************************************************************************************************
// Vector suite
//*************************************************************************************************
void vectorSuite(SUINT& errors, SUINT& tests)
{
	errors += vectorInit(tests);
	errors += vectorSet(tests);
	TestVectorCompareEqual(errors, tests);
	TestVectorCompareNotEqual(errors, tests);
}
示例#7
0
static void ENTITY_ComputeMinMaxMesh(mesh_t * mesh) {
    unsigned int i;

    vectorSet(mesh->bounding_box.max, 0, 0, 0);
    vectorSet(mesh->bounding_box.min, 0, 0, 0);

    for (i = 0; i < mesh->num_verticies; i++) {
        mesh->bounding_box.min[0] = MIN(mesh->bounding_box.min[0], mesh->vertices[i].position[0]);
        mesh->bounding_box.min[1] = MIN(mesh->bounding_box.min[1], mesh->vertices[i].position[1]);
        mesh->bounding_box.min[2] = MIN(mesh->bounding_box.min[2], mesh->vertices[i].position[2]);

        mesh->bounding_box.max[0] = MAX(mesh->bounding_box.max[0], mesh->vertices[i].position[0]);
        mesh->bounding_box.max[1] = MAX(mesh->bounding_box.max[1], mesh->vertices[i].position[1]);
        mesh->bounding_box.max[2] = MAX(mesh->bounding_box.max[2], mesh->vertices[i].position[2]);
    }
}
示例#8
0
void Mesh::createVertexnormals(void) {
  int i, j, ii;
  bool connect;
  float normal[3];
  for (i = 0; i < vertexcount; i++) {
    bool found = false;
    vectorSet(normal, 0, 0, 0);
    for (j = 0; j < polygoncount; j++) {
      connect = false;
      class Polygon *polygon = &polygons[j];
      for (ii = 0; ii < polygon->vertexcount; ii++) {
        if (polygons[j].vertices[ii] == &(vertices[i])) {
          connect = true;
        }
      }
      if (connect) {
        vectorAdd(normal, polygon->planenormal);
        found = true;
      }
    }
    if (found) {
      vectorNormalize(vertices[i].normal, normal);
    }
  }
  for (j = 0; j < polygoncount; j++) {
    class Polygon *polygon = &polygons[j];
    if (!polygon->realsmooth)
      polygon->smooth = true;
  }
}
示例#9
0
文件: vector.c 项目: doniexun/fcc
void* vectorRemoveReorder (vector* v, int n) {
    if (v->length <= n)
        return 0;

    void* last = vectorPop(v);
    vectorSet(v, n, last);
    return last;
}
示例#10
0
文件: vector.c 项目: Voroz/Ordlista
void vectorRemove(Vector *pVector, int index){
	#ifdef DEBUG_ON
		// Check if out of bounds
		if (index < 0 || index >= pVector->size){
			printf("'vectorRemove' - Index %d is out of bounds for vector of size %d\n", index, pVector->size);
		}
	#endif
	// Check usage and halves vector if usage is <= 50%
	vectorHalfCapacityIfNotUsed(pVector);

	// Remove value att index position
	vectorFreeValue(pVector->data[index]);
	// Move all values whos index is larger than 'index' one lower (element 4 becomes 5, 5 becomes 6, and so on)
	for (int i = index; i < (pVector->size - 1); i++){
		vectorSet(pVector, i, pVector->data[i + 1]);
	}
	// Decrement vector->size and set last value to NULL
	vectorSet(pVector, (pVector->size--), NULL);
}
示例#11
0
文件: vector.c 项目: Voroz/Ordlista
//
// Moves all values one step higer from index position and inserts the new value at index
//
void vectorInsert(Vector *pVector, int index, void* *value, int sizeOfElem){
	#ifdef DEBUG_ON
		// Check if out of bounds
		if (index < 0 || index >= pVector->size){
			printf("'vectorInsert' - Index %d is out of bounds for vector of size %d\n", index, pVector->size);
		}
	#endif
	// Make the vector one element larger to make room for the new value
	pVector->size++;
	vectorDoubleCapacityIfFull(pVector);

	// Move all values whos index is larger than 'index' one higher (element 5 becomes 4, 4 becomes 3, and so on)
	for (int i = (pVector->size - 1); i > index; i--){
		vectorSet(pVector, i, pVector->data[i - 1]);
	}
	// Save the value at a new adress
	void* ptr = vectorCopyValue(value, sizeOfElem);

	// Save the new adress in the vector
	vectorSet(pVector, index, ptr);
}
示例#12
0
Vertex::Vertex(void) {
  vectorSet(position, 0, 0, 0);
  vectorSet(normal, 0, 0, 0);
}
示例#13
0
Vertex::Vertex(float x, float y, float z, float nx, float ny, float nz) {
  vectorSet(position, x, y, z);
  vectorSet(normal, nx, ny, nz);
}
示例#14
0
bool MeshShape::checkCollisionPeer(MeshShape *target) {
  float normal[3];
  float contactpoint[3];

  bool collided = false;

  int i;

  Mesh *sourcemesh, *targetmesh;

  sourcemesh = this->mesh;
  targetmesh = target->mesh;
  for (i = 0; i < sourcemesh->vertexcount; i++) {
    Vertex *vertex = &sourcemesh->vertices[i];
    float vertexposition[3];
    object->transformPoint(vertexposition, vertex->position);
    target->object->unTransformPoint(vertexposition, vertexposition);

    if (checkPointMeshCollision(vertexposition, targetmesh, normal,
                                contactpoint)) {
      target->object->transformVector(normal, normal);
      target->object->transformPoint(contactpoint, contactpoint);

      if (vectorIsZero(contactpoint)) {
        vectorSet(contactpoint, 0, 0, 0);
      }
      addCollision(object, target->object, normal, contactpoint);
      collided = true;
    }
  }

  sourcemesh = target->mesh;
  targetmesh = this->mesh;
  for (i = 0; i < sourcemesh->vertexcount; i++) {
    Vertex *vertex = &sourcemesh->vertices[i];
    float vertexposition[3];
    target->object->transformPoint(vertexposition, vertex->position);
    object->unTransformPoint(vertexposition, vertexposition);

    if (checkPointMeshCollision(vertexposition, targetmesh, normal,
                                contactpoint)) {
      object->transformVector(normal, normal);
      object->transformPoint(contactpoint, contactpoint);

      addCollision(target->object, object, normal, contactpoint);
      collided = true;
    }
  }

  sourcemesh = this->mesh;
  targetmesh = target->mesh;
  for (i = 0; i < sourcemesh->edgecount; i++) {
    Edge *edge = &sourcemesh->edges[i];
    float v1[3], v2[3];
    object->transformPoint(v1, edge->v1->position);
    target->object->unTransformPoint(v1, v1);

    object->transformPoint(v2, edge->v2->position);
    target->object->unTransformPoint(v2, v2);

    if (checkEdgeMeshCollision(v1, v2, targetmesh, normal, contactpoint)) {
      target->object->transformVector(normal, normal);
      target->object->transformPoint(contactpoint, contactpoint);

      addCollision(object, target->object, normal, contactpoint);
      collided = true;
    }
  }

  return collided;
}
示例#15
0
void        vectorDeletePos(vector_t *vec, size_t pos)
{
    vectorSet(vec, pos, NONE_VALUE, P_NONE);
}
示例#16
0
Vertex::Vertex(float x, float y, float z) {
  vectorSet(position, x, y, z);
  vectorSet(normal, x, y, z);
  vectorNormalize(normal);
}
示例#17
0
bool handleCollision(Contact *contact) {
  Object *source = contact->object1;
  Object *target = contact->object2;
  float *normal = contact->normal;
  float *contactpoint = contact->position;

  float sourcevelocity[3], targetvelocity[3];
  float sourcecontactpoint[3], targetcontactpoint[3];

  vectorSub(sourcecontactpoint, contactpoint, source->position);
  source->getVelocity(sourcevelocity, sourcecontactpoint);

  if (target == NULL) {
    vectorSet(targetcontactpoint, 0, 0, 0);
    vectorSet(targetvelocity, 0, 0, 0);
  } else {
    vectorSub(targetcontactpoint, contactpoint, target->position);
    target->getVelocity(targetvelocity, targetcontactpoint);
  }

  float deltavelocity[3];
  vectorSub(deltavelocity, sourcevelocity, targetvelocity);
  float dot = vectorDot(deltavelocity, normal);

  // if (fabs(dot) < EPSILON) return false;
  // if (dot > -1.0e-5 && dot < 1.0e-5) return false;
  // if (dot >= 0) return false;
  if (dot > -1.0e-5)
    return false;

  float invmass1;
  invmass1 = source->invmass;

  float invmass2;
  if (target == NULL)
    invmass2 = 0;
  else
    invmass2 = target->invmass;

  float t1;
  if (source->invmomentofinertia == 0) {
    t1 = 0;
  } else {
    float v1[3];
    vectorCross(v1, sourcecontactpoint, normal);
    vectorScale(v1, source->invmomentofinertia);
    float w1[3];
    vectorCross(w1, v1, sourcecontactpoint);
    t1 = vectorDot(normal, w1);
  }

  float t2;
  if (target == NULL || target->invmomentofinertia == 0) {
    t2 = 0;
  } else {
    float v1[3];
    vectorCross(v1, targetcontactpoint, normal);
    vectorScale(v1, target->invmomentofinertia);
    float w1[3];
    vectorCross(w1, v1, targetcontactpoint);
    t2 = vectorDot(normal, w1);
  }

  float denominator = invmass1 + invmass2 + t1 + t2;

  float e = 1.0 - COLLISIONFRICTION;

  float impulsesize = (1 + e) * dot / denominator;

  // printf("%f\n", impulsesize);

  float impulse[3];
  vectorScale(impulse, normal, impulsesize);

  float friction[3];
  vectorScale(friction, normal, vectorDot(deltavelocity, normal));
  vectorAdd(friction, deltavelocity);
  vectorNormalize(friction);
  float frictionsize = 10 * KINETICFRICTION * dot / denominator;
  float maxfrictionsize = 0.1 * vectorLength(deltavelocity);
  if (frictionsize < -maxfrictionsize)
    frictionsize = -maxfrictionsize;
  vectorScale(friction, -frictionsize);
  vectorAdd(impulse, friction);

  if (target != NULL) {
    target->addImpulse(impulse, targetcontactpoint);
    target->calculateStateVariables();
  }

  float speed;
  float speed2[3];

  if (target != NULL && source != NULL) {
    // float kvel[3];
    // source->getVelocity(kvel);
    float k = vectorLength(sourcevelocity) * 0.1;
    // if (k > 1) k = 1;
    speed = -impulsesize * target->invmass * k;
    vectorScale(speed2, impulse, target->invmass * k);
    /*float kvel[3];
        source->getVelocity(kvel);
        float k = 0;//vectorDot(speed2, kvel);
        if (k < EPSILON) k = 0;
        speed *= k;
        vectorScale(speed2, k);
        if (k > 0) */ target->hitForce(speed, speed2, source);
  }

  vectorScale(impulse, -1);
  source->addImpulse(impulse, sourcecontactpoint);
  source->calculateStateVariables();

  // vectorScale(speed, source->invmass);
  if (target != NULL && source != NULL) {
    // float kvel[3];
    // target->getVelocity(kvel);
    float k = vectorLength(targetvelocity) * 0.1;
    // if (k > 1) k = 1;
    speed = -impulsesize * source->invmass * k;
    vectorScale(speed2, impulse, source->invmass * k);
    /*float kvel[3];
        target->getVelocity(kvel);
        float k = 0;//vectorDot(speed2, kvel);
        if (k < EPSILON) k = 0;
        speed *= k;
        vectorScale(speed2, k);
        if (k > 0) */ source->hitForce(speed, speed2, target);
  }

  return true;
}