void
QvisReflectWidget::setupCamera()
{
    // Set the view.
    vector3 camera1 = vec_create(24.2f, 16.5f, 29.7f);

#ifdef DONT_KNOW_THE_VALUES
    // we're debugging
    float r = sqrt(camera1.x * camera1.x + camera1.z * camera1.z);
    float camera1Angle = -acos(camera1.x / r) + 3.14159 / 2.;
    float camera2Angle = camera1Angle + 3.14159;
#else
    // we know the values.
    const float r = 38.309f;
    const float camera1Angle = 0.683708f;
    const float camera2Angle = 3.8253f;
#endif

    float angle = (1. - cameraInterpolant) * camera1Angle + 
                  cameraInterpolant * camera2Angle;

    // figure out x and z using the angle.
    float x = r * cos(angle);
    float z = r * sin(angle);

    vector3 camera = vec_create(x, camera1.y, z);

    matrix4 view = m3du_create_view_matrix(
            camera,
            vec_create(0,-3,0),
            vec_create(0,1,0));
    renderer.set_view_matrix(view);
    renderer.set_view_reference_point(camera);
}
示例#2
0
文件: vec.c 项目: larioj/languages
struct vec *vec_copy(struct vec *v) {
	struct vec *newv = vec_create(v->size);
	for (int i = 0; i < newv->size; i++) {
		newv->element[i] = v->element[i];
	}
	return newv;
}
示例#3
0
文件: vec.c 项目: larioj/languages
struct vec *vec_removeFirstN(struct vec *v, int n) {
	size_t newsize = v->size - n;
	struct vec *newv = vec_create(newsize);
	for (int i = 0; i < newv->size; i++) {
		newv->element[i] = v->element[i +n];
	}
	return newv;
}
示例#4
0
void
rism_rdf (State *dom, Vec g,
          const real a[3],        /* center */
          int n, const real r[n], /* radial mesh */
          int m,                  /* quadrature order */
          real rdf[n])            /* out */
{
  const ProblemData *PD = dom->PD;

  /* Prepare Fourier coefficients.  Only needed for trigonometric
     interpolation: */
  local Vec g_fft = NULL;
  if (!trilinear)
    {
      g_fft = vec_create (dom->dc);

      MatMult (dom->fft_mat, g, g_fft);
      /* Do not VecScale (g_fft, volume_element (PD)), the
         interpolation code assumes that ... */
    }

  /* Coordinates  and weights of  spherical quadrature.  Only mm  <= m
     points are valid: */
  real x[m][3], w[m];

  const int mm = genpts (m, x, w);

  /* (Real) grid coordinates and interpolated values: */
  real y[mm][3], gr[mm];

  /* Over radial layers: */
  for (int j = 0; j < n; j++)
    {
      /* Translate quadrature  coordinates into real  grid coordinates
         where integer values correspond to the grid nodes: */
      for (int i = 0; i < mm; i++)
        FOR_DIM
          y[i][dim] = (a[dim] + r[j] * x[i][dim] + PD->L[dim] / 2) / PD->h[dim];

      /* NOTE:  trigonometric  interpolation   is  O(N^3)  per  point,
         trilinear is O(1): */
      if (trilinear)
        bgy3d_interp (dom->da, g, mm, y, gr);
      else
        bgy3d_fft_interp (dom->fft_mat, g_fft, mm, y, gr);

      /* Scale by integration weights: */
      for (int i = 0; i < mm; i++)
        gr[i] *= w[i];

      /* Integrate over sphere: */
      rdf[j] = sum (mm, gr);
    }

  if (!trilinear)
    vec_destroy (&g_fft);
}
示例#5
0
文件: vec.c 项目: larioj/languages
struct vec *vec_push(struct vec *v, int item) {
	size_t newsize = v->size + 1;
	struct vec *newv = vec_create(newsize);
	for (int i = 0; i < v->size; i++) {
		newv->element[i] = v->element[i];
	}
	newv->element[v->size] = item;
	return newv;
}
示例#6
0
文件: vec.c 项目: larioj/languages
struct vec *vec_removeAtIndex(struct vec *v, int index) {
	struct vec *newv = vec_create(v->size - 1);
	for (int i = 0; i < newv->size; i++) {
		int oldindex = i;
		if (oldindex >= index) {
			oldindex++;
		}
		newv->element[i] = v->element[oldindex];
	}
	return newv;
}
示例#7
0
文件: vec.c 项目: larioj/languages
struct vec *vec_concat(struct vec *lhs, struct vec *rhs) {
	size_t newsize = lhs->size + rhs->size;
	struct vec *v = vec_create(newsize);
	int i;
	for (i = 0; i < lhs->size; i++) {
		v->element[i] = lhs->element[i];
	}
	for (i = 0; i < rhs->size; i++) {
		v->element[i + lhs->size] = rhs->element[i];
	}
	return v;
}
示例#8
0
文件: pp.c 项目: berkus/moto
MotoMacroBuilder *motopp_createMacroBuilder(char *filename) {
   MotoMacroBuilder *mb = emalloc(sizeof(MotoMacroBuilder));   
   
   mb->relative_root 	= motopp_getRelativeRoot(filename);
   mb->filename 	= motopp_getRealPath(filename);

   mb->startline = 1;
   mb->buf = buf_createDefault();
   mb->macros = stab_createDefault();
   mb->args = vec_create(5, (int(*)(const void *, const void *))strcmp);
   
   return mb;
}
void
QvisReflectWidget::redrawScene2D(QPainter *painter)
{
    // Fill in the background color.
    painter->fillRect(rect(), palette().brush(QPalette::Background));

    //
    // Set up the camera.
    //
    vector3 camera = vec_create(0.f, 0.f, 35.f);
    matrix4 view = m3du_create_view_matrix(
            camera,
            vec_create(0.f,0.f,0.f),
            vec_create(0.f,1.f,0.f));
    renderer.set_view_matrix(view);
    renderer.set_view_reference_point(camera);

    // Set up the lights.
    renderer.set_light(1, M3D_LIGHT_AMB, 0.f, 0.f, 0.f, 0.1f, 0.1f, 0.1f);
    renderer.set_light(2, M3D_LIGHT_EYE, -35.f, -35.f, -50.f, 0.7f, 0.7f, 0.7f);
    renderer.begin_scene(painter);
    renderer.set_world_matrix(m3du_create_identity_matrix());

    // Draw the reference axes
    axes2D.addToRenderer(renderer);

    // Draw the on/off actors.
    drawOnOffActors(4, 1.2f);

    // Render the scene
    renderer.end_scene();

    // Draw the Axis labels.
    int h = fontMetrics().height();
    vector3 x0 = renderer.transform_world_point(vec_create(-axes_size, 0, axes_size));
    vector3 x1 = renderer.transform_world_point(vec_create(axes_size, 0, axes_size));
    vector3 y0 = renderer.transform_world_point(vec_create(0, axes_size, axes_size));
    vector3 y1 = renderer.transform_world_point(vec_create(0, -axes_size, axes_size));
    painter->setPen(palette().foreground().color());
    const char *x = "+X";
    painter->drawText((int) x0.x, (int) (x0.y + h), "-X");
    painter->drawText((int) (x1.x - fontMetrics().width(x)), (int) (x1.y + h), x);
    painter->drawText((int) (y0.x + 5), (int) (y0.y + h), "+Y");
    painter->drawText((int) (y1.x + 5), (int) (y1.y), "-Y");
}
示例#10
0
文件: pgrset.c 项目: berkus/moto
//FIXME. NOT TESTED
Vector *
pgrset_getArray(PGResultSet *rset, int column)
{
  Vector *vec = vec_create(pgrset_rows(rset), NULL);
  int cursor;

  pgrset_checkClosed(rset);
  
  //Get current cursor position
  cursor = rset->row;
  rset->row = -1;
  pgrset_checkColumn(rset, &column);
  
  while(pgrset_next(rset))
    vec_add(vec, PQgetvalue(rset->res, rset->row, column));

  //Place cursor back where it was
  rset->row = cursor;

  return vec;
}
示例#11
0
void next_step_cal(FLUX *flux, PCS *pcs, TCONF *tconf, MAPPER *mapper, MESH *mesh, CDAT4 *vsf_lst)
{
	size_t eg_size = mapper->eg_size;
	size_t rt_size = mapper->rt_size;
	CDAT4 *vsf = mesh->vsf;
	FLUX *flux_lst = flux_create(mapper);
	flux_copy(flux_lst, flux);
	CDAT4 *sr_rvs = cdat4_create(mapper);
	sr_rvs_cal(sr_rvs, tconf, mesh);
	MAT *M = mat_create(eg_size*rt_size);
	MAT *S = mat_create(eg_size*rt_size);
	MAT *F = mat_create(eg_size*rt_size);
	EDAT4 *DFDM = edat4_create(mapper);
	EDAT4 *DNOD = edat4_create(mapper);
	cal_DFDM(DFDM, mesh);
	cal_m(M, DFDM, DNOD, mapper, mesh, sr_rvs);
	CDAT4 *chi_bar = cdat4_create(mapper);
	cal_chi_bar(chi_bar, tconf, mesh);
	cal_s(S, mapper, mesh);
	cal_f(F, mapper, mesh, chi_bar);
	mat_adds(M, S, -1.0);
	mat_adds(M, F, -1.0);
	VEC *src_eff = vec_create(eg_size*rt_size);
	src_eff_cal(src_eff,tconf,mesh,vsf_lst,flux_lst,pcs);
	VEC *sol = vec_ref_create(eg_size*rt_size, flux->data);
	(*mat_solver)(sol,M,src_eff,1024);
	vec_ref_free(sol);
	
	pcs_cal(pcs,flux,flux_lst,vsf,vsf_lst,tconf);
	cdat4_free(chi_bar);
	vec_free(src_eff);
	edat4_free(DNOD);
	edat4_free(DFDM);
	mat_free(F);
	mat_free(S);
	mat_free(M);
	cdat4_free(sr_rvs);
	flux_free(flux_lst);
}
示例#12
0
void
QvisReflectWidget::setupAndDraw(QPainter *p)
{
    // Fill in the background color.
    p->fillRect(rect(), palette().brush(QPalette::Background));

    renderer.set_light(1, M3D_LIGHT_EYE, 0.f,0.f,-35.f, 1.f, 1.f, 1.f);
    renderer.set_light(2, M3D_LIGHT_OFF, 0.f,0.f,-1.f, 0.f, 0.f, 0.f);
    renderer.begin_scene(p);
    renderer.set_world_matrix(m3du_create_identity_matrix());

    // Draw the reference axes
    axes.addToRenderer(renderer);

    // Draw the cubes or spheres.
    drawOnOffActors(8, 1.f);

    // If we're not switching cameras, add the arrow to the scene.
    if(!switchingCameras)
    {
        if(activeCamera == 0)
        {
            matrix4 world = mtx_mult(
                m3du_create_scaling_matrix(1., 1., -1.),
                m3du_create_translation_matrix(axes_size + 3, -axes_size,
                    -ARROW_LENGTH * 0.5f));
            renderer.set_world_matrix(world);
            arrow.addToRenderer(renderer, ARROW_ID);
        }
        else
        {
            matrix4 world = mtx_mult(
                m3du_create_scaling_matrix(1., 1., -1.),
                m3du_create_translation_matrix(-axes_size - 3,
                    -axes_size, -ARROW_LENGTH * 0.5));
            renderer.set_world_matrix(world);
            arrow.addToRenderer(renderer, ARROW_ID);
        }
    }

    // Render the scene
    renderer.end_scene();

    // Add some annotation
    if(!switchingCameras)
    {
        int cx = width() / 2;
        int cy = height() / 2;
        int edge = qMin(width(), height());
        QRect square(cx - edge / 2, cy - edge / 2, edge, edge);

        if(activeCamera == 0)
        {
            const char *txt = "Front view";
            p->drawText(square.x() + 5, square.y() + square.height() - 5, txt);

            vector3 p0 = renderer.transform_world_point(vec_create(axes_size, 0, 0));
            vector3 p1 = renderer.transform_world_point(vec_create(0, axes_size, 0));
            vector3 p2 = renderer.transform_world_point(vec_create(0, 0, axes_size));

            p->drawText((int) (p0.x + 5), (int) (p0.y + 5), "+X");
            p->drawText((int) (p1.x), (int) (p1.y - 5), "+Y");
            p->drawText((int) (p2.x - 20), (int) (p2.y + 5), "+Z");
        }
        else
        {
            const char *txt = "Back view";
            p->drawText(square.x() + 5, square.y() + square.height() - 5, txt);

            vector3 p0 = renderer.transform_world_point(vec_create(-axes_size, 0, 0));
            vector3 p1 = renderer.transform_world_point(vec_create(0, axes_size, 0));
            vector3 p2 = renderer.transform_world_point(vec_create(0, 0, -axes_size));

            p->drawText((int) (p0.x + 5), (int) (p0.y + 5), "-X");
            p->drawText((int) (p1.x), (int) (p1.y - 5), "+Y");
            p->drawText((int) (p2.x - 20), (int) (p2.y + 5), "-Z");
        }
    }
}
示例#13
0
文件: stack.c 项目: berkus/moto
Stack *
stack_create(int cap, int (*cfn)(const void *, const void *)) {
	return vec_create(cap,cfn);
}