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


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

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


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

示例1: normalAt

TVector3 PrimitiveSuperellipsoid::normalAt( const TIntersection &inter ) const {
  float x = fabsf( inter.pointWorldSpace[__X] );
  float y = fabsf( inter.pointWorldSpace[__Y] );
  float z = fabsf( inter.pointWorldSpace[__Z] );

  float k = powerf( powerf( x, power[__X] ) + powerf( y, power[__X] ), power[__Y] - 1.0f );
  TVector3 N;
  
  N[__X] = k * SGNX(inter.pointWorldSpace[__X]) * powerf( x, power[__X] - 1.0f );
  N[__Y] = k * SGNX(inter.pointWorldSpace[__Y]) * powerf( y, power[__X] - 1.0f ); // FIXME ?
  N[__Z] =     SGNX(inter.pointWorldSpace[__Z]) * powerf( z, power[__Z] - 1.0f );
  
  N.normalize();
  return N;
}
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:15,代码来源:superellipsoid.cpp

示例2: getColor

TColor LightSquare::getColor( const TWorld &world, const TRay &ray, const TRay &lightRay ) {
  const TFinish *finish = ray.intersection.texture->finish;

  stats.increase( TStatistic::STATISTIC_DIFFUSE );

  // Diffuse
  float diffuse = 0.0f;
  if ( finish->diffuseFactor > 0.0f ) {
    // FIXME: create a light ray for each dot in square and compute average value
    // we compute angle between lightRay (from intersection to center of square)
    // this "trick" is a good approximation if dotSize is small
    float angleLight = ray.intersection.normal | lightRay.direction;
    if ( angleLight > 0.0f )
      //--float intensity = powf( angleLight, finish->brilliance ); // FIXME
      diffuse = angleLight * finish->diffuseFactor;
  }

  // Specular
  float specular = 0.0f;
  if ( finish->specularFactor > 0.0f ) {
    TVector3 H = lightRay.direction - ray.direction; H.normalize();
    float angleSpecular = H | ray.intersection.normal;
    if ( angleSpecular > 0.0f ) {
      float intensity = powf( angleSpecular, finish->specularRoughness );
      specular = intensity * finish->specularFactor;
    }
  }

  // Phong
  float phong = 0.0f;
  if ( finish->phongFactor > 0.0f ) {
    TVector3 R = reflectVector( ray.direction, ray.intersection.normal );
    float anglePhong = R | lightRay.direction;
    if ( anglePhong > 0.0f ) {
      float intensity = powf( anglePhong, finish->phongSize );
      phong = intensity * finish->phongFactor;
    }
  }

  return color * ( brightness * ( diffuse + specular + phong ) );
}
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:41,代码来源:square.cpp

示例3: computeLighting

bool LightSquare::computeLighting( const TWorld &world, const TRay &ray,
				   TLighting &lighting ) {
  lighting.light = this;
  lighting.visible = isLighten( ray.intersection.pointWorldSpace );
  // If point not in light volume, return false (no diffuse component)
  if ( !lighting.visible )
    return false;

  const TFinish *finish = ray.intersection.texture->finish;

  // reset lighting
  lighting.shadow = 0.0f;
  lighting.diffuse = 0.0f;
  lighting.specular = 0.0f;
  lighting.phong = 0.0f;
  float att = 0.0f;

  TRay lightRay;
  TPoint3 *dotGridIdx = dotGrid;
  for ( int i = 0; i < numDots; i++, dotGridIdx++ ) {
    // create a lightRay from dot in grid to intersection
    lightRay.direction = *dotGridIdx - ray.intersection.pointWorldSpace;
    float dist2 = lightRay.direction.magnitudeSquared();
    lightRay.direction *= fastInvSqrt( dist2 ); // normalize vector
    lightRay.origin = ray.intersection.pointWorldSpace + lightRay.direction * 0.1f; // origin is intersection
    lightRay.reverseDirection = inverseVector( lightRay.direction );
    lightRay.target = *dotGridIdx;

    stats.increase( TStatistic::STATISTIC_LIGHT_RAY );

    // TODO
    att += brightness;
    
    // if shadow: proceed with next lightRay
    if ( world.findFirstIntersection( lightRay, ray.intersection, dist2, shadowCache ) )
      continue;
    // if no shadow: add 1.0f (no shadow) to lighting.shadow
    lighting.shadow += 1.0f;

    stats.increase( TStatistic::STATISTIC_DIFFUSE );
    
    // Diffuse
    if ( finish->diffuseFactor > 0.0f ) {
      float angleLight = ray.intersection.normal | lightRay.direction;
      if ( angleLight > 0.0f )
	//--float intensity = powf( angleLight, finish->brilliance ); // FIXME
	lighting.diffuse += angleLight * finish->diffuseFactor;
    }
    
    // Specular
    if ( finish->specularFactor > 0.0f ) {
      TVector3 H = lightRay.direction - ray.direction; H.normalize();
      float angleSpecular = H | ray.intersection.normal;
      if ( angleSpecular > 0.0f ) {
	float intensity = powf( angleSpecular, finish->specularRoughness );
	lighting.specular += intensity * finish->specularFactor;
      }
    }
    
    // Phong
    if ( finish->phongFactor > 0.0f ) {
      TVector3 R = reflectVector( ray.direction, ray.intersection.normal );
      float anglePhong = R | lightRay.direction;
      if ( anglePhong > 0.0f ) {
	float intensity = powf( anglePhong, finish->phongSize );
	lighting.phong += intensity * finish->phongFactor;
      }
    }
  }

  // If full shadow, return false (no diffuse component)
  if ( lighting.shadow <= 0.0f )
    return false;

  // att, shadow, diffuse, specular and phong must be scaled by oneOverNumDots (=N)
  // att * N * shadow * N * ( diffuse * N + specular * N + phong * N )
  // = N*N * ( att * shadow * ( N * ( diffuse + specular + phong ) )
  // = N*N*N * ( att * shadow * ( diffuse + specular + phong ) )
  lighting.color = color * ( (oneOverNumDots*oneOverNumDots*oneOverNumDots) * att * lighting.shadow * ( lighting.diffuse + lighting.specular + lighting.phong ) );
  return true;
}
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:81,代码来源:square.cpp

示例4: getColor

TColor PigmentNoisy::getColor( const TPoint3 &hitPoint ) const {
  TVector3 p = TurbulenceNoise::getNoise3( hitPoint - anchor );
  p.normalize();
  return TColor( p[0], p[1], p[2]);
}
开发者ID:SinaC,项目名称:OldRaytrace,代码行数:5,代码来源:noisy.cpp


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