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


C++ Point3F::len方法代码示例

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


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

示例1: resolveCollision

/** Resolve collision with an immovable object
   Computes & applies the collision impulse needed to keep the body
   from penetrating the given surface.
*/
bool Rigid::resolveCollision(const Point3F& p, const Point3F &normal)
{
   atRest = false;
   Point3F v,r;
   getOriginVector(p,&r);
   getVelocity(r,&v);
   F32 n = -mDot(v,normal);
   if (n >= 0.0f) {

      // Collision impulse, straight forward force stuff.
      F32 d = getZeroImpulse(r,normal);
      F32 j = n * (1.0f + restitution) * d;
      Point3F impulse = normal * j;

      // Friction impulse, calculated as a function of the
      // amount of force it would take to stop the motion
      // perpendicular to the normal.
      Point3F uv = v + (normal * n);
      F32 ul = uv.len();
      if (ul) {
         uv /= -ul;
         F32 u = ul * getZeroImpulse(r,uv);
         j *= friction;
         if (u > j)
            u = j;
         impulse += uv * u;
      }

      //
      applyImpulse(r,impulse);
   }
   return true;
}
开发者ID:Adhdcrazzy,项目名称:Torque3D,代码行数:37,代码来源:rigid.cpp

示例2: prepRenderImage

bool PxSingleActor::prepRenderImage(   SceneState *state,
                                          const U32 stateKey,
                                          const U32 startZone, 
                                          const bool modifyBaseState )
{
   if ( !mShapeInstance || !state->isObjectRendered(this) )
      return false;

   Point3F cameraOffset;
   getTransform().getColumn(3,&cameraOffset);
   cameraOffset -= state->getDiffuseCameraPosition();
   F32 dist = cameraOffset.len();
   if ( dist < 0.01f )
      dist = 0.01f;

   F32 invScale = (1.0f/getMax(getMax(getScale().x,getScale().y),getScale().z));
   dist *= invScale;
   S32 dl = mShapeInstance->setDetailFromDistance( state, dist );
   if (dl<0)
      return false;

   renderObject( state );

   return false;
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:25,代码来源:pxSingleActor.cpp

示例3: updateCameraPos

void Etherform::updateCameraPos(F32 delta)
{
	//
	// Update 3rd person camera position.
	//

	F32 min,max;
	Point3F offset;
	MatrixF rot;
	this->getCameraParameters(&min,&max,&offset,&rot);

	Point3F vec = mCameraTargetPos - mCameraPos;
	F32    dist = vec.len();

	if(dist == 0)
	{
		// Catch camera position up to its target position.
		mCameraPos = mCameraTargetPos;
	}
	else if(dist > max)
	{
		// Catch camera up to max allowed dist from target position.
		vec.normalize(); vec.neg();
		mCameraPos = mCameraTargetPos + vec * max;
	}
	else
	{
		// Move camera pos towards its target pos.
#if 0
		F32 speed = mDataBlock->accelerationForce;
		speed *= 1 - (1/vec.lenSquared());

		vec.normalize();
		mCameraPos += vec * speed * delta;
#else
		//F32 speedScale = this->getVelocity().len() / mDataBlock->accelerationForce;
		F32 speedScale = 4; //mDataBlock->accelerationForce / 2;
		F32 distScale = 1 - (1/vec.lenSquared());
		vec *= speedScale * distScale * delta;
		if(vec.len() > dist)
			mCameraPos = mCameraTargetPos;
		else
			mCameraPos += vec;
#endif
	}
}
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:46,代码来源:etherform.cpp

示例4: updateWorkingCollisionSet

//----------------------------------------------------------------------------
void Item::updateWorkingCollisionSet(const U32 mask, const F32 dt)
{
   // It is assumed that we will never accelerate more than 10 m/s for gravity...
   //
   Point3F scaledVelocity = mVelocity * dt;
   F32 len    = scaledVelocity.len();
   F32 newLen = len + (10 * dt);

   // Check to see if it is actually necessary to construct the new working list,
   //  or if we can use the cached version from the last query.  We use the x
   //  component of the min member of the mWorkingQueryBox, which is lame, but
   //  it works ok.
   bool updateSet = false;

   Box3F convexBox = mConvex.getBoundingBox(getTransform(), getScale());
   F32 l = (newLen * 1.1) + 0.1;  // from Convex::updateWorkingList
   convexBox.minExtents -= Point3F(l, l, l);
   convexBox.maxExtents += Point3F(l, l, l);

   // Check containment
   {
      if (mWorkingQueryBox.minExtents.x != -1e9)
      {
         if (mWorkingQueryBox.isContained(convexBox) == false)
         {
            // Needed region is outside the cached region.  Update it.
            updateSet = true;
         }
         else
         {
            // We can leave it alone, we're still inside the cached region
         }
      }
      else
      {
         // Must update
         updateSet = true;
      }
   }

   // Actually perform the query, if necessary
   if (updateSet == true)
   {
      mWorkingQueryBox = convexBox;
      mWorkingQueryBox.minExtents -= Point3F(2 * l, 2 * l, 2 * l);
      mWorkingQueryBox.maxExtents += Point3F(2 * l, 2 * l, 2 * l);

      disableCollision();
      if (mCollisionObject)
         mCollisionObject->disableCollision();

      mConvex.updateWorkingList(mWorkingQueryBox, mask);

      if (mCollisionObject)
         mCollisionObject->enableCollision();
      enableCollision();
   }
}
开发者ID:Bloodknight,项目名称:GMK,代码行数:59,代码来源:item.cpp

示例5: setCommonScale

void CelAnimMesh::setCommonScale( Shape::Mesh & otherMesh )
{
   CelAnimMesh *potherMesh = dynamic_cast<CelAnimMesh *>(&otherMesh);
   AssertFatal(potherMesh,
      "TS::CelAnimMesh::setCommonScale:  meshes not same type");

#if 0 
   // array of unpacked verts -- points only
   Point3F *unpackedVerts = new Point3F[fVerts.size()];
   int v;
   for (v=0;v<fVerts.size();v++)
      fVerts[v].getPoint(unpackedVerts[v],fScale,fOrigin);

   Point3F *otherUnpackedVerts = new Point3F[potherMesh->fVerts.size()];
   for (v=0;v<potherMesh->fVerts.size();v++)
      potherMesh->fVerts[v].getPoint(otherUnpackedVerts[v],potherMesh->fScale,potherMesh->fOrigin);

   // get minVert and maxVert for setting new fScale, fOrigin, and fRadius
   Point3F minVert = unpackedVerts[0];
   Point3F maxVert = unpackedVerts[0];
   for (v=1;v<fVerts.size();v++)
   {
      minVert.setMin( unpackedVerts[v] );
      maxVert.setMax( unpackedVerts[v] );
   }
   for (v=0;v<potherMesh->fVerts.size();v++)
   {
      minVert.setMin( otherUnpackedVerts[v] );
      maxVert.setMax( otherUnpackedVerts[v] );
   }

   // figure new fOrigin, fScale, and fRadius
   Point3F newOrigin = minVert;
   maxVert -= minVert;
   Point3F newScale( maxVert.x/255.0f, maxVert.y/255.0f, maxVert.z/255.0f);
   float newRadius = maxVert.len();

   // re-pack this shapes verts     
   int i;
   Point3F temp;
   for (i=0;i<fVerts.size();i++)
      fVerts[i].setPoint(unpackedVerts[i],newScale,newOrigin);
   fOrigin=newOrigin;
   fScale=newScale;
   fRadius=newRadius;

   // re-pack other shapes verts
   for (i=0;i<potherMesh->fVerts.size();i++)
      potherMesh->fVerts[i].setPoint(otherUnpackedVerts[i],newScale,newOrigin);
   potherMesh->fOrigin=fOrigin;
   potherMesh->fScale=newScale;
   potherMesh->fRadius=newRadius;

   delete [] unpackedVerts;
   delete [] otherUnpackedVerts;
#endif      
}
开发者ID:AltimorTASDK,项目名称:TribesRebirth,代码行数:57,代码来源:ts_CelAnimMesh.cpp

示例6: consoleError

void Point3NormalizeValidator::validateType(SimObject *object, void *typePtr)
{
    Point3F *v = (Point3F *) typePtr;
    const F32 len = v->len();
    if(!mIsEqual(len, 1.0f))
    {
        consoleError(object, "Vector length must be %g", length);
        *v *= length / len;
    }
}
开发者ID:caomw,项目名称:Torque3D,代码行数:10,代码来源:typeValidators.cpp

示例7: findBest

bool WindEmitter::findBest(   const Point3F& cameraPos, 
                              const VectorF& cameraDir,
                              F32 viewDistance,
                              U32 maxResults,
                              WindEmitterList* results )
{
   PROFILE_START(WindEmitter_findBest);

   // Build a sphere from the camera point.
	SphereF cameraSphere;
   cameraSphere.center = cameraPos;
   cameraSphere.radius = viewDistance;

   // Collect the active spheres within the camera space and score them.
   WindEmitterList best;
   WindEmitterList::iterator iter = smAllEmitters.begin();
   for ( ; iter != smAllEmitters.end(); iter++ )
   {        
      const SphereF& sphere = *(*iter);

      // Skip any spheres outside of our camera range or that are disabled.
      if ( !(*iter)->mEnabled || !cameraSphere.isIntersecting( sphere ) )
         continue;

      // Simple score calculation...
      //
      // score = ( radius / distance to camera ) * dot( cameraDir, vector from camera to sphere )
      //
      Point3F vect = sphere.center - cameraSphere.center;
      F32 dist = vect.len();
      (*iter)->mScore = dist * sphere.radius;
      vect /= getMax( dist, 0.001f );
      (*iter)->mScore *= mDot( vect, cameraDir );

      best.push_back( *iter );
   }

   // Sort the results by score!
   dQsort( best.address(), best.size(), sizeof(WindEmitter*), &WindEmitter::_sortByScore );

   // Clip the results to the max requested.
   if ( best.size() > maxResults )
      best.setSize( maxResults );

   // Merge the results and return.
   results->merge( best );

   PROFILE_END(); // WindEmitter_findBest

   return best.size() > 0;
}
开发者ID:campadrenalin,项目名称:terminal-overload,代码行数:51,代码来源:windEmitter.cpp

示例8: updateWorkingCollisionSet

void Etherform::updateWorkingCollisionSet()
{
   // First, we need to adjust our velocity for possible acceleration.  It is assumed
   // that we will never accelerate more than 20 m/s for gravity, plus 10 m/s for
   // jetting, and an equivalent 10 m/s for jumping.  We also assume that the
   // working list is updated on a Tick basis, which means we only expand our
   // box by the possible movement in that tick.
   Point3F scaledVelocity = mVelocity * TickSec;
   F32 len    = scaledVelocity.len();
   F32 newLen = len + (10.0f * TickSec);

   // Check to see if it is actually necessary to construct the new working list,
   // or if we can use the cached version from the last query.  We use the x
   // component of the min member of the mWorkingQueryBox, which is lame, but
   // it works ok.
   bool updateSet = false;

   Box3F convexBox = mConvex.getBoundingBox(getTransform(), getScale());
   F32 l = (newLen * 1.1f) + 0.1f;  // from Convex::updateWorkingList
   const Point3F  lPoint( l, l, l );
   convexBox.minExtents -= lPoint;
   convexBox.maxExtents += lPoint;

   // Check containment
   if (mWorkingQueryBox.minExtents.x != -1e9f)
   {
      if (mWorkingQueryBox.isContained(convexBox) == false)
         // Needed region is outside the cached region.  Update it.
         updateSet = true;
   }
   else
   {
      // Must update
      updateSet = true;
   }
   
   // Actually perform the query, if necessary
   if (updateSet == true)
   {
      const Point3F  twolPoint( 2.0f * l, 2.0f * l, 2.0f * l );
      mWorkingQueryBox = convexBox;
      mWorkingQueryBox.minExtents -= twolPoint;
      mWorkingQueryBox.maxExtents += twolPoint;

      disableCollision();
      mConvex.updateWorkingList(mWorkingQueryBox,
         isGhost() ? sClientCollisionContactMask : sServerCollisionContactMask);
      enableCollision();
   }
}
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:50,代码来源:etherform.cpp

示例9: _onContact

void PxSingleActor::_onContact(  NxActor *ourActor, 
                                    NxActor *hitActor, 
                                    SceneObject *hitObject,
                                    const Point3F &hitPoint,
                                    const Point3F &impactForce )
{
   if ( isGhost() )
      return;

   String strHitPos = String::ToString( "%g %g %g", hitPoint.x, hitPoint.y, hitPoint.z );
   String strImpactVec = String::ToString( "%g %g %g", impactForce.x, impactForce.y, impactForce.z );
   String strImpactForce = String::ToString( "%g", impactForce.len() );
      
   Con::executef( mDataBlock, "onCollision", getIdString(), 
      hitObject ? hitObject->scriptThis() : "", 
      strHitPos.c_str(), strImpactVec.c_str(), strImpactForce.c_str() );
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:17,代码来源:pxSingleActor.cpp

示例10: setTranslate

// This is for panning the viewport camera.
void GuiMaterialPreview::setTranslate(S32 modifier, F32 xstep, F32 ystep)
{
	F32 transstep = (modifier & SI_SHIFT ? mTransStep : (mTransStep*mTranMult));

	F32 nominalDistance = 20.0;
	Point3F vec = mCameraPos;
	vec -= mOrbitPos;
	transstep *= vec.len() / nominalDistance;

	if (modifier & SI_PRIMARY_CTRL)
	{
		mOrbitRelPos.x += ( xstep * transstep );
		mOrbitRelPos.y += ( ystep * transstep );
	}
	else
	{
		mOrbitRelPos.x += ( xstep * transstep );
		mOrbitRelPos.z += ( ystep * transstep );
	}
}
开发者ID:Azaezel,项目名称:Torque3D,代码行数:21,代码来源:guiMaterialPreview.cpp

示例11: scheduleThunder

void Lightning::scheduleThunder(Strike* newStrike)
{
   AssertFatal(isClientObject(), "Lightning::scheduleThunder: server objects should not enter this version of the function");

   // If no thunder sounds, don't schedule anything!
   if (mDataBlock->numThunders == 0)
      return;

   GameConnection* connection = GameConnection::getConnectionToServer();
   if (connection) {
      MatrixF cameraMatrix;

      if (connection->getControlCameraTransform(0, &cameraMatrix)) {
         Point3F worldPos;
         cameraMatrix.getColumn(3, &worldPos);

         worldPos.x -= newStrike->xVal;
         worldPos.y -= newStrike->yVal;
         worldPos.z  = 0.0f;

         F32 dist = worldPos.len();
         F32 t    = dist / 330.0f;

         // Ok, we need to schedule a random strike sound t secs in the future...
         //
         if (t <= 0.03f) {
            // If it's really close, just play it...
            U32 thunder = sgLightningRand.randI(0, mDataBlock->numThunders - 1);
            SFX->playOnce(mDataBlock->thunderSounds[thunder]);
         } else {
            Thunder* pThunder = new Thunder;
            pThunder->tRemaining = t;
            pThunder->next       = mThunderListHead;
            mThunderListHead     = pThunder;
         }
      }
   }
}
开发者ID:GeekOfWires,项目名称:OmniEngine.Net,代码行数:38,代码来源:lightning.cpp

示例12: prepRenderImage

void TSStatic::prepRenderImage( SceneRenderState* state )
{
   if( !mShapeInstance )
      return;
	//WLE - Vince
	//Lod preloading
    GameConnection* connection = GameConnection::getConnectionToServer();
	if (connection && !connection->didFirstRender)
		{
		TSRenderState rdata;
		rdata.setSceneState( state );
		rdata.setFadeOverride( 1.0f );
		rdata.setOriginSort( mUseOriginSort );
		for (S32 i = mShapeInstance->getSmallestVisibleDL(); i >= 0; i-- )
			{
			mShapeInstance->setCurrentDetail( i );
			   
			mShapeInstance->render( rdata );
			}
		}

   Point3F cameraOffset;
   getRenderTransform().getColumn(3,&cameraOffset);
   cameraOffset -= state->getDiffuseCameraPosition();
   F32 dist = cameraOffset.len();
   if (dist < 0.01f)
      dist = 0.01f;

   if (mUseAlphaLod)
   {
      mAlphaLOD = 1.0f;
      if ((mAlphaLODStart < mAlphaLODEnd) && mAlphaLODStart > 0.1f)
      {
         if (mInvertAlphaLod)
		 {
            if (dist <= mAlphaLODStart)
			{
               return;
			}
  
            if (dist < mAlphaLODEnd)
			{
               mAlphaLOD = ((dist - mAlphaLODStart) / (mAlphaLODEnd - mAlphaLODStart));
			}
         }
         else
		 {
            if (dist >= mAlphaLODEnd)
			{
               return;
			}
  
            if (dist > mAlphaLODStart)
			{
               mAlphaLOD -= ((dist - mAlphaLODStart) / (mAlphaLODEnd - mAlphaLODStart));
			}
         }
      }
   }

   F32 invScale = (1.0f/getMax(getMax(mObjScale.x,mObjScale.y),mObjScale.z));   

   if ( mForceDetail == -1 )
      mShapeInstance->setDetailFromDistance( state, dist * invScale );
   else
      mShapeInstance->setCurrentDetail( mForceDetail );

   if ( mShapeInstance->getCurrentDetail() < 0 )
      return;

   GFXTransformSaver saver;
   
   // Set up our TS render state.
   TSRenderState rdata;
   rdata.setSceneState( state );
   rdata.setFadeOverride( 1.0f );
   rdata.setOriginSort( mUseOriginSort );

   // If we have submesh culling enabled then prepare
   // the object space frustum to pass to the shape.
   Frustum culler;
   if ( mMeshCulling )
   {
      culler = state->getCullingFrustum();
      MatrixF xfm( true );
      xfm.scale( Point3F::One / getScale() );
      xfm.mul( getRenderWorldTransform() );
      xfm.mul( culler.getTransform() );
      culler.setTransform( xfm );
      rdata.setCuller( &culler );
   }

   // We might have some forward lit materials
   // so pass down a query to gather lights.
   LightQuery query;
   query.init( getWorldSphere() );
   rdata.setLightQuery( &query );

   MatrixF mat = getRenderTransform();
   mat.scale( mObjScale );
//.........这里部分代码省略.........
开发者ID:Dwarf-King,项目名称:OmniEngine.Net,代码行数:101,代码来源:tsStatic.cpp

示例13: terrTexGen

   void terrTexGen( vertexType vtype, Point4F *clipmapMapping, const MatrixF &blockTransform, const Point3F &cameraPosition, LightInfo *light, SceneState * state)
   {
      PROFILE_SCOPE(Terrain_TexGen);
      SceneManager * sceneManager = state->getSceneManager();
      Point3F relative;
      const F32 blockTexCoordScale = 1.0f / (TerrainRender::mCurrentBlock->getSquareSize() * TerrainBlock::BlockSize);
      // Apply texgen to the new verts...
      if (vtype == vertexTypeFullClipMapping)
      {
         for(U32 i=0; i<mCurVertex; i++)
         {
            mVertexStore[i].texCoord.x = mVertexStore[i].point.x * blockTexCoordScale;
            mVertexStore[i].texCoord.y = mVertexStore[i].point.y * blockTexCoordScale;
         }
      }
      else if (vtype == vertexTypeSingleTextureClipMapping)
      {
         // Compute the fixedfunction vert stuff now
         AssertFatal(clipmapMapping != NULL, "TerrBatch::end - vertexTypeSingleTextureClipMapping requires clipmapMapping variable!");
         const F32 fadeConstant = 3.0f;
         const F32 blockTexCoordScale2 = blockTexCoordScale * clipmapMapping->z;
         for(U32 i=0; i<mCurVertex; i++)
         {
            mVertexStorePCNT[i].point = mVertexStore[i].point;
            mVertexStorePCNT[i].normal = mVertexStore[i].normal;
            mVertexStorePCNT[i].texCoord.x = mVertexStore[i].point.x * blockTexCoordScale2;
            mVertexStorePCNT[i].texCoord.y = mVertexStore[i].point.y * blockTexCoordScale2;
            relative.x = mVertexStorePCNT[i].texCoord.x - clipmapMapping->x;
            relative.y = mVertexStorePCNT[i].texCoord.y - clipmapMapping->y;
            relative.z = 0;
            // note: this uses 128.0f - instead of 255.0f - to hide some
            // transition artifacts at the edges (which are not visible
            // in the shader path due to its use of /2 in the vertex
            // shader and saturate(fade*2) in the pixel shader, which
            // allows sharp transitions to be interpolated more cleanly)
            mVertexStorePCNT[i].color.set(255, 255, 255, (U8)mClampF(128.0f - (relative.len() * (2.0f * fadeConstant) - (fadeConstant - 1.0f)) * 255.0f, 0.0f, 255.0f));
         }
      }
      else if (vtype == vertexTypeDLight)
      {
         // Compute the fixedfunction vert stuff now
         AssertFatal(clipmapMapping != NULL, "TerrBatch::end - vertexTypeDLight requires clipmapMapping variable!");
         AssertFatal(light != NULL, "TerrBatch::end - vertexTypeDLight requires light variable!");
         AssertFatal(light->mRadius > 0, "TerrBatch::end - vertexTypeDLight requires light->mRadius > 0!");
         const F32 blockTexCoordScale2 = blockTexCoordScale * clipmapMapping->z;
         const F32 heightOffset = sceneManager->getFogHeightOffset();
         const F32 inverseHeightRange = sceneManager->getFogInvHeightRange();
         const F32 inverseVisibleDistanceMod = 1.0f / sceneManager->getVisibleDistanceMod();
         Point3F worldPoint;
         const F32 lightRadius = light->mRadius;
         const Point3F lightPosition = light->mPos;
         F32 intensity;
         const F32 inverseLightRadius = 1.0f / lightRadius;
         // note: this imitates sgLightingModel only very loosely for
         // performance reasons, it does look very similar to the shader path
         for(U32 i=0; i<mCurVertex; i++)
         {
            mVertexStorePCNTT[i].point = mVertexStore[i].point;
            mVertexStorePCNTT[i].normal = mVertexStore[i].normal;
            mVertexStorePCNTT[i].texCoord[0].x = mVertexStore[i].point.x * blockTexCoordScale2;
            mVertexStorePCNTT[i].texCoord[0].y = mVertexStore[i].point.y * blockTexCoordScale2;
            blockTransform.mulP(mVertexStore[i].point, &worldPoint);
            relative = worldPoint - cameraPosition;
            mVertexStorePCNTT[i].texCoord[1].x = 1.0 - (relative.len() * inverseVisibleDistanceMod);
            mVertexStorePCNTT[i].texCoord[1].y = (worldPoint.z - heightOffset) * inverseHeightRange;
            relative = worldPoint - lightPosition;
            intensity = getMax(1.0f - relative.len() * inverseLightRadius, 0.0f);
            intensity = 512.0f * intensity;
            if (intensity > 0)
               mVertexStorePCNTT[i].color.set((U8)getMin(light->mColor.red * intensity, 255.0f), (U8)getMin(light->mColor.green * intensity, 255.0f), (U8)getMin(light->mColor.blue * intensity, 255.0f), 255);
            else
               mVertexStorePCNTT[i].color.set(0, 0, 0, 255);
         }
      }
      else if (vtype == vertexTypeFog)
      {
         const F32 heightOffset = sceneManager->getFogHeightOffset();
         const F32 inverseHeightRange = sceneManager->getFogInvHeightRange();
         const F32 inverseVisibleDistanceMod = 1.0f / sceneManager->getVisibleDistanceMod();
         Point3F worldPoint;
         for(U32 i=0; i<mCurVertex; i++)
         {
            mVertexStorePCNT[i].point = mVertexStore[i].point;
            mVertexStorePCNT[i].normal = mVertexStore[i].normal;
            blockTransform.mulP(mVertexStore[i].point, &worldPoint);
            relative = worldPoint - cameraPosition;
            mVertexStorePCNT[i].texCoord.x = 1.0 - (relative.len() * inverseVisibleDistanceMod);
            mVertexStorePCNT[i].texCoord.y = (worldPoint.z - heightOffset) * inverseHeightRange;
            mVertexStorePCNT[i].color.set(255, 255, 255, 255);
         }
      }
      // The only time 'vertexTypeDetail' is used is during a fixed-function detail pass.
      else if( vtype == vertexTypeDetail )
      {
         // Get detail distance squared to save us from sqrt
         const F32 detailDistanceSquared = TerrainRender::mCurrentBlock->mDetailDistance * TerrainRender::mCurrentBlock->mDetailDistance;

         // Detail Brightness done via assignment of color values
         const U8 colorByte = mClamp( 255 * TerrainRender::mCurrentBlock->mDetailBrightness, 0, 255 );

//.........这里部分代码省略.........
开发者ID:dodong471520,项目名称:pap,代码行数:101,代码来源:terrBatch.cpp

示例14: render

void PlanetRenderImage::render(TSRenderContext &rc)
{
   // A simple planet culling scheme would be to dot the line of sight
   // with the vector from the camera to the planet.  This would eliminate
   // the length test of v below (after m_cross((Point3F)plane, vpNormal, &v))
   GFXSurface *gfxSurface = rc.getSurface();

   gfxSurface->setHazeSource(GFX_HAZE_NONE);
   gfxSurface->setShadeSource(GFX_SHADE_CONSTANT);
   gfxSurface->setAlphaSource(GFX_ALPHA_NONE);
	gfxSurface->setFillMode(GFX_FILL_TEXTURE);
	gfxSurface->setTransparency(FALSE);
   gfxSurface->setTexturePerspective(FALSE);

   gfxSurface->setConstantShade(1.0f);

   int textureHeight;
   gfxSurface->setTextureMap(texture);
   textureHeight = texture->height;
   
   TSCamera *camera = rc.getCamera();
  
   TS::PointArray *pointArray = rc.getPointArray();
   pointArray->reset();
   pointArray->useIntensities(false);
   pointArray->useTextures(textCoord);
   pointArray->useTextures(true);
	pointArray->setVisibility( TS::ClipMask );

   // find out how high the bitmap is at 100% as projected onto the viewport,
   // texel:pixel will be 1:1 at 640x480
   //const RectF &worldVP  = camera->getWorldViewport();
   //const float h = textureHeight*((worldVP.upperL.y - worldVP.lowerR.y)/480.0f);
   //const float sz = 0.5*distance*(h/camera->getNearDist());

   // find the position of the planet
   Point3F displacement = camera->getTCW().p;
   //displacement.z *= -(distance - visibleDistance)/visibleDistance;
   displacement.z = -displacement.z*(distance/(visibleDistance*1.5f));
   Point3F pos = position;
   pos += displacement;
 
   // find the normal to the view plane in world coords
   Point3F v0(0.0f, 1.0f, 0.0f), vpNormal;
   m_mul(v0, (RMat3F)camera->getTCW(), &vpNormal);
   vpNormal.normalize();

   // construct the plane that the camera, planet pos & celestial NP all
   // lie on
   PlaneF plane(pos, camera->getTCW().p, 
      Point3F(displacement.x, displacement.y, displacement.z + distance));

   // the cross product of the VP normal and the normal to the plane just
   // constructed is the up vector for the planet
   Point3F v;
   m_cross((Point3F)plane, vpNormal, &v);
   if (IsEqual(v.len(), 0.0f))
      // planet is directly to the right or left of camera
      return;
   v.normalize();
   
   // cross the up with the normal and we get the right vector
   Point3F u;
   m_cross(vpNormal, v, &u);
   u *= size;
   v *= size;

   TS::VertexIndexPair V[6];
   Point3F ul = pos;
   ul -= u; ul += v;
   V[0].fVertexIndex   = pointArray->addPoint(ul);
   V[0].fTextureIndex  = 0;
   Point3F ur = pos;
   ur += u; ur += v;
   V[1].fVertexIndex   = pointArray->addPoint(ur);
   V[1].fTextureIndex  = 1;
   Point3F lr = pos;
   lr += u; lr -= v;
   V[2].fVertexIndex   = pointArray->addPoint(lr);
   V[2].fTextureIndex  = 2;
   Point3F ll = pos;
   ll -= u; ll -=v;
   V[3].fVertexIndex   = pointArray->addPoint(ll);
   V[3].fTextureIndex  = 3;
	if (gfxSurface->getCaps() & GFX_DEVCAP_SUPPORTS_CONST_ALPHA)
	   gfxSurface->setZTest(GFX_NO_ZTEST);
   pointArray->drawPoly(4, V, 0);
	if (gfxSurface->getCaps() & GFX_DEVCAP_SUPPORTS_CONST_ALPHA)
	   gfxSurface->setZTest(GFX_ZTEST_AND_WRITE);
   if(lensFlare) {
      TS::TransformedVertex vx;
      camera->transformProject(pos, &vx);
      bool vis = vx.fStatus & TS::TransformedVertex::Projected;
      lensFlare->setSunPos(vis, vx.fPoint, pos);
   }
}
开发者ID:AltimorTASDK,项目名称:TribesRebirth,代码行数:96,代码来源:simPlanet.cpp

示例15: space

// warning: a work in progress...not tested yet
bool 
CelAnimMesh::collideBox(int frameIndex,
                        const TMat3F & trans,       // from box to mesh space (box center to origin)
                        const TMat3F & invTrans,    // from mesh to box space
                        const Point3F &radii,
                        CollisionSurface & cs) const
{
   cs;

   int hitface = -1;
   float hitDepth;
   Point3F hitNormal;
   float overlap;

   AssertFatal( fFrames.size() > 0, "Shape must have at least one frame." );
   AssertFatal( frameIndex >= 0 && frameIndex < fFrames.size(),
                "TS::CelAnimMesh: frame index out of range" );
                
   // get the frame struct:
   const Frame *frm = &fFrames[frameIndex];
   int fv = frm->fFirstVert;
   const Point3F *pScale = &frm->fScale;
   const Point3F *pOrigin = &frm->fOrigin;

   int i;
   Point3F v[3],tv[3]; // tv is work space for m_polyOBox...
   for (i=0;i<fFaces.size();i++)
   {
      const Face & theFace = fFaces[i];
      fVerts[theFace.fVIP[0].fVertexIndex+fv].getPoint(v[0],*pScale,*pOrigin);
      fVerts[theFace.fVIP[1].fVertexIndex+fv].getPoint(v[1],*pScale,*pOrigin);
      fVerts[theFace.fVIP[2].fVertexIndex+fv].getPoint(v[2],*pScale,*pOrigin);

      // build the normal
      Point3F normal;
      m_normal(v[0],v[1],v[2],normal);

      if (!m_polyOBox(radii,trans,invTrans,normal,v,tv,3,overlap))
         continue;

/*
      // build the normal
      Point3F normal;
      m_normal(v1,v2,v3,normal);

      float planeDist = m_dot(normal,v1);
      float negBoxDist = m_dot(normal,trans.p); // negative of dist of box from origin
      if (planeDist+negBoxDist<0.0f) // back-face from box center
         continue;

      // does the face's plane intersect the box
      float overlap;
      if (!m_planeOBox(bRadii,trans,normal,planeDist,overlap))
         continue;

      Point3F tv1,tv2,tv3,tMin,tMax;
      m_mul(v1,invTrans,&tv1);
      m_mul(v2,invTrans,&tv2);
      m_mul(v3,invTrans,&tv3);
      tMin=tv1;
      tMin.setMin(tv2);
      tMin.setMin(tv3);
      tMax=tv1;
      tMax.setMax(tv2);
      tMax.setMax(tv3);

      if (tMin.x>bRadii.x)
         continue;
      if (tMax.x<-bRadii.x)
         continue;
      if (tMin.y>bRadii.y)
         continue;
      if (tMax.y<-bRadii.y)
         continue;
      if (tMin.z>bRadii.z)
         continue;
      if (tMax.z<-bRadii.z)
         continue;
*/

      {
         // collision
         hitface = i;
         hitNormal = normal;
         hitDepth = overlap/normal.len();
      }
   }
   hitNormal,hitDepth;
   return hitface!=-1;
}
开发者ID:AltimorTASDK,项目名称:TribesRebirth,代码行数:91,代码来源:ts_CelAnimMesh.cpp


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