예제 #1
0
파일: triosc.cpp 프로젝트: czestmyr/Brewsic
TripleOscillatorGui::TripleOscillatorGui(SafePtr<IControl> parent, TripleOscillator* osc):
	_osc(osc),
	Window(parent, 0, 0, 240, 260, osc->getSynthName().c_str()) {

	SafePtr<IControl> slider = safe_new(Slider(safePtr(), 0, 0, 0, -400, 600, &osc->_shift));
	SafePtr<IControl> frame = safe_new(Frame(safePtr(), 0, 0, 0, 0, 0));

        frame->adopt(osc->_adsr[0]->getGui());

	SafePtr<IControl> label1 = safe_new(Label(frame, 0, 0, "First oscillator"));

	SafePtr<IControl> frame3 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel1 = safe_new(PictureSelector(frame3, 0, 0, 32, 32, &osc->_first_gen)).cast<PictureSelector>();
	SafePtr<IControl> exp = safe_new(IControl(frame3));  // expander to make pselector go left

	frame3->setPreferedSize(0, 34, 1);
	frame3->packHorizontally(5);

	SafePtr<IControl> label2 = safe_new(Label(frame, 0, 0, "Second oscillator"));

	SafePtr<IControl> frame1 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel2 = safe_new(PictureSelector(frame1, 0, 0, 32, 32, &osc->_second_gen)).cast<PictureSelector>();
	SafePtr<IControl> wheel1_label = safe_new(Label(frame1, 0, 0, "Detune osc2"));
	SafePtr<IControl> wheel1 = safe_new(Wheel(frame1, 30, 5, 20, 20, -100.0, 100.0, &_osc->_first));
	wheel1_label->setPreferedSize(100, 20, 1);

	frame1->setPreferedSize(0, 34, 1);
	frame1->packHorizontally(5);

	SafePtr<IControl> label3 = safe_new(Label(frame, 0, 0, "Third oscillator"));

	SafePtr<IControl> frame2 = safe_new(Frame(frame, 0, 0, 0, 0, 0));
	SafePtr<PictureSelector> psel3 = safe_new(PictureSelector(frame2, 0, 0, 32, 32, &osc->_third_gen)).cast<PictureSelector>();
	SafePtr<IControl> wheel2_label = safe_new(Label(frame2, 0, 0, "Detune osc3"));
	SafePtr<IControl> wheel2 = safe_new(Wheel(frame2, 30, 5, 20, 20, -100.0, 100.0, &_osc->_second));
	wheel2_label->setPreferedSize(100, 20, 1);

	frame2->setPreferedSize(0, 34, 1);
	frame2->packHorizontally(5);

	frame->packVertically(5);

	packHorizontally(5);

	// Add generator images to picture selectors
	for (int i = 0; i < (int)GEN_NUMBER; ++i) {
		const char* filename = GeneratorFactory::inst()->getGeneratorPictureFilename((GeneratorType)i);
		psel1->addPicture(filename);
		psel2->addPicture(filename);
		psel3->addPicture(filename);
	}
}
예제 #2
0
파일: mixer.cpp 프로젝트: czestmyr/Brewsic
MixerGui::MixerGui(SafePtr<IControl> parent, MainMixer* mixer)
: Window(parent, 0, 0, 600, 300, "Main mixer"), _mixer(mixer) {
  SafePtr<IControl> hframe = safe_new(Frame(safePtr(), 0, 0, 600, 300, 0));

  // Main volume controls
  SafePtr<IControl> frame = safe_new(Frame(hframe, 0, 0, 20, 300, 0));
  SafePtr<Label> header  = safe_new(Label(frame, 0, 20, "M")).cast<Label>();
  SafePtr<Slider> slider = safe_new(Slider(frame, 0, 40, 280, 0.0, 1.5, &_mixer->getMasterVolume()->_vol, 50)).cast<Slider>();

  header->setPreferedSize(0, 14, 1);
  slider->setPreferedSize(0, 0, 1);

  frame->packVertically(5);
  frame->setPreferedSize(0, 0, 1);

  for (int i = 0; i < _mixer->getChannels(); ++i) {
    char buffer[16];
    sprintf(buffer, "Ch.%i", i+1);

    SafePtr<IControl> frame = safe_new(Frame(hframe, 0, 0, 20, 300, 0));
    SafePtr<Button> button = safe_new(Button(frame, 0, 0, "SQ.", mixer->getSynthQueue(i)->showGuiAction())).cast<Button>();
    SafePtr<Label> header  = safe_new(Label(frame, 0, 20, buffer)).cast<Label>();
    SafePtr<Slider> slider = safe_new(Slider(frame, 0, 40, 280, 0.0, 1.5, &_mixer->getVolume(i)->_vol, 50)).cast<Slider>();

    button->setPreferedSize(0, 22, 1);
    header->setPreferedSize(0, 14, 1);
    slider->setPreferedSize(0, 0, 1);

    frame->packVertically(5);
    frame->setPreferedSize(0, 0, 1);
  }

  hframe->packHorizontally(5);
}
예제 #3
0
파일: item.cpp 프로젝트: Bloodknight/GMK
void Item::updatePos(const U32 /*mask*/, const F32 dt)
{
   // Try and move
   Point3F pos;
   mObjToWorld.getColumn(3,&pos);
   delta.posVec = pos;

   bool contact = false;
   bool nonStatic = false;
   bool stickyNotify = false;
   CollisionList collisionList;
   F32 time = dt;

   static Polyhedron sBoxPolyhedron;
   static ExtrudedPolyList sExtrudedPolyList;
   static EarlyOutPolyList sEarlyOutPolyList;
   MatrixF collisionMatrix(true);
   Point3F end = pos + mVelocity * time;
   U32 mask = isServerObject() ? sServerCollisionMask : sClientCollisionMask;

   // Part of our speed problem here is that we don't track contact surfaces, like we do
   //  with the player.  In order to handle the most common and performance impacting
   //  instance of this problem, we'll use a ray cast to detect any contact surfaces below
   //  us.  This won't be perfect, but it only needs to catch a few of these to make a
   //  big difference.  We'll cast from the top center of the bounding box at the tick's
   //  beginning to the bottom center of the box at the end.
   Point3F startCast((mObjBox.minExtents.x + mObjBox.maxExtents.x) * 0.5,
                     (mObjBox.minExtents.y + mObjBox.maxExtents.y) * 0.5,
                     mObjBox.maxExtents.z);
   Point3F endCast((mObjBox.minExtents.x + mObjBox.maxExtents.x) * 0.5,
                   (mObjBox.minExtents.y + mObjBox.maxExtents.y) * 0.5,
                   mObjBox.minExtents.z);
   collisionMatrix.setColumn(3, pos);
   collisionMatrix.mulP(startCast);
   collisionMatrix.setColumn(3, end);
   collisionMatrix.mulP(endCast);
   RayInfo rinfo;
   bool doToughCollision = true;
   disableCollision();
   if (mCollisionObject)
      mCollisionObject->disableCollision();
   if (getContainer()->castRay(startCast, endCast, mask, &rinfo))
   {
      F32 bd = -mDot(mVelocity, rinfo.normal);

      if (bd >= 0.0)
      {
         // Contact!
         if (mDataBlock->sticky && rinfo.object->getTypeMask() & (STATIC_COLLISION_TYPEMASK)) {
            mVelocity.set(0, 0, 0);
            mAtRest = true;
            mAtRestCounter = 0;
            stickyNotify = true;
            mStickyCollisionPos    = rinfo.point;
            mStickyCollisionNormal = rinfo.normal;
            doToughCollision = false;;
         } else {
            // Subtract out velocity into surface and friction
            VectorF fv = mVelocity + rinfo.normal * bd;
            F32 fvl = fv.len();
            if (fvl) {
               F32 ff = bd * mDataBlock->friction;
               if (ff < fvl) {
                  fv *= ff / fvl;
                  fvl = ff;
               }
            }
            bd *= 1 + mDataBlock->elasticity;
            VectorF dv = rinfo.normal * (bd + 0.002);
            mVelocity += dv;
            mVelocity -= fv;

            // Keep track of what we hit
            contact = true;
            U32 typeMask = rinfo.object->getTypeMask();
            if (!(typeMask & StaticObjectType))
               nonStatic = true;
            if (isServerObject() && (typeMask & ShapeBaseObjectType)) {
               ShapeBase* col = static_cast<ShapeBase*>(rinfo.object);
               queueCollision(col,mVelocity - col->getVelocity());
            }
         }
      }
   }
   enableCollision();
   if (mCollisionObject)
      mCollisionObject->enableCollision();

   if (doToughCollision)
   {
      U32 count;
      for (count = 0; count < 3; count++)
      {
         // Build list from convex states here...
         end = pos + mVelocity * time;


         collisionMatrix.setColumn(3, end);
         Box3F wBox = getObjBox();
         collisionMatrix.mul(wBox);
         Box3F testBox = wBox;
         Point3F oldMin = testBox.minExtents;
         Point3F oldMax = testBox.maxExtents;
         testBox.minExtents.setMin(oldMin + (mVelocity * time));
         testBox.maxExtents.setMin(oldMax + (mVelocity * time));

         sEarlyOutPolyList.clear();
         sEarlyOutPolyList.mNormal.set(0,0,0);
         sEarlyOutPolyList.mPlaneList.setSize(6);
         sEarlyOutPolyList.mPlaneList[0].set(wBox.minExtents,VectorF(-1,0,0));
         sEarlyOutPolyList.mPlaneList[1].set(wBox.maxExtents,VectorF(0,1,0));
         sEarlyOutPolyList.mPlaneList[2].set(wBox.maxExtents,VectorF(1,0,0));
         sEarlyOutPolyList.mPlaneList[3].set(wBox.minExtents,VectorF(0,-1,0));
         sEarlyOutPolyList.mPlaneList[4].set(wBox.minExtents,VectorF(0,0,-1));
         sEarlyOutPolyList.mPlaneList[5].set(wBox.maxExtents,VectorF(0,0,1));

         CollisionWorkingList& eorList = mConvex.getWorkingList();
         CollisionWorkingList* eopList = eorList.wLink.mNext;
         while (eopList != &eorList) {
            if ((eopList->mConvex->getObject()->getTypeMask() & mask) != 0)
            {
               Box3F convexBox = eopList->mConvex->getBoundingBox();
               if (testBox.isOverlapped(convexBox))
               {
                  eopList->mConvex->getPolyList(&sEarlyOutPolyList);
                  if (sEarlyOutPolyList.isEmpty() == false)
                     break;
               }
            }
            eopList = eopList->wLink.mNext;
         }
         if (sEarlyOutPolyList.isEmpty())
         {
            pos = end;
            break;
         }

         collisionMatrix.setColumn(3, pos);
         sBoxPolyhedron.buildBox(collisionMatrix, mObjBox, true);

         // Build extruded polyList...
         VectorF vector = end - pos;
         sExtrudedPolyList.extrude(sBoxPolyhedron, vector);
         sExtrudedPolyList.setVelocity(mVelocity);
         sExtrudedPolyList.setCollisionList(&collisionList);

         CollisionWorkingList& rList = mConvex.getWorkingList();
         CollisionWorkingList* pList = rList.wLink.mNext;
         while (pList != &rList) {
            if ((pList->mConvex->getObject()->getTypeMask() & mask) != 0)
            {
               Box3F convexBox = pList->mConvex->getBoundingBox();
               if (testBox.isOverlapped(convexBox))
               {
                  pList->mConvex->getPolyList(&sExtrudedPolyList);
               }
            }
            pList = pList->wLink.mNext;
         }

         if (collisionList.getTime() < 1.0)
         {
            // Set to collision point
            F32 dt = time * collisionList.getTime();
            pos += mVelocity * dt;
            time -= dt;

            // Pick the most resistant surface
            F32 bd = 0;
            const Collision* collision = 0;
            for (int c = 0; c < collisionList.getCount(); c++) {
               const Collision &cp = collisionList[c];
               F32 dot = -mDot(mVelocity,cp.normal);
               if (dot > bd) {
                  bd = dot;
                  collision = &cp;
               }
            }

            if (collision && mDataBlock->sticky && collision->object->getTypeMask() & (STATIC_COLLISION_TYPEMASK)) {
               mVelocity.set(0, 0, 0);
               mAtRest = true;
               mAtRestCounter = 0;
               stickyNotify = true;
               mStickyCollisionPos    = collision->point;
               mStickyCollisionNormal = collision->normal;
               break;
            } else {
               // Subtract out velocity into surface and friction
               if (collision) {
                  VectorF fv = mVelocity + collision->normal * bd;
                  F32 fvl = fv.len();
                  if (fvl) {
                     F32 ff = bd * mDataBlock->friction;
                     if (ff < fvl) {
                        fv *= ff / fvl;
                        fvl = ff;
                     }
                  }
                  bd *= 1 + mDataBlock->elasticity;
                  VectorF dv = collision->normal * (bd + 0.002);
                  mVelocity += dv;
                  mVelocity -= fv;

                  // Keep track of what we hit
                  contact = true;
                  U32 typeMask = collision->object->getTypeMask();
                  if (!(typeMask & StaticObjectType))
                     nonStatic = true;
                  if (isServerObject() && (typeMask & ShapeBaseObjectType)) {
                     ShapeBase* col = static_cast<ShapeBase*>(collision->object);
                     queueCollision(col,mVelocity - col->getVelocity());
                  }
               }
            }
         }
         else
         {
            pos = end;
            break;
         }
      }
      if (count == 3)
      {
         // Couldn't move...
         mVelocity.set(0, 0, 0);
      }
   }

   // If on the client, calculate delta for backstepping
   if (isGhost()) {
      delta.pos     = pos;
      delta.posVec -= pos;
      delta.dt = 1;
   }

   // Update transform
   MatrixF mat = mObjToWorld;
   mat.setColumn(3,pos);
   Parent::setTransform(mat);
   enableCollision();
   if (mCollisionObject)
      mCollisionObject->enableCollision();
   updateContainer();

   if ( mPhysicsRep )
      mPhysicsRep->setTransform( mat );

   //
   if (contact) {
      // Check for rest condition
      if (!nonStatic && mVelocity.len() < sAtRestVelocity) {
         mVelocity.x = mVelocity.y = mVelocity.z = 0;
         mAtRest = true;
         mAtRestCounter = 0;
      }

      // Only update the client if we hit a non-static shape or
      // if this is our final rest pos.
      if (nonStatic || mAtRest)
         setMaskBits(PositionMask);
   }

   // Collision callbacks. These need to be processed whether we hit
   // anything or not.
   if (!isGhost())
   {
      SimObjectPtr<Item> safePtr(this);
      if (stickyNotify)
      {
         notifyCollision();
         if(bool(safePtr))
			 onStickyCollision_callback( getIdString() );
      }
      else
         notifyCollision();

      // water
      if(bool(safePtr))
      {
         if(!mInLiquid && mWaterCoverage != 0.0f)
         {
            mInLiquid = true;
            if ( !isGhost() )
             mDataBlock->onEnterLiquid_callback( this, mWaterCoverage, mLiquidType.c_str() );
         }

         else if(mInLiquid && mWaterCoverage == 0.0f)
         {
            mInLiquid = false;
            if ( !isGhost() )
             mDataBlock->onLeaveLiquid_callback( this, mLiquidType.c_str() );
         }
      }
   }
}