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


C++ Vec3f::Cross方法代码示例

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


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

示例1: SetCamera

//---------------------------------------
void Frustum::SetCamera( const Vec3f& p, const Vec3f& d, const Vec3f& u )
{
	Vec3f nc, fc, x, y, z;

	z = p - d;
	z.Normalize();

	x = u.Cross( z );
	x.Normalize();

	y = z.Cross( x );

	nc = p - z * mNearDist;
	fc = p - z * mFarDist;

	mNearPoints[0] = nc + y * mNearH - x * mNearW;
	mNearPoints[1] = nc + y * mNearH + x * mNearW;
	mNearPoints[2] = nc - y * mNearH - x * mNearW;
	mNearPoints[3] = nc - y * mNearH + x * mNearW;

	mFarPoints[0] = fc + y * mFarH - x * mFarW;
	mFarPoints[1] = fc + y * mFarH + x * mFarW;
	mFarPoints[2] = fc - y * mFarH - x * mFarW;
	mFarPoints[3] = fc - y * mFarH + x * mFarW;

	mPlanes[ FP_TOP    ] = Planef( mNearPoints[1], mNearPoints[0], mFarPoints[0] );
	mPlanes[ FP_BOTTOM ] = Planef( mNearPoints[2], mNearPoints[3], mFarPoints[3] );
	mPlanes[ FP_LEFT   ] = Planef( mNearPoints[0], mNearPoints[2], mFarPoints[2] );
	mPlanes[ FP_RIGHT  ] = Planef( mNearPoints[3], mNearPoints[1], mFarPoints[3] );
	mPlanes[ FP_NEAR   ] = Planef( mNearPoints[0], mNearPoints[1], mNearPoints[3] );
	mPlanes[ FP_FAR    ] = Planef( mFarPoints[1], mFarPoints[0], mFarPoints[2] );
}
开发者ID:andrewtc,项目名称:AndroidWars,代码行数:33,代码来源:Frustum.cpp

示例2: Pan

void QRenderOutputWidget::Pan(float DownDegrees, float RightDegrees)
{
	Vec3f LoS = FocalPoint - Position;

	Vec3f right		= LoS.Cross(ViewUp);
	Vec3f orthogUp	= LoS.Cross(right);

	right.Normalize();
	orthogUp.Normalize();

	const float Length = (FocalPoint - Position).Length();

	const unsigned int WindowWidth	= this->Image.Width();

	const float U = Length * (RightDegrees / WindowWidth);
	const float V = Length * (DownDegrees / WindowWidth);

	Position	= Position + right * U - ViewUp * V;
	FocalPoint	= FocalPoint + right * U - ViewUp * V;
}
开发者ID:ChuckDanglars,项目名称:exposure-render.exposurerender,代码行数:20,代码来源:renderoutputwidget.cpp

示例3: Orbit

void QRenderOutputWidget::Orbit(float DownDegrees, float RightDegrees)
{
	Vec3f ReverseLoS = Position - FocalPoint;

	Vec3f right		= ViewUp.Cross(ReverseLoS);
	Vec3f orthogUp	= ReverseLoS.Cross(right);
	Vec3f Up = Vec3f(0.0f, 1.0f, 0.0f);
		
	ReverseLoS.RotateAxis(right, DownDegrees);
	ReverseLoS.RotateAxis(Up, RightDegrees);
	ViewUp.RotateAxis(right, DownDegrees);
	ViewUp.RotateAxis(Up, RightDegrees);

	Position = ReverseLoS + FocalPoint;
}
开发者ID:ChuckDanglars,项目名称:exposure-render.exposurerender,代码行数:15,代码来源:renderoutputwidget.cpp

示例4: updateOrientation

void updateOrientation() {
	if ( orientationDirty == false ) {
		return;
	}
	orientationDirty = false;
	
	float decay = 0.9f;
	
	float hyst = cos( ToRadians( app_orientationHysteresis.GetVal() ) );

	if ( GotCompassUpdate ) {
		if ( headingSmooth.Dot( heading ) < hyst ) {
			headingSmooth *= decay;
			headingSmooth += (1.0f - decay) * heading;
		}
		headingSmooth.Normalize();
	} 		

	if ( accelSmooth.Dot( accel ) < hyst ) {
		accelSmooth *= decay;
		accelSmooth += (1.0f - decay) * accel;		
	}
	accelSmooth.Normalize();		
	
	Vec3f up = -accelSmooth;
	up.Normalize();
	Vec3f north = headingSmooth;
	north -= up * up.Dot( north );
	north.Normalize();

	Matrix3f toTrueNorth = Rotationf( up, ToRadians( trueHeadingDiff ) ).GetMatrix3();
	north = toTrueNorth * north;
	
	Vec3f east = north.Cross( up );

	Matrix4f o;
	o.SetRow( 0, Vec4f(  east.x,  east.y,  east.z, 0.0f ) );
	o.SetRow( 1, Vec4f( north.x, north.y, north.z, 0.0f ) );
	o.SetRow( 2, Vec4f(    up.x,    up.y,    up.z, 0.0f ) );
	o.SetRow( 3, Vec4f(     0.0,     0.0,     0.0, 1.0f ) );
	
	platformOrientation = o.Transpose();
}
开发者ID:bcrowell,项目名称:planetfinder_ios,代码行数:43,代码来源:app.cpp

示例5: textFile

Terrain::Terrain(void) {
  _width = 1024;
  _height = 1024;

  ifstream textFile("height.dat");
  if(!textFile.is_open()) {
    cerr << "Error whilst reading heightmap" << endl;
    EndGame(1);
  } else {
    for(int z = 0; z < 1024; z++) {
      getline(textFile, _line);
      if(_line.empty()) {
        break;
      }
      for(int x = 0; x < 1024; x++) {
        pos = _line.find(' ');
        if(pos == string::npos) {
          break;
        }
        string _line2(_line, 0, pos);
        stringstream strh(_line2);
        strh >> _heightData[z][x];
        _line.erase(0,pos+1);
      }
    }
    textFile.close();
  }

  glGenTextures(1, &_tex);
  glBindTexture(GL_TEXTURE_2D, _tex);
  // GL_MODULATE for correct lighting and shit, not really needed because of shaders.
  // When the texture area is small, bilinear filter the closest mipmap.
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  // When texture area is large, bilinear filter the original.
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  if(glfwLoadTexture2D("terrain1.tga", GLFW_BUILD_MIPMAPS_BIT) != GL_TRUE) {
    cerr << "Error while reading the terrain texture!" << endl;
    EndGame(1);
  }

  // Calculate the normals.
  _normals = new Vec3f*[_height];
  Vec3f** normals2 = new Vec3f*[_height];
  for(int i = 0; i < _height; i++) {
    _normals[i] = new Vec3f[_width];
    normals2[i] = new Vec3f[_width];
  }

  // Rough normals.
  for(int z = 0; z < _height; z++) {
    for(int x = 0; x < _width; x++) {
      Vec3f sum(0.0, 0.0, 0.0);

      Vec3f down;
      if(z > 0) {
        down = Vec3f(0.0, GetHeight(x, z-1) - GetHeight(x, z), -1.0);
      }
      Vec3f up;
      if(z < _height-1) {
        up = Vec3f(0.0, GetHeight(x, z+1) - GetHeight(x,z), 1.0);
      }
      Vec3f left;
      if(x > 0) {
        left = Vec3f(-1.0, GetHeight(x-1, z) - GetHeight(x,z), 0.0);
      }
      Vec3f right;
      if(x < _width-1) {
        right = Vec3f(1.0, GetHeight(x+1, z) - GetHeight(x,z), 0.0);
      }

      if(x > 0 && z > 0) { 
        sum += down.Cross(left).Normalize();
      }
      if(x > 0 && z < _height-1) {
        sum += left.Cross(up).Normalize();
      }
      if(x < _width-1 && z < _height-1) {
        sum += up.Cross(right).Normalize();
      }
      if(x < _width-1 && z > 0) {
        sum += right.Cross(down).Normalize();
      }

      normals2[x][z] = sum;
    }
  }

  // Smooth notmals.
  const float FALLOUT_RATIO = 0.5f;
  for(int z = 0; z < _height; z++) {
    for(int x = 0; x < _width; x++) {
      Vec3f sum = normals2[x][z];

      if(x > 0) {
        sum += normals2[x-1][z] * FALLOUT_RATIO;
      }
      if(x < _width-1) {
        sum += normals2[x+1][z] * FALLOUT_RATIO;
      }
      if(z > 0) {
//.........这里部分代码省略.........
开发者ID:Allanis,项目名称:TerrainTest,代码行数:101,代码来源:terrain.cpp


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