Exemplo n.º 1
0
static void write_joint_with_updates(FILE *p3dfile, joint *jointPt, int indref)
{
  double *a1pos,*a2pos,*a3pos,*a4pos;
  double posdiff[3],axis1[3],axis2[3],axis3[3];
  double dihedang;
  char   jname[255];
  char   cadchar[255];

  a1pos = jointPt->atomsindihedral[0]->pos;
  a2pos = jointPt->atomsindihedral[1]->pos;
  a3pos = jointPt->atomsindihedral[2]->pos;
  a4pos = jointPt->atomsindihedral[3]->pos;

  vectSub(a3pos,a2pos,posdiff);
  vectNormalize(posdiff,axis2);
  vectSub(a2pos,a1pos,posdiff);
  vectNormalize(posdiff,axis1);
  vectSub(a4pos,a3pos,posdiff);
  vectNormalize(posdiff,axis3);

  dihedang = compute_dihedang(axis3,axis2,axis1);

  // update global_indJ
  global_indJ++;

  strcpy(jname,"theta.LIG");
  sprintf(cadchar,".%d",global_indJ);
  strcat(jname,cadchar);
  sprintf(cadchar,".%d-%d-%d-%d",
	  jointPt->atomsindihedral[0]->serial,jointPt->atomsindihedral[1]->serial,
	  jointPt->atomsindihedral[2]->serial,jointPt->atomsindihedral[3]->serial);
  strcat(jname,cadchar);

  write_joint(jname,global_indJ,indref,a3pos,axis2,dihedang,dihedang,jointPt->vmin,jointPt->vmax);
}
Exemplo n.º 2
0
void moveCamera(float forward_dist, float right_dist, float up_dist)
{
    Point3f right_vec = vectNormalize(vectMul(camera_target, up));
    Point3f up_vec = vectNormalize(vectMul(right_vec, camera_target));

    camera_pos = vectMulScalar(camera_pos, camera_target, forward_dist * camera_speed);
    camera_pos = vectMulScalar(camera_pos, right_vec, right_dist * camera_speed);
    camera_pos = vectMulScalar(camera_pos, up_vec, up_dist * camera_speed);
}
Exemplo n.º 3
0
static int same_sign_vect(double *v1, double *v2)
{
  double v1n[3],v2n[3];

  vectNormalize(v1,v1n);
  vectNormalize(v2,v2n);
  if(vectDotProd(v1n,v2n) > 0.0)
    return 1;
  else
    return 0;
}
Exemplo n.º 4
0
static void normalized_vectXprod(double *a, double *b, double *c)
{
  double nnc[3];

  nnc[0] = a[1] * b[2] - a[2] * b[1];
  nnc[1] = a[2] * b[0] - a[0] * b[2];
  nnc[2] = a[0] * b[1] - a[1] * b[0];

  vectNormalize(nnc,c);
}
Exemplo n.º 5
0
static Vector3D	areaLightGetDirection(AreaLightClass *self,
                                      HitRecordStruct *hitRecord)
{
  Vector3D	samplePoint;

  samplePoint = areaLightGetSampleThreadsafe(self);
  PRIV(normal) = PRIV(mObject)->getNormal(PRIV(mObject), &samplePoint);
  PRIV(wi) = samplePoint;
  vectOpMinus(&PRIV(wi), &hitRecord->hitPoint);
  vectNormalize(&PRIV(wi));
  return (PRIV(wi));
}
Exemplo n.º 6
0
void captureOctTree(Point3f camera, Point3f target, Point3f up, int width, int height, float *data)
{
    //normalize vectors
    target = vectNormalize(target);
    up = vectNormalize(up);

    Point3f right = vectNormalize(vectMul(target, up));
    Point3f relative_up = vectNormalize(vectMul(right, camera_target));

    target = vectDiv(target, tanf(AOV / 2.f));
    Point3f bottom_left_vec = vectSum(target, vectDiv(relative_up, -2), vectDiv(right, -2));

    Point3f dright = vectDiv(right, (float)width);
    Point3f dup = vectDiv(relative_up, (float)height);

    cl_int status;

    status = clEnqueueAcquireGLObjects(queue, 1, &image, 0, NULL, NULL);
    check_cl(status, "enqueue gl");

    // find the camera
    Point3f origin = camera;
    OctTreeNode *tree = mainOctTree;
    int dx, dy, dz;
    float radius = 1.f;
    Point3f center = (Point3f) { 0.f, 0.f, 0.f };
    Point3f local = vectMulScalar(origin, center, -1);
    cl_int offset = 0;
    while (tree->type >= 0) {
        dx = local.x > 0;
        dy = local.y > 0;
        dz = local.z > 0;
        offset = tree->nodes[dx][dy][dz];
        tree = mainOctTree + offset;

        radius /= 2.f;
        center = (Point3f) {
            center.x + (2 * dx - 1) * radius,
            center.y + (2 * dy - 1) * radius,
            center.z + (2 * dz - 1) * radius
        };

        local = vectMulScalar(origin, center, -1);
    }

    Point3f camera111 = vectMulScalar(origin, (Point3f) { 1.f, 1.f, 1.f }, 1.f);
    Point3f light111 = vectMulScalar(light, (Point3f) { 1.f, 1.f, 1.f }, 1.f);

    // cl_float3 is bigger than Point3f but we're only passing stack-allocated stuff, so reading garbage is safe
    status = clSetKernelArg(kernel, 0, sizeof(cl_float3), &camera111);
    check_cl(status, "set arg 0");
    status = clSetKernelArg(kernel, 1, sizeof(cl_float3), &light111);
    check_cl(status, "set arg 1");
    status = clSetKernelArg(kernel, 2, sizeof(cl_float3), &bottom_left_vec);
    check_cl(status, "set arg 2");
    status = clSetKernelArg(kernel, 3, sizeof(cl_float3), &dup);
    check_cl(status, "set arg 3");
    status = clSetKernelArg(kernel, 4, sizeof(cl_float3), &dright);
    check_cl(status, "set arg 4");
    status = clSetKernelArg(kernel, 5, sizeof(cl_mem), &mainOctCL);
    check_cl(status, "set arg 5");
    status = clSetKernelArg(kernel, 6, sizeof(cl_mem), &image);
    check_cl(status, "set arg 6");
    status = clSetKernelArg(kernel, 7, sizeof(cl_int), &offset);
    check_cl(status, "set arg 7");

    // run kernel
    size_t global_work_size[] = {width, height};
    size_t local_work_size[] = {8, 8};
    status = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, NULL);
    check_cl(status, "enqueue kernel");

    status = clEnqueueReleaseGLObjects(queue, 1, &image, 0, NULL, NULL);
    check_cl(status, "release gl");

    status = clFinish(queue);
    check_cl(status, "finish");

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);

    glBegin(GL_QUADS);
    glTexCoord2i(0, 1);
    glVertex2f(-1, 1.0f);
    glTexCoord2i(1, 1);
    glVertex2f(1.0f, 1.0f);
    glTexCoord2i(1, 0);
    glVertex2f(1.0f, -1.f);
    glTexCoord2i(0, 0);
    glVertex2f(-1, -1.f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glFinish();
}
Exemplo n.º 7
0
void Game::manageInputs() {
    // Player 1
    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
        _p1.setVelocity(_p1.velocity().x, -1);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        _p1.setVelocity(-1, _p1.velocity().y);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        _p1.setVelocity(1, _p1.velocity().y);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
        _p1.setVelocity(_p1.velocity().x, 1);
    }

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
        _p1.boost();
    } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) == false) {
        _p1.chargeBoost();
    }

    if(_nbPlayer == 2) {
        // Player 2
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
            _p2.setVelocity(_p2.velocity().x, -1);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
            _p2.setVelocity(-1, _p2.velocity().y);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
            _p2.setVelocity(1, _p2.velocity().y);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
            _p2.setVelocity(_p2.velocity().x, 1);
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift)) {
            _p2.boost();

        } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) == false) {
            _p2.chargeBoost();
        }

    } else { // Sinon, c'est une ia

        if(_iaUpdateClock.getElapsedTime().asSeconds() >= 0.25f) {
            sf::Vector2f dep = _ball.extrapolatedPosition() - _p2.position();
            float dist = distance(_p2.position().x, _p2.position().y, _ball.extrapolatedPosition().x, _ball.extrapolatedPosition().y);

            dep/=dist;

            _p2.setVelocity(dep);
            _iaUpdateClock.restart();
            _oldDep = dep;

        } else {
            _p2.setVelocity(_oldDep);
        }

        sf::Vector2f p1_ball, p2_ball;

        p1_ball = _ball.position() - _p1.position();

        p2_ball = _ball.position() - _p2.position();

        if(vectDotProduct(_goal2.position() - _ball.position(), _ball.velocity()) > 0
           && _ball.position().x - 30 < _p2.position().x && _ball.position().x >= 50 && vectLength(_ball.velocity()) != 0) {
            _p2.setVelocity(vectNormalize(_goal2.position() - _p2.position()));
        } else if(_ball.position().x < 50) {
            _p2.setVelocity(_oldDep);
        }
        // ==========================================

        if(_p2.boostValue() > 0 && _boostP2 && distance(_p2.position(), _ball.position()) > 100)
            _p2.boost();
        else
            _p2.chargeBoost();

        if(_p2.boostValue() <= 0 && _boostP2) {
            _boostP2 = false;
        }

        if(_boostP2 == false && _p2.boostValue() == 100) {
            _boostP2 = true;
        }
    }
}