Esempio n. 1
0
void BillboardSet::CalculateFixedScreenSize(const FrameInfo& frame)
{
    float invViewHeight = 1.0f / frame.viewSize_.y_;
    float halfViewWorldSize = frame.camera_->GetHalfViewSize();

    if (!frame.camera_->IsOrthographic())
    {
        Matrix4 viewProj(frame.camera_->GetProjection() * frame.camera_->GetView());
        const Matrix3x4& worldTransform = node_->GetWorldTransform();
        Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;

        for (unsigned i = 0; i < billboards_.Size(); ++i)
        {
            Vector4 projPos(viewProj * Vector4(billboardTransform * billboards_[i].position_, 1.0f));
            billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize * projPos.w_;
        }
    }
    else
    {
        for (unsigned i = 0; i < billboards_.Size(); ++i)
            billboards_[i].screenScaleFactor_ = invViewHeight * halfViewWorldSize;
    }

    bufferDirty_ = true;
    forceUpdate_ = true;
    worldBoundingBoxDirty_ = true;
}
Esempio n. 2
0
void weighted_avg(Mesh& m)
{
  std::vector<int>cnt(m.v.size());
  std::vector<Vec3> projPos(m.v.size());
  std::vector<Vec3>nbrPos(m.v.size());
  std::vector<Plane> plane;

  avgNbrPos(m,nbrPos);
  m.get_normal_center();
  get_plane(m,plane);
  //--------
  //  |disp|n
  //  |    |
  //   \   |
  //    \  |
  //     \v|
  for(size_t ii=0;ii<m.t.size();ii++){
    for(int jj=0;jj<3;jj++){
      int vidx = m.t[ii][jj];
      int label = m.t[ii].label;
      real_t d = plane[label].c.dot(plane[label].n);
      real_t disp=m.v[vidx].dot(plane[label].n);
      Vec3 vp=m.v[vidx]+plane[label].n*(d-disp);
      projPos[vidx]+=vp;
      cnt[vidx]++;
    }
  }
  for(size_t ii=0;ii<m.v.size();ii++){
    projPos[ii]/=cnt[ii];
  }

  float wSum=wN+wP+w0+wV;
  wSum=1/wSum;
  for(size_t ii=0;ii<m.v.size();ii++){
    m.v[ii]=wSum*(wN*nbrPos[ii]+
                  wP*projPos[ii]+
                  wV*m.v[ii]+
                  w0*m.v0[ii]);
  }
}
Esempio n. 3
0
void Text3D::CalculateFixedScreenSize(const FrameInfo& frame)
{
    Vector3 worldPosition = node_->GetWorldPosition();
    Vector3 worldScale = node_->GetWorldScale();

    if (fixedScreenSize_)
    {
        float textScaling = 2.0f / TEXT_SCALING / frame.viewSize_.y_;
        float halfViewWorldSize = frame.camera_->GetHalfViewSize();

        if (!frame.camera_->IsOrthographic())
        {
            Matrix4 viewProj(frame.camera_->GetProjection(false) * frame.camera_->GetView());
            Vector4 projPos(viewProj * Vector4(worldPosition, 1.0f));
            worldScale *= textScaling * halfViewWorldSize * projPos.w_;
        }
        else
            worldScale *= textScaling * halfViewWorldSize;
    }

    customWorldTransform_ = Matrix3x4(worldPosition, frame.camera_->GetFaceCameraRotation(
        worldPosition, node_->GetWorldRotation(), faceCameraMode_), worldScale);
    worldBoundingBoxDirty_ = true;
}
/**
 *	This method draws the lens effect.
 */
void LensEffect::draw()
{
	OcclusionLevels::iterator it = occlusionLevels_.begin();
	OcclusionLevels::iterator end = occlusionLevels_.end();

	while (it != end)
	{
		FlareData & flare = it->second;

		if (flare.age() <= OLDEST_LENS_EFFECT)
		{
			float alphaStrength = 1.f - (flare.age() / OLDEST_LENS_EFFECT);

			//calculate distance and projected postiion of flare
			Vector4 projPos( this->position().x, this->position().y, 
							 this->position().z, 1.f );
			Moo::rc().viewProjection().applyPoint( projPos, projPos );

			// If its infront of the screen
			if (projPos.w > 0.f)
			{
				float oow = 1.f / projPos.w;
				projPos.x *= oow;
				projPos.y *= oow;
				projPos.z *= oow;
				projPos.w = oow;

				//calculate distance of flare
				float dist = Vector3( this->position() - 
								Moo::rc().invView().applyToOrigin() ).length();
				
				float scale;
				if (this->maxDistance() != 0.f)
				{
					float t = dist / this->maxDistance();
					t = Math::clamp( 0.f, t, 1.f );
					scale = 1.f - (t*t);
				}
				else
				{
					scale = 0.f;
				}

				if (scale > 0.f)
				{
					flare.draw( projPos, alphaStrength, scale, colour_ );

					//draw secondaries
					FlareData::Flares::const_iterator it = flare.secondaries().begin();
					FlareData::Flares::const_iterator end = flare.secondaries().end();

					while ( it != end )
					{
						FlareData fd = *it++;

						fd.draw( projPos, alphaStrength, scale, colour_ );
					}
				}
			}
		}

		++it;
	}
}