当前位置: 首页>>代码示例>>C++>>正文


C++ Vec::normalize方法代码示例

本文整理汇总了C++中Vec::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec::normalize方法的具体用法?C++ Vec::normalize怎么用?C++ Vec::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vec的用法示例。


在下文中一共展示了Vec::normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: VECPRODUCT

void
ClipPlanes::drawOtherSlicesInViewport(QGLViewer *viewer, int ic)
{
  Vec voxelScaling = Global::voxelScaling();
  Vec pos = m_clips[ic]->position();
  Vec cxaxis = m_clips[ic]->m_xaxis;
  cxaxis = VECPRODUCT(cxaxis, voxelScaling);
  cxaxis.normalize();
  Vec cyaxis = m_clips[ic]->m_yaxis;
  cyaxis = VECPRODUCT(cyaxis, voxelScaling);
  cyaxis.normalize();
  Vec cnormal = m_clips[ic]->m_tang;
  cnormal = VECPRODUCT(cnormal, voxelScaling);
  cnormal.normalize();

  float aspectRatio = viewer->aspectRatio(); 
  float cdist = 2*viewer->sceneRadius()/m_clips[ic]->viewportScale(); 
  float fov = viewer->camera()->fieldOfView(); 
  float yf = cdist*tan(fov*0.5); 
  float xf = yf*aspectRatio;

  Vec vc[4];
  vc[0] = pos - xf*cxaxis - yf*cyaxis;
  vc[1] = pos + xf*cxaxis - yf*cyaxis;
  vc[2] = pos - xf*cxaxis + yf*cyaxis;
  vc[3] = pos + xf*cxaxis + yf*cyaxis;

  if (m_clips[ic]->showOtherSlice())
    {
      glColor4f(0.5, 0.5, 0.5, 0.8);
      for (int tic=0; tic<m_clips.count(); tic++)
	{
	  if (tic != ic)
	    {
	      Vec postic = m_clips[tic]->position();
	      Vec cnormaltic = m_clips[tic]->m_tang;
	      cnormaltic = VECPRODUCT(cnormaltic, voxelScaling);
	      cnormaltic.normalize();
	      int thickness = m_clips[tic]->thickness();
	      Vec cc = m_clips[tic]->color();

	      glLineWidth(3);
	      glColor4f(cc.x*0.5, cc.y*0.5, cc.z*0.5, 0.5);
	      drawViewportIntersections(postic-thickness*cnormaltic, cnormaltic, vc);

	      glLineWidth(2);
	      glColor4f(cc.x*0.7, cc.y*0.7, cc.z*0.7, 0.7);
	      drawViewportIntersections(postic, cnormaltic, vc);

	      glLineWidth(1);
	      glColor4f(cc.x*0.5, cc.y*0.5, cc.z*0.5, 0.5);
	      drawViewportIntersections(postic+thickness*cnormaltic, cnormaltic, vc);
	    }
	}
    }
}
开发者ID:mdoube,项目名称:drishti,代码行数:56,代码来源:clipplane.cpp

示例2: reflect

/** Cast reflected ray
 ** @param ray incoming ray
 ** @param pt intersection point
 ** @param normal normal of pt
 ** @return reflected ray
 **/
Ray reflect(Ray ray, Vec pt, Vec normal){
  Vec v = ray.getOrig() - pt; v = v.normalize();
  Vec dir = normal * (2 * v.dot(normal)) - v; dir = dir.normalize(); // reflected direction
  Ray t(pt, dir, 0, 9999, ReflectedRay);
  if (debugMode) {
    printf("reflected ray: origin = "); t.getOrig().print();
    printf("reflected ray: direction = "); t.getDir().print();
  }
  return t;
}
开发者ID:jacyxli,项目名称:ray-tracer,代码行数:16,代码来源:main.cpp

示例3: calcPlayerObjAngle

	Angle Client::calcPlayerObjAngle(Vec2<int> mouseScreenPos)
	{
		if (worldModel.getPlayerObjs().exists(playerId))
		{
			PlayerObj *playerObj = (worldModel.getPlayerObjs())[playerId];

			float angle;
			Pos mousePos(viewportHandler.screenToGame(worldRenderer.getRenderArea(playerObj), mouseScreenPos));
			Vec aimVec = mousePos - playerObj->pos;
			aimVec.normalize();
			if ((aimVec.x > 0.5) || (aimVec.x < 0.5f))
			{
				angle = asin(aimVec.y);
				if (aimVec.x < 0.0f) angle = PI_F - angle;
			}
			else
			{
				angle = acos(aimVec.x);
				if (aimVec.y < 0.0f) angle = -angle;
			}

			return angle;
		}
		
		return 0.0f;
	}
开发者ID:southor,项目名称:planet,代码行数:26,代码来源:Client.cpp

示例4: RT_lights

//alg for calculating shading. Calls diffuseShade and SpecularShade
Color RT_lights(Figure* obj, const Ray& ray, const Vec& thePoint, const Vec& normal)
{
    Color c = Color();
    for (list<Light*>::iterator iterator = lightList.begin(), end = lightList.end(); iterator != end; ++iterator) {
        Light* theLight = *iterator;

        pair<double, Figure*> inter = nearestIntersection(Ray(Vec(thePoint), theLight->getPos()), MIN_T / SHAD_RES, 1.0, EPSILON, false);
        if (inter.first <= 0) {
            Vec* toLight = thePoint.normalize(theLight->getPos());
            double dotProduct = toLight->dot(normal);
            Vec* subt = (thePoint.sub(theLight->getPos()));
            double dist = abs(subt->getMag());
            Color dif = diffuseShade(obj, theLight, max(dotProduct, 0.0), dist);
            Vec* Q = normal.scale(normal.dot(*toLight));
            Vec* S = Q->sub(*toLight);
            Vec* S2 = S->scale(2.0);
            Vec* R = toLight->add(*S2);
            Vec* norm = ray.getNorm();
            Vec* scaledNorm = norm->scale(-1.0);
            dotProduct = max(0.0, R->dot(*scaledNorm));
            Color spec = specularShade(obj, normal, theLight, *toLight, pow(dotProduct, obj->getShininess()), ray, dist);
            c = c.add(dif.add(spec));
            delete(toLight);
            delete(Q);
            delete(S);
            delete(R);
            delete(S2);
            delete(subt);
            delete(norm);
            delete(scaledNorm);
        }
    }
    return c;
}
开发者ID:zuchermann,项目名称:GraphicsClass,代码行数:35,代码来源:ray-tracing.cpp

示例5: computeTangents

void
GiLightObject::makePlanar(int v0, int v1, int v2)
{
  int npoints = m_points.count();

  if (npoints < 3)
    return;
    
  Vec cen = m_points[0];
  for(int i=1; i<npoints; i++)
    cen += m_points[i];
  cen /= npoints;

  Vec normal;
  normal = (m_points[v0]-m_points[v1]).unit()^(m_points[v2]-m_points[v1]).unit();
  normal.normalize();
  // now shift all points into the plane
  for(int i=0; i<npoints; i++)
    {
      Vec v0 = m_points[i]-cen;
      float dv = normal*v0;
      m_points[i] -= dv*normal;
    }

  computeTangents();

  m_updateFlag = true;
  m_lightChanged = true; // for light recomputation
  m_undo.append(m_points);
}
开发者ID:nci,项目名称:drishti,代码行数:30,代码来源:gilightobject.cpp

示例6: createSystemScene

void Seaweed::createSystemScene()
{
	Particle *p1, *p2;
	// add a fixed particle
	Vec initPos = Vec(0.5, 0.5, 0.0); // just use the first point
	p1 = new Particle(initPos, Vec(), 0.0, particleRadius);
	particles.push_back(p1); // init velocity is null and so is the weght. The particle can not move then, it will be the root of seaweed
	// add a set of particles particles
	Vec pos1 = initPos;
	for(int i = 1; i< NB_PARTICLE; i++)
	{
		float positionCurve = i*(1.0/NB_PARTICLE);
		Vect3d * pos1Curve = new Vect3d(pos1.x,pos1.y,pos1.z);
		control->get_pos(pos1Curve, positionCurve);
		Vec vel1;
		if(i%2)
		{
			vel1 = Vec(0.0, defaultVelocity, 0.0);	// non null initial velocity on y axis(lateral movement)
		}
		else
		{
			vel1 = Vec(0.0, -defaultVelocity*0.8, 0.0);	// non null initial velocity on y axis(lateral movement)
		}
		p2 = new Particle(Vec(pos1Curve->x,pos1Curve->y,pos1Curve->z), vel1, 0.1, particleRadius); // No gravity now
		particles.push_back(p2);
		
		// add a spring between the two particle
		Vec u = p2->getPosition() - p1->getPosition();
		Spring *s = new Spring(p1, p2, 5.0, u.normalize()+(rand()%10)/80.0 , 1.5); // add a string between the two created particle
		springs.push_back(s);
		p1 = p2;
	}
	// .. then create a chain of particles
}
开发者ID:proto3,项目名称:3DProject_M1S2,代码行数:34,代码来源:seaweed.cpp

示例7: trimesh

static int trimesh(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "trimesh: expected table");
    }

    std::vector<Vec> vertices;
    lua_getfield(ls, -1, "vertices");
    lua_pushnil(ls);
    while (lua_next(ls, -2) != 0) {
        double x, y, z;
        get_xyz(ls, x, y, z);
        vertices.push_back(Vec{x, y, z});
        lua_pop(ls, 1);
    }
    lua_pop(ls, 1);

    std::vector<TriangleMesh::Face> faces;
    lua_getfield(ls, -1, "faces");
    lua_pushnil(ls);
    while (lua_next(ls, -2) != 0) {
        size_t i, j, k;
        lua_getfield(ls, -1, "i");
        i = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        lua_getfield(ls, -1, "j");
        j = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        lua_getfield(ls, -1, "k");
        k = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        Vec ab = vertices[j] - vertices[i];
        Vec ac = vertices[k] - vertices[i];
        Vec norm = ab.cross(ac);
        norm.normalize();

        faces.push_back(TriangleMesh::Face{i, j, k, norm});
        lua_pop(ls, 1);
    }
    lua_pop(ls, 1);

    lua_getfield(ls, -1, "material");
    Material *mat = reinterpret_cast<Material *>(lua_touserdata(ls, -1));
    lua_pop(ls, 1);

    TriangleMesh *tm = new TriangleMesh;
    tm->faces = std::move(faces);
    tm->vertices = std::move(vertices);
    tm->material.reset(mat);

    lua_pushlightuserdata(ls, tm);

    return 1;
}
开发者ID:dminor,项目名称:raytrace,代码行数:57,代码来源:scene.cpp

示例8: step

void RigidBody::step(double dt){
  FILE_LOG(logDEBUG)<<"entered RigidBody::step(double dt)"<<std::endl;

  // set com
  // NOTE: com is transform r in THIS case
  for(unsigned i=0;i<3;i++)
      com[i] = Tws(i,3);

  // NOTE: set accel for integration function
  vd_ = &vd;

  FILE_LOG(logDEBUG) << "q (before) = " << q << std::endl;
  FILE_LOG(logDEBUG) << "v (before) = " << v << std::endl;
  FILE_LOG(logDEBUG) << "vd (before) = " << vd << std::endl;

  // Set forces to apply
  // apply drag force
  {
      double k = 0.1;
      Ravelin::Vector3d drag;
      v.get_sub_vec(0,3,drag);

      drag = -drag *= (drag.dot(drag) * k);
      apply_force(drag,com);
  }

  // apply forces
  calc_fwd_dynamics();

  // Set up state
    Vec state;
    state.set_zero(q.rows() + v.rows());
    state.set_sub_vec(0,q);
    state.set_sub_vec(q.rows(),v);

  // Integrate state forward 1 step
    sim_->integrate(sim_->time,dt,&fn,state);

  // re-normalize quaternion state
    state.get_sub_vec(0,q.rows(),q);
    state.get_sub_vec(q.rows(),state.rows(),v);
    Vec e;
    q.get_sub_vec(3,7,e);
    e.normalize();
    q.set_sub_vec(3,e);

  FILE_LOG(logDEBUG) << "q (after) = " << q << std::endl;
  FILE_LOG(logDEBUG) << "v (after) = " << v << std::endl;
  FILE_LOG(logDEBUG) << "vd (after) = " << vd << std::endl;

  // Update graphics transform
  update();

  FILE_LOG(logDEBUG)<<"exited RigidBody::step(.)"<<std::endl;
  reset_accumulators();
}
开发者ID:samzapo,项目名称:Simulation,代码行数:56,代码来源:RigidBodyDynamics.cpp

示例9: drawLabel

void Charge::drawLabel(QGLViewer& viewer, QFontMetrics& fontMetrics) 
{
   Vec pos(getPosition());
   Vec shift = viewer.camera()->position() - pos;
   shift.normalize();

   pos = pos + 1.05 * shift * getRadius(true);
   pos = viewer.camera()->projectedCoordinatesOf(pos);
   pos.x -= fontMetrics.width(m_label)/2;
   pos = viewer.camera()->unprojectedCoordinatesOf(pos);
   viewer.renderText(pos[0], pos[1], pos[2], m_label);
}
开发者ID:bjnano,项目名称:IQmol,代码行数:12,代码来源:ChargeLayer.C

示例10: testNormalize

template<class Vec> void testNormalize()
{
	Vec vec;
	for (unsigned int i = 0; i < vec.getDimension(); i++)
		vec[i] = numbers[i];

// getNormalized
	auto temp = vec.getNormalized();
	ASSERT(dbgl::isSimilar(temp.getLength(), 1.0f));
// normalize
	vec.normalize();
	ASSERT(dbgl::isSimilar(vec.getLength(), 1.0f));
}
开发者ID:Drag-On,项目名称:Dragon-Blaze-Game-Library,代码行数:13,代码来源:VectorTests.cpp

示例11: main

/** Main function **/
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage:\t./hw6 filename\n");
    exit(0);
  }
  
  // Read .in file
  for (int i = 1; i < argc; i++) scene.readfile(argv[i]);
  scene.print();
  
  // Create screen
  img = new Image(scene.w, scene.h);
  float pix[3] = {0.0, 0.0, 0.0};
  Vec wp[9];
  Vec rayDirection;
  Ray rays[9];
  Vec pixColor[9];
  
  // Camera frame parameters
  img->setCamera(scene.eyePos, scene.at, scene.up);
  
  // for each pixel on the screen
  for (int i=0; i<scene.w; i++) {
    for (int j=0; j<scene.h; j++) {
      // supersampling for 9 rays per pixel
      for (int row = 0; row < 3; row++) {
        for (int col = 0; col < 3; col++) {
          int idx = row*3 + col;
          wp[idx] = img->normalizePixel(Vec(i+0.5*row,j+0.5*col,0), scene.fovy);
          rayDirection = wp[idx] - img->cf.eyePos;
          rayDirection = rayDirection.normalize();
          rays[idx] = Ray(scene.eyePos, rayDirection, 0, 9999, CameraRay);
          pixColor[idx] = trace(rays[idx], 4);
        }
      }
      // set debug mode
      if (i==scene.w/2 && j==scene.h/2+1) debugMode = 0;
      else debugMode = 0;
      // output color info
      Vec color = (pixColor[0] + pixColor[2] + pixColor[6] + pixColor[8]) * (1.0/16) + (pixColor[1] + pixColor[3] + pixColor[5] + pixColor[7]) * (1.0/8) + pixColor[4] * (1.0/4);
      pix[0] = color.x;
      pix[1] = color.y;
      pix[2] = color.z;
      img->setPixel(pix, i, j);
    }
  }
  // Write pixel color to ppm file
  img->writeToPPM(scene.outname);
  
  return 0;
}
开发者ID:jacyxli,项目名称:ray-tracer,代码行数:52,代码来源:main.cpp

示例12: draw_model

void draw_model ( const Model& m, bool smooth)
{
	glEnable(GL_NORMALIZE);
	if(App->wireframe){glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);}
	else
		glPolygonMode(GL_FRONT, GL_FILL);

	glBegin(GL_TRIANGLES);
	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

	if(smooth)
	{
		for(int i = 0; i < m.fsize; i++)
		{
			glColor3d(m.F[i].r/255.0, m.F[i].g/255.0, m.F[i].b/255.0);

			glNormal3d(m.N[m.F[i].na].x, m.N[m.F[i].na].y, m.N[m.F[i].na].z);
			glVertex3d(m.V[m.F[i].va].x, m.V[m.F[i].va].y, m.V[m.F[i].va].z);

			glNormal3d(m.N[m.F[i].nb].x, m.N[m.F[i].nb].y, m.N[m.F[i].nb].z);
			glVertex3d(m.V[m.F[i].vb].x, m.V[m.F[i].vb].y, m.V[m.F[i].vb].z);

			glNormal3d(m.N[m.F[i].nc].x, m.N[m.F[i].nc].y, m.N[m.F[i].nc].z);
			glVertex3d(m.V[m.F[i].vc].x, m.V[m.F[i].vc].y, m.V[m.F[i].vc].z);
		}
		glEnd();
	}

	if(!smooth)
	{
		for(int i = 0; i < m.fsize; i++)
		{
			glColor3d(m.F[i].r/255.0, m.F[i].g/255.0, m.F[i].b/255.0);

			Vec u = m.V[m.F[i].vb] - m.V[m.F[i].va];
			Vec v = m.V[m.F[i].vb] - m.V[m.F[i].vc];

			Vec w = cross(v, u);
			w.normalize();
			glNormal3d(w.x, w.y, w.z);

			glVertex3d(m.V[m.F[i].va].x, m.V[m.F[i].va].y, m.V[m.F[i].va].z);
			glVertex3d(m.V[m.F[i].vb].x, m.V[m.F[i].vb].y, m.V[m.F[i].vb].z);
			glVertex3d(m.V[m.F[i].vc].x, m.V[m.F[i].vc].y, m.V[m.F[i].vc].z);

		}
		glEnd();

	}
}
开发者ID:jfloreza,项目名称:UCM,代码行数:50,代码来源:draw.cpp

示例13: drawLabel

void Atom::drawLabel(Viewer& viewer, LabelType const type, QFontMetrics& fontMetrics) 
{
   Vec pos(getPosition());
   Vec shift = viewer.camera()->position() - pos;
   shift.normalize();
   QString label(getLabel(type));

   pos = pos + 1.05 * shift * getRadius(true);
   pos = viewer.camera()->projectedCoordinatesOf(pos);
   pos.x -= fontMetrics.width(label)/2.0;
   pos.y += fontMetrics.height()/4.0;
   pos = viewer.camera()->unprojectedCoordinatesOf(pos);

   glColor3f(0.1, 0.1, 0.1);
   viewer.renderText(pos[0], pos[1], pos[2], label, viewer.labelFont());
}
开发者ID:nutjunkie,项目名称:IQmol,代码行数:16,代码来源:AtomLayer.C

示例14: main

int main(int  argc, char** argv)
{

	GLubyte *pic;

	


	createSceneFromFile();
	time_t start;
	time_t end;

	time(&start);
	pic = scene->camera->getPicture(*scene, *intersectionFinder);
	time(&end);

	double diff = difftime(end, start);
	printf("Rendering time in seconds: %lf\n", diff);

	Display display(width, height, "RayTracing");
	display.setPicture(pic);
	display.show();


	delete intersectionFinder;
	delete pic;
	delete scene;
	return 0;


	Vec a(-1, -1, 0);
	Vec n(0, 1, 0);
	a.normalize();
	n.normalize();
	Vec r = (a - 2 * ((a) * n) * n);
	float c = 0;
	while (c < M_PI / 2){
		Vec r = (a*c - 2 * ( (a*c) * n) * n);
		r.normalize();
		c += 0.1;
		if (n*r<=0){
			c += 0;
		}
	}
	
	return 0;
}
开发者ID:yannn12,项目名称:Graphic-Ass2,代码行数:47,代码来源:main.cpp

示例15: getCurrentForce

Vec Spring::getCurrentForce() const
{
    // we compute the force applied on particle 1 by particle 2

    Vec u = p1->getPosition() - p2->getPosition();

    double uNorm = u.normalize();	// u is thereafter normalized!
    if (uNorm < 1.0e-6) 
        return Vec();	// null force

    // force due to stiffness only
    Vec sF = -stiffness * (uNorm - equilibriumLength) * u;
    // damping force
    Vec dF = -damping * ((p1->getVelocity() - p2->getVelocity()) * u) * u;

    return sF + dF;
}
开发者ID:posva,项目名称:g3d,代码行数:17,代码来源:spring.cpp


注:本文中的Vec::normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。