예제 #1
0
// This "rounds" the projection matrix to remove subtexel movement during shadow map
// rasterization.  This is here to reduce shadow shimmering.
void PSSMLightShadowMap::_roundProjection(const MatrixF& lightMat, const MatrixF& cropMatrix, Point3F &offset, U32 splitNum)
{
   // Round to the nearest shadowmap texel, this helps reduce shimmering
   MatrixF currentProj = GFX->getProjectionMatrix();
   currentProj = cropMatrix * currentProj * lightMat;

   // Project origin to screen.
   Point4F originShadow4F(0,0,0,1);
   currentProj.mul(originShadow4F);
   Point2F originShadow(originShadow4F.x / originShadow4F.w, originShadow4F.y / originShadow4F.w);   

   // Convert to texture space (0..shadowMapSize)
   F32 t = mNumSplits < 4 ? mShadowMapTex->getWidth() / mNumSplits : mShadowMapTex->getWidth() / 2;
   Point2F texelsToTexture(t / 2.0f, mShadowMapTex->getHeight() / 2.0f);
   if (mNumSplits >= 4) texelsToTexture.y *= 0.5f;
   originShadow.convolve(texelsToTexture);

   // Clamp to texel boundary
   Point2F originRounded;
   originRounded.x = mFloor(originShadow.x + 0.5f);
   originRounded.y = mFloor(originShadow.y + 0.5f);

   // Subtract origin to get an offset to recenter everything on texel boundaries
   originRounded -= originShadow;

   // Convert back to texels (0..1) and offset
   originRounded.convolveInverse(texelsToTexture);
   offset.x += originRounded.x;
   offset.y += originRounded.y;
}
예제 #2
0
void afxZodiacData::convertGradientRangeFromDegrees(Point2F& gradrange, const Point2F& gradrange_deg)
{
  F32 x = mCos(mDegToRad(gradrange_deg.x));
  F32 y = mCos(mDegToRad(gradrange_deg.y));
  if (y > x)
    gradrange.set(x, y);
  else
    gradrange.set(y, x);
}
예제 #3
0
파일: Mover.cpp 프로젝트: fjz13/Medusa
Point2F Mover::CalculateDrag(float dragMag)
{
	//F drag=-v*v*dragMag
	Point2F drag = -mVelocity;
	drag.Normalize();

	drag *= dragMag;
	drag *= mVelocity.LengthSquared();
	return drag;
}
예제 #4
0
파일: Mover.cpp 프로젝트: fjz13/Medusa
Point2F Mover::CalculateAttract(const Mover& other, float g, float minDistanceSquared/*=1.f*/)
{
	//F=G*m1*m2/(r*r)
	Point2F force = mPosition - other.mPosition;
	float distanceSquared =Math::Max(force.LengthSquared(),minDistanceSquared);

	force.Normalize();
	force *= g*mMass*other.mMass;
	force /= distanceSquared;
	return force;
}
예제 #5
0
파일: Mover.cpp 프로젝트: fjz13/Medusa
Point2F Mover::CalculateFriction(float frictionMag, const Point2F& gravity)
{
	//Friction=-frictionMag*N*v
	//v==mVelocity.Normalize()

	Point2F friction = -mVelocity;
	friction.Normalize();

	friction *= frictionMag;
	friction *= mMass*gravity;
	return friction;
}
예제 #6
0
//=============================================================================
Point2F Rectangle2::center() const
{
    Point2F result;

    Vector2F dir2 = dir();
    dir2.multiply(0.5);
    result.add(dir2);

    Vector2F up2 = up();
    up2.multiply(0.5);
    result.add(up2);

    return result;
}
예제 #7
0
//=============================================================================
Point2F Rectangle2::point( const Point2F& params) const
{
    Vector2F dir(width_);
    dir.multiply(params.x());

    Vector2F up(up_());
    up.multiply(params.y());

    Point2F result(origin_);
    result.add(dir);
    result.add(up);

    return result;
}
예제 #8
0
TEST(Point2, SetMethods) {
    Point2F pt;
    pt.set(4.f, 2.f);
    EXPECT_FLOAT_EQ(4.f, pt.x);
    EXPECT_FLOAT_EQ(2.f, pt.y);

    auto lst = {0.f, 5.f};
    pt.set(lst);
    EXPECT_FLOAT_EQ(0.f, pt.x);
    EXPECT_FLOAT_EQ(5.f, pt.y);

    pt.set(Point2F(9.f, 8.f));
    EXPECT_FLOAT_EQ(9.f, pt.x);
    EXPECT_FLOAT_EQ(8.f, pt.y);
}
예제 #9
0
ColorF toLUV( const ColorF &rgbColor )
{
   static const Point3F scXYZLUVDot( 1.0f, 15.0f, 3.0f );
   static const Point2F sc49( 4.0f, 9.0f );

   ColorF xyzColor = ConvertRGB::toXYZ( rgbColor );

   const Point2F &xyz_xy = *((Point2F *)&xyzColor);

   Point2F uvColor = sc49;
   uvColor.convolve( xyz_xy );
   uvColor /= mDot( *(Point3F *)&xyzColor, scXYZLUVDot );

   return ColorF( uvColor.x, uvColor.y, xyzColor.green, rgbColor.alpha );
}
예제 #10
0
파일: T2lRay2.cpp 프로젝트: ta2la/geogebra
//=============================================================================
Point2F Ray2::getPoint(double parameter, double offset) const
{
    Vector2F delta = dir_;
    delta.multiply(parameter);
    Point2F result =  origin_;
    result.add(delta);

    if (offset == 0.0) return result;

    Vector2F offsetVec = dir_;
    offsetVec.setPerpendLeft();
    offsetVec.multiply( offset/offsetVec.getLength() );
    result.add(offsetVec);

    return result;
}
예제 #11
0
void calculateHandAxisRotation(const MatrixF& handRotation, const F32& maxHandAxisRadius, Point2F& outRotation)
{
   const VectorF& controllerUp = handRotation.getUpVector();
   outRotation.x = controllerUp.x;
   outRotation.y = controllerUp.y;

   // Limit the axis angle to that given to us
   if(outRotation.len() > maxHandAxisRadius)
   {
      outRotation.normalize(maxHandAxisRadius);
   }

   // Renormalize to the range of 0..1
   if(maxHandAxisRadius != 0.0f)
   {
      outRotation /= maxHandAxisRadius;
   }
}
예제 #12
0
void MaterialEditor::onMouseMoveEvent(const GuiEvent &event)
{
   lastMousePoint = event.mousePoint;

   for(S32 n = 0; n < nodeList.size(); ++n )
   {
      Node* node = &nodeList[n];
      node->mouseOver = false;

      if ( event.mousePoint.x >= node->x && event.mousePoint.x <= node->x + node->width
         && event.mousePoint.y >= node->y && event.mousePoint.y <= node->y + node->height )
      {
         node->mouseOver = true;

         for ( S32 i = 0; i < node->inputs.size(); ++i )
         {
            InputPoint* input = &node->inputs[i];
            input->mouseOver = false;

            Point2F dist = input->lastPosition - Point2F(lastMousePoint.x, lastMousePoint.y);
            if (  dist.len() <= 5 )
               input->mouseOver = true;
         }

         for ( S32 i = 0; i < node->outputs.size(); ++i )
         {
            OutputPoint* output = &node->outputs[i];
            output->mouseOver = false;

            Point2F dist = output->lastPosition - Point2F(lastMousePoint.x, lastMousePoint.y);
            if (  dist.len() <= 5 )
               output->mouseOver = true;
         }
      }
   }
}
예제 #13
0
//=============================================================================
Point2F Rectangle2::point(int index) const
{
    while ( index < 0 ) index += 4;
    while ( index > 3 ) index -= 4;

    Point2F result = origin_;

    switch (index)
    {
    case 1:
        result.add(width_);
        break;
    case 2:
        result.add(width_);
    case 3:
        result.add(up_());
        break;
    case 0:
    default:
        break;
    }

    return result;
}
예제 #14
0
void MaterialEditor::renderConnection(Connection* connection)
{
   NVGcontext* vg = Link.Graphics.dglGetNVGContext();
	if (vg)
	{
      Point2F mStart;
      Point2F mEnd;

      if ( connection->outputToMouse )
         mEnd.set(lastMousePoint.x, lastMousePoint.y);
      else {
         Node* endNode = findNode(connection->inputNodeName);
         if ( !endNode || connection->inputIndex >= endNode->inputs.size() ) 
            return;
         mEnd.set(endNode->inputs[connection->inputIndex].lastPosition.x, endNode->inputs[connection->inputIndex].lastPosition.y);
      }

      if ( connection->inputToMouse )
         mStart.set(lastMousePoint.x, lastMousePoint.y);
      else {
         Node* startNode = findNode(connection->outputNodeName);
         if ( !startNode || connection->outputIndex >= startNode->outputs.size() ) 
            return;
         mStart.set(startNode->outputs[connection->outputIndex].lastPosition.x, startNode->outputs[connection->outputIndex].lastPosition.y);
      }

      Point2F mControlPointA(mStart.x + 50, mStart.y);
      Point2F mControlPointB(mEnd.x - 50, mEnd.y);

      F32 diff = (mEnd.y - mStart.y) * 0.25f;
      mControlPointA.y -= diff;
      mControlPointB.y += diff;

		Link.NanoVG.nvgBeginPath(vg);
		Link.NanoVG.nvgMoveTo(vg, mStart.x, mStart.y);
		Link.NanoVG.nvgBezierTo(vg, mControlPointA.x, mControlPointA.y, 
                                  mControlPointB.x, mControlPointB.y, 
                                  mEnd.x, mEnd.y);
		Link.NanoVG.nvgStrokeColor(vg, Link.NanoVG.nvgRGBA(255, 255, 255, 200));
		Link.NanoVG.nvgStrokeWidth(vg, 5.0f);
		Link.NanoVG.nvgStroke(vg);
   }
}
예제 #15
0
void PxCloth::unpackUpdate( NetConnection *conn, BitStream *stream )
{
   Parent::unpackUpdate( conn, stream );

   // TransformMask
   if ( stream->readFlag() )
   {
      MatrixF mat;
      mathRead( *stream, &mat );
   // start jc
      if(mCloth)
      {
         NxVec3 delta(mat.getPosition() - getTransform().getPosition());

         if(mCloth->isSleeping())
            mCloth->wakeUp();

         if ( mAttachmentMask & BIT( 0 ) )
            mCloth->attachVertexToGlobalPosition( 0, mCloth->getPosition( 0 ) + delta );
         if ( mAttachmentMask & BIT( 1 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x-1, mCloth->getPosition( mPatchVerts.x-1 ) + delta );   
         if ( mAttachmentMask & BIT( 2 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x, mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x ) + delta );
         if ( mAttachmentMask & BIT( 3 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - 1, mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - 1 ) + delta );   
         if ( mAttachmentMask & BIT( 4 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2), mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2) ) + delta );
         if ( mAttachmentMask & BIT( 5 ) )
            mCloth->attachVertexToGlobalPosition( (mPatchVerts.x/2), mCloth->getPosition( (mPatchVerts.x/2) ) + delta );
         if ( mAttachmentMask & BIT( 6 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2), mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) ) + delta );
         if ( mAttachmentMask & BIT( 7 ) )
            mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1), mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1) ) + delta );
         
         if ( mAttachmentMask & BIT( 8 ) )
            for ( U32 i = mPatchVerts.x * mPatchVerts.y - mPatchVerts.x; i < mPatchVerts.x * mPatchVerts.y; i++ )
               mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta );
         
         if ( mAttachmentMask & BIT( 9 ) )
            for ( U32 i = 0; i < mPatchVerts.x; i++ )
               mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta );

         if ( mAttachmentMask & BIT( 10 ) )
            for ( U32 i = 0; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x )
               mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta );

         if ( mAttachmentMask & BIT( 11 ) )
            for ( U32 i = mPatchVerts.x-1; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x )
               mCloth->attachVertexToGlobalPosition( i, mCloth->getPosition( i ) + delta );
      }
   // end jc


      setTransform( mat );
   }

// start jc
   // ScaleAttachmentPointsMask
   if ( stream->readFlag() )
   {
      Point3F attachmentPointScale;
      mathRead( *stream, &attachmentPointScale );

      if(mCloth)
      {
         Point3F scale(Point3F::One);
         scale.convolveInverse(mAttachmentPointScale);
         scale.convolve(attachmentPointScale);
         NxVec3 delta(scale);

         if(mCloth->isSleeping())
            mCloth->wakeUp();

         static NxVec3 delta2;
         if ( mAttachmentMask & BIT( 0 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( 0 ),delta);                                                       mCloth->attachVertexToGlobalPosition( 0, delta2); }
         if ( mAttachmentMask & BIT( 1 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x-1 ), delta);                                        mCloth->attachVertexToGlobalPosition( mPatchVerts.x-1, delta2); } 
         if ( mAttachmentMask & BIT( 2 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x ), delta);          mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - mPatchVerts.x, delta2); }
         if ( mAttachmentMask & BIT( 3 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - 1 ), delta);                      mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - 1, delta2); }
         if ( mAttachmentMask & BIT( 4 ) )
         {   delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2) ), delta);     mCloth->attachVertexToGlobalPosition( mPatchVerts.x * mPatchVerts.y - (mPatchVerts.x/2), delta2); }
         if ( mAttachmentMask & BIT( 5 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( (mPatchVerts.x/2) ), delta);                                      mCloth->attachVertexToGlobalPosition( (mPatchVerts.x/2), delta2); }
         if ( mAttachmentMask & BIT( 6 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) ), delta);                      mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2), delta2); }
         if ( mAttachmentMask & BIT( 7 ) )
         {  delta2.arrayMultiply(mCloth->getPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1) ), delta);  mCloth->attachVertexToGlobalPosition( mPatchVerts.x * (mPatchVerts.y/2) + (mPatchVerts.x-1), delta2); }
         
         if ( mAttachmentMask & BIT( 8 ) )
            for ( U32 i = mPatchVerts.x * mPatchVerts.y - mPatchVerts.x; i < mPatchVerts.x * mPatchVerts.y; i++ )
               {   delta2.arrayMultiply(mCloth->getPosition( i ), delta);     mCloth->attachVertexToGlobalPosition( i, delta2); }
         
         if ( mAttachmentMask & BIT( 9 ) )
            for ( U32 i = 0; i < mPatchVerts.x; i++ )
               {   delta2.arrayMultiply(mCloth->getPosition( i ), delta);     mCloth->attachVertexToGlobalPosition( i, delta2); }

         if ( mAttachmentMask & BIT( 10 ) )
            for ( U32 i = 0; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x )
               {   delta2.arrayMultiply(mCloth->getPosition( i ), delta);     mCloth->attachVertexToGlobalPosition( i, delta2); }

         if ( mAttachmentMask & BIT( 11 ) )
            for ( U32 i = mPatchVerts.x-1; i < mPatchVerts.x * mPatchVerts.y; i+=mPatchVerts.x )
               {   delta2.arrayMultiply(mCloth->getPosition( i ), delta);     mCloth->attachVertexToGlobalPosition( i, delta2); }
      }

      mAttachmentPointScale = attachmentPointScale;
   }
// end jc

   // MaterialMask
   if ( stream->readFlag() )
   {
      stream->read( &mMaterialName );
      SAFE_DELETE( mMatInst );
   }

   // ClothMask
   if ( stream->readFlag() )
   {
      Point2I patchVerts;
      Point2F patchSize;
      mathRead( *stream, &patchVerts );
      mathRead( *stream, &patchSize );

      if (  patchVerts != mPatchVerts ||
            !patchSize.equal( mPatchSize ) )
      {
         mPatchVerts = patchVerts;
         mPatchSize = patchSize;
         _releaseMesh();
      }

      U32 attachMask;
      stream->read( &attachMask );
      if ( attachMask != mAttachmentMask )
      {
         mAttachmentMask = attachMask;
         _releaseCloth();
      }

      mBendingEnabled = stream->readFlag();
      mDampingEnabled = stream->readFlag();
      mTriangleCollisionEnabled = stream->readFlag();
      mSelfCollisionEnabled = stream->readFlag();
      stream->read( &mThickness );
      stream->read( &mFriction );
      stream->read( &mBendingStiffness );
      stream->read( &mDampingCoefficient );

      F32 density;
      stream->read( &density );
      if ( density != mDensity )
      {
         mDensity = density;
         _releaseCloth();
      }

      if (  isClientObject() && 
            isProperlyAdded() &&
            mWorld &&
            !mCloth )
      {
         _createClothPatch();
      }

      _updateClothProperties();
   }
}
예제 #16
0
void PSSMLightShadowMap::setShaderParameters(GFXShaderConstBuffer* params, LightingShaderConstants* lsc)
{
   PROFILE_SCOPE( PSSMLightShadowMap_setShaderParameters );

   AssertFatal(mNumSplits > 0 && mNumSplits <= MAX_SPLITS,
      avar("PSSMLightShadowMap::_setNumSplits() - Splits must be between 1 and %d!", MAX_SPLITS));

   if ( lsc->mTapRotationTexSC->isValid() )
      GFX->setTexture( lsc->mTapRotationTexSC->getSamplerRegister(), 
                        SHADOWMGR->getTapRotationTex() );

   const ShadowMapParams *p = mLight->getExtended<ShadowMapParams>();

   Point4F  sx(Point4F::Zero), 
            sy(Point4F::Zero),
            ox(Point4F::Zero), 
            oy(Point4F::Zero), 
            aXOff(Point4F::Zero), 
            aYOff(Point4F::Zero);

   for (U32 i = 0; i < mNumSplits; i++)
   {
      sx[i] = mScaleProj[i].x;
      sy[i] = mScaleProj[i].y;
      ox[i] = mOffsetProj[i].x;
      oy[i] = mOffsetProj[i].y;
   }

   Point2F shadowMapAtlas;
   if (mNumSplits < 4)
   {
      shadowMapAtlas.x = 1.0f / (F32)mNumSplits;
      shadowMapAtlas.y = 1.0f;
   
      // 1xmNumSplits
      for (U32 i = 0; i < mNumSplits; i++)
         aXOff[i] = (F32)i * shadowMapAtlas.x;
   }
   else
   {
      shadowMapAtlas.set(0.5f, 0.5f);
  
      // 2x2
      for (U32 i = 0; i < mNumSplits; i++)
      {
         if (i == 1 || i == 3)
            aXOff[i] = 0.5f;
         if (i > 1)
            aYOff[i] = 0.5f;
      }
   }

   params->setSafe(lsc->mScaleXSC, sx);
   params->setSafe(lsc->mScaleYSC, sy);
   params->setSafe(lsc->mOffsetXSC, ox);
   params->setSafe(lsc->mOffsetYSC, oy);
   params->setSafe(lsc->mAtlasXOffsetSC, aXOff);
   params->setSafe(lsc->mAtlasYOffsetSC, aYOff);
   params->setSafe(lsc->mAtlasScaleSC, shadowMapAtlas);

   Point4F lightParams( mLight->getRange().x, p->overDarkFactor.x, 0.0f, 0.0f );
   params->setSafe( lsc->mLightParamsSC, lightParams );
      
   params->setSafe( lsc->mFarPlaneScalePSSM, mFarPlaneScalePSSM);

   Point2F fadeStartLength(p->fadeStartDist, 0.0f);
   if (fadeStartLength.x == 0.0f)
   {
      // By default, lets fade the last half of the last split.
      fadeStartLength.x = (mSplitDist[mNumSplits-1] + mSplitDist[mNumSplits]) / 2.0f;
   }
   fadeStartLength.y = 1.0f / (mSplitDist[mNumSplits] - fadeStartLength.x);
   params->setSafe( lsc->mFadeStartLength, fadeStartLength);
   
   params->setSafe( lsc->mOverDarkFactorPSSM, p->overDarkFactor);

   // The softness is a factor of the texel size.
   params->setSafe( lsc->mShadowSoftnessConst, p->shadowSoftness * ( 1.0f / mTexSize ) );
}
예제 #17
0
 void PathSerializer::WritePoint(const Point2F& point) {
     result << point.GetX() << ' ' << point.GetY() << ' ';
 }
예제 #18
0
void PxCloth::unpackUpdate( NetConnection *conn, BitStream *stream )
{
   Parent::unpackUpdate( conn, stream );

   // TransformMask
   if ( stream->readFlag() )
   {
      MatrixF mat;
      mathRead( *stream, &mat );
      setTransform( mat );
   }

   // MaterialMask
   if ( stream->readFlag() )
   {
      stream->read( &mMaterialName );
      SAFE_DELETE( mMatInst );
   }

   // ClothMask
   if ( stream->readFlag() )
   {
      Point2I patchVerts;
      Point2F patchSize;
      mathRead( *stream, &patchVerts );
      mathRead( *stream, &patchSize );

      if (  patchVerts != mPatchVerts ||
            !patchSize.equal( mPatchSize ) )
      {
         mPatchVerts = patchVerts;
         mPatchSize = patchSize;
         _releaseMesh();
      }

      U32 attachMask;
      stream->read( &attachMask );
      if ( attachMask != mAttachmentMask )
      {
         mAttachmentMask = attachMask;
         _releaseCloth();
      }

      mBendingEnabled = stream->readFlag();
      mDampingEnabled = stream->readFlag();
      mTriangleCollisionEnabled = stream->readFlag();
      mSelfCollisionEnabled = stream->readFlag();
      stream->read( &mThickness );
      stream->read( &mFriction );
      stream->read( &mBendingStiffness );
      stream->read( &mDampingCoefficient );

      F32 density;
      stream->read( &density );
      if ( density != mDensity )
      {
         mDensity = density;
         _releaseCloth();
      }

      if (  isClientObject() && 
            isProperlyAdded() &&
            mWorld &&
            !mCloth )
      {
         _createClothPatch();
      }

      _updateClothProperties();
   }
}
예제 #19
0
void Scene::render() {
#ifdef GL_33
	//Light
	glUniform3fv(lightDirectionLocation, 1, &lightDirection.x);
	glUniform4fv(lightColorLocation, 1, &lightColor.red);
	glUniform4fv(ambientColorLocation, 1, &ambientColor.red);

	glUniform3fv(sunPositionLocation, 1, &sunPosition.x);
	glUniform1f(sunPowerLocation, sunPower);
	glUniform1f(specularExponentLocation, specularExponent);

	//Camera
	viewMatrix = glm::mat4x4(1);
	viewMatrix = glm::rotate(viewMatrix, pitch, glm::vec3(1, 0, 0));
	viewMatrix = glm::rotate(viewMatrix, yaw, glm::vec3(0, 1, 0));
	viewMatrix = glm::rotate(viewMatrix, -90.0f, glm::vec3(1, 0, 0));
	viewMatrix = glm::translate(viewMatrix, -cameraPosition);

	//Model
	modelMatrix = glm::mat4x4(1);

	//Combined
	glm::mat4x4 mvpMat = projectionMatrix * viewMatrix * modelMatrix;
	glm::mat3x3 mv3Mat = glm::mat3(viewMatrix * modelMatrix);

	//Send to OpenGL
	glUniformMatrix4fv(mvpMatrixLocation, 1, GL_FALSE, &mvpMat[0][0]);
	glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);
	glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);
	glUniformMatrix3fv(modelView3Location, 1, GL_FALSE, &mv3Mat[0][0]);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor(0.5f, 0.5f, 0.5f, 1.0f);

	glEnable(GL_CULL_FACE);
	glEnable(GL_ALPHA);
	glEnable(GL_MULTISAMPLE);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	for (U32 index = 0; index < difCount; index ++) {
		difs[index]->render();
	}

#ifdef BUILD_PHYSICS
	Point3F pos = sphere->getPosition();
	AngAxisF rot = sphere->getRotation();

	//Model
	modelMatrix = glm::mat4x4(1);
	modelMatrix = glm::translate(modelMatrix, glm::vec3(pos.x, pos.y, pos.z));
	modelMatrix = glm::rotate(modelMatrix, rot.angle * (F32)(180.0f / M_PI), glm::vec3(rot.axis.x, rot.axis.y, rot.axis.z));

	//Combined
	mvpMat = projectionMatrix * viewMatrix * modelMatrix;

	//Send to OpenGL
	glUniformMatrix4fv(mvpMatrixLocation, 1, GL_FALSE, &mvpMat[0][0]);
	glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);
	glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &viewMatrix[0][0]);

	sphere->render(ColorF(1, 1, 0, 1));
#endif
#else
	//Load the model matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_CULL_FACE);
	glEnable(GL_ALPHA);
	glEnable(GL_MULTISAMPLE);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//Camera
	viewMatrix = glm::mat4x4(1);
	viewMatrix = glm::rotate(viewMatrix, pitch, glm::vec3(1, 0, 0));
	viewMatrix = glm::rotate(viewMatrix, yaw, glm::vec3(0, 1, 0));
	viewMatrix = glm::rotate(viewMatrix, -90.0f, glm::vec3(1, 0, 0));
	//	viewMatrix = glm::translate(viewMatrix, -cameraPosition);
	viewMatrix = glm::translate(viewMatrix, cameraPosition);

	glLoadMatrixf(&modelviewMatrix[0][0]);

	//Clear
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
	glLightfv(GL_LIGHT0, GL_POSITION, gLightDirection);

	Point3F offset = {0.f, 0.f, 0.f};

	if (listNeedsDisplay) {
		displayList = glGenLists(1);
		glNewList(displayList, GL_COMPILE_AND_EXECUTE);
		for (U32 index = 0; index < difCount; index ++) {
			difs[index]->render();
		}
		glEndList();
		listNeedsDisplay = false;
	} else {
		glCallList(displayList);
	}

	sphere->render(ColorF(1, 1, 0, 1));
	glDisable(GL_CULL_FACE);

	if (selection.hasSelection) {
		Surface surface = selection.interior->surface[selection.surfaceIndex];
		TexGenEq texGenEq = selection.interior->texGenEq[surface.texGenIndex];
		Point3F normal = selection.interior->normal[selection.interior->plane[surface.planeIndex].normalIndex];
		Point3F first = selection.interior->point[selection.interior->index[surface.windingStart]];
		F32 len = 0;

		glBegin(GL_TRIANGLE_STRIP);
		for (U32 i = 0; i < surface.windingCount; i ++) {
			Point3F vert = selection.interior->point[selection.interior->index[surface.windingStart + i]];

			glVertex3f(vert.x, vert.y, vert.z);

			Point2F point = point3F_project_plane(vert, normal, first);
			F32 distance = point.length();
			len = (distance > len ? distance : len);
		}
		glEnd();

		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(-1, 1, -1, 1, -100, 100);
		glMatrixMode(GL_MODELVIEW);
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		glLoadIdentity();

		Texture *texture = selection.interior->texture[surface.textureIndex];
		if (texture) {
			if (!texture->generated) {
				texture->generateBuffer();
			}
			texture->activate();
		}

		glBegin(GL_TRIANGLE_STRIP);

		int w, h;
		SDL_GetWindowSize(window, &w, &h);

		GLfloat aspect = (GLfloat)w / (GLfloat)h;

		for (U32 i = 0; i < surface.windingCount; i ++) {
			Point3F vert = selection.interior->point[selection.interior->index[surface.windingStart + i]];

			Point2F texuv = Point2F(planeF_distance_to_point(texGenEq.planeX, vert), planeF_distance_to_point(texGenEq.planeY, vert));
			glTexCoord2fv(&texuv.x);

			Point2F point = point3F_project_plane(vert, (surface.planeFlipped ? normal * -1 : normal), first);
			glVertex3f(point.x / len / aspect, point.y / len, 0);
		}
		glEnd();

		if (texture)
			texture->deactivate();
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_LIGHTING);
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	}
#endif
}
예제 #20
0
namespace PrimBuild
{
Vector<GFXVertexPCT> mTempVertBuff;
GFXVertexBufferHandle<GFXVertexPCT> mVertBuff;
GFXPrimitiveType  mType;
U32               mCurVertIndex;
ColorI            mCurColor( 255, 255, 255 );
Point2F           mCurTexCoord;
const ColorI      _colWhite( 255, 255, 255, 255 );

#ifdef TORQUE_DEBUG
U32 mMaxVerts;

#define INIT_VERTEX_SIZE(x) mMaxVerts = x;
#define VERTEX_BOUNDS_CHECK() AssertFatal( mCurVertIndex < mMaxVerts, "PrimBuilder encountered an out of bounds vertex! Break and debug!" );

// This next check shouldn't really be used a lot unless you are tracking down
// a specific bug. -pw
#define VERTEX_SIZE_CHECK() AssertFatal( mCurVertIndex <= mMaxVerts, "PrimBuilder allocated more verts than you used! Break and debug or rendering artifacts could occur." );

#else

#define INIT_VERTEX_SIZE(x)
#define VERTEX_BOUNDS_CHECK()
#define VERTEX_SIZE_CHECK()

#endif

//-----------------------------------------------------------------------------
// begin
//-----------------------------------------------------------------------------
void begin( GFXPrimitiveType type, U32 maxVerts )
{
   AssertFatal( type >= GFXPT_FIRST && type < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );

   mType = type;
   mCurVertIndex = 0;
   INIT_VERTEX_SIZE( maxVerts );
   mTempVertBuff.setSize( maxVerts );
}

void beginToBuffer( GFXPrimitiveType type, U32 maxVerts )
{
   AssertFatal( type >= GFXPT_FIRST && type < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );

   mType = type;
   mCurVertIndex = 0;
   INIT_VERTEX_SIZE( maxVerts );
   mTempVertBuff.setSize( maxVerts );
}

//-----------------------------------------------------------------------------
// end
//-----------------------------------------------------------------------------
GFXVertexBuffer * endToBuffer( U32 &numPrims )
{
   mVertBuff.set(GFX, mTempVertBuff.size(), GFXBufferTypeVolatile);
   GFXVertexPCT *verts = mVertBuff.lock();
   dMemcpy( verts, mTempVertBuff.address(), mTempVertBuff.size() * sizeof(GFXVertexPCT) );
   mVertBuff.unlock();

   VERTEX_SIZE_CHECK();

   switch( mType )
   {
      case GFXPointList:
      {
         numPrims = mCurVertIndex;
         break;
      }

      case GFXLineList:
      {
         numPrims = mCurVertIndex / 2;
         break;
      }

      case GFXLineStrip:
      {
         numPrims = mCurVertIndex - 1;
         break;
      }

      case GFXTriangleList:
      {
         numPrims = mCurVertIndex / 3;
         break;
      }

      case GFXTriangleStrip:
      case GFXTriangleFan:
      {
         numPrims = mCurVertIndex - 2;
         break;
      }
      case GFXPT_COUNT:
         // handle warning
         break;
   }

   return mVertBuff;
}

void end( bool useGenericShaders )
{
   if ( mCurVertIndex == 0 ) 
      return; 

   VERTEX_SIZE_CHECK();

   U32 vertStride = 1;
   U32 stripStart = 0;

   AssertFatal( mType >= GFXPT_FIRST && mType < GFXPT_COUNT, "PrimBuilder::end() - Bad primitive type!" );
               
   switch( mType )
   {
      default:
      case GFXPointList:
      {
         vertStride = 1;
         break;
      }

      case GFXLineList:
      {
         vertStride = 2;
         break;
      }

      case GFXTriangleList:
      {
         vertStride = 3;
         break;
      }

      case GFXLineStrip:
      {
         stripStart = 1;
         vertStride = 1;
         break;
      }

      case GFXTriangleStrip:
      case GFXTriangleFan:
      {
         stripStart = 2;
         vertStride = 1;
         break;
      }
   }

   if ( useGenericShaders )
      GFX->setupGenericShaders( GFXDevice::GSModColorTexture );

   const GFXVertexPCT *srcVerts = mTempVertBuff.address();
   U32 numVerts = mCurVertIndex;
   
   // Make sure we don't have a dirty prim buffer left.
   GFX->setPrimitiveBuffer( NULL );

   if ( stripStart > 0 )
   {
      // TODO: Fix this to allow > MAX_DYNAMIC_VERTS!

      U32 copyVerts = getMin( (U32)MAX_DYNAMIC_VERTS, numVerts );
      mVertBuff.set( GFX, copyVerts, GFXBufferTypeVolatile );

      GFXVertexPCT *verts = mVertBuff.lock();
      dMemcpy( verts, srcVerts, copyVerts * sizeof( GFXVertexPCT ) );
      mVertBuff.unlock();

      U32 numPrims = ( copyVerts / vertStride ) - stripStart;
      GFX->setVertexBuffer( mVertBuff );
      GFX->drawPrimitive( mType, 0, numPrims );
   }
   else
   {
      while ( numVerts > 0 )
      {
         U32 copyVerts = getMin( (U32)MAX_DYNAMIC_VERTS, numVerts );
         copyVerts -= copyVerts % vertStride;

         mVertBuff.set( GFX, copyVerts, GFXBufferTypeVolatile );

         GFXVertexPCT *verts = mVertBuff.lock();
         dMemcpy( verts, srcVerts, copyVerts * sizeof( GFXVertexPCT ) );
         mVertBuff.unlock();

         U32 numPrims = copyVerts / vertStride;
         GFX->setVertexBuffer( mVertBuff );
         GFX->drawPrimitive( mType, 0, numPrims );

         srcVerts += copyVerts;
         numVerts -= copyVerts;
      }
   }
}

//-----------------------------------------------------------------------------
// vertex2f
//-----------------------------------------------------------------------------
void vertex2f( F32 x, F32 y )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.x = x;
   vert->point.y = y;
   vert->point.z = 0.0;
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex3f
//-----------------------------------------------------------------------------
void vertex3f( F32 x, F32 y, F32 z )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.x = x;
   vert->point.y = y;
   vert->point.z = z;
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex3fv
//-----------------------------------------------------------------------------
void vertex3fv( const F32 *data )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.set( data[0], data[1], data[2] );
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}

//-----------------------------------------------------------------------------
// vertex2fv
//-----------------------------------------------------------------------------
void vertex2fv( const F32 *data )
{
   VERTEX_BOUNDS_CHECK();
   GFXVertexPCT *vert = &mTempVertBuff[mCurVertIndex++];

   vert->point.set( data[0], data[1], 0.f );
   vert->color = mCurColor;
   vert->texCoord = mCurTexCoord;
}



//-----------------------------------------------------------------------------
// color
//-----------------------------------------------------------------------------
void color( const ColorI &inColor )
{
   mCurColor = inColor;
}

void color( const ColorF &inColor )
{
   mCurColor = inColor;
}

void color3i( U8 red, U8 green, U8 blue )
{
   mCurColor.set( red, green, blue );
}

void color4i( U8 red, U8 green, U8 blue, U8 alpha )
{
   mCurColor.set( red, green, blue, alpha );
}

void color3f( F32 red, F32 green, F32 blue )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ) );
}

void color4f( F32 red, F32 green, F32 blue, F32 alpha )
{
   mCurColor.set( U8( red * 255 ), U8( green * 255 ), U8( blue * 255 ), U8( alpha * 255 ) );
}


//-----------------------------------------------------------------------------
// texCoord
//-----------------------------------------------------------------------------
void texCoord2f( F32 x, F32 y )
{
   mCurTexCoord.set( x, y );
}

void shutdown()
{
   mVertBuff = NULL;
}

}  // namespace PrimBuild
예제 #21
0
//-----------------------------------------------------------------------------
// texCoord
//-----------------------------------------------------------------------------
void texCoord2f( F32 x, F32 y )
{
   mCurTexCoord.set( x, y );
}