Persistent::Base::Error LSTerrainStamp::read(StreamIO &sio, int, int)
{
   TextureType texType;
   Point2I pt; 
   int lenght, i;

   texList.clear();
   flatList.clear();

   // Read the list of TextureTypes, getting length first
   if (!sio.read(&lenght))            return Persistent::Base::ReadError;
   for (i = 0; i < lenght; i++)
   {
      if (!texType.tile.read(sio))    return Persistent::Base::ReadError;     
      if (!sio.read(&texType.flags))   return Persistent::Base::ReadError;
      if (!sio.read(&texType.textureID))   return Persistent::Base::ReadError;
      texList.push_back(texType);
   }

   // Read the list of TextureTypes, getting length first
   if (!sio.read(&lenght))            return Persistent::Base::ReadError;
   for (i = 0; i < lenght; i++)
   {
      if (!pt.read(sio))                 return Persistent::Base::ReadError;     
      flatList.push_back(pt);
   }

   // Read the clamping value
   if (!sio.read(&clamp_max_detail))  return Persistent::Base::ReadError;

   return Persistent::Base::Ok;   
} 
static EClip ComputeLocationCode( const Point2I & pt, const Rectangle & rect )
{
    int code = ClipNone;

    if ( pt.X() < rect.Left() )
        code |= ClipLeft;
    if ( pt.Y() < rect.Top() )
        code |= ClipTop;
    if ( rect.Right() < pt.X() )
        code |= ClipRight;
    if ( rect.Bottom() < pt.Y() )
        code |= ClipBottom;

    return  EClip( code );
}
bool EditorCamera::onMouseMove(int x, int y)
{
   if (!mMouseDown)
      return false;

   Point2I pos = Point2I(x, y);
   Point2I delta = mMouseStart - pos;
   mMouseStart = pos;

   if (delta.isZero()) return false;

   mHorizontalAngle += delta.x * 0.01f;
   mVerticalAngle -= delta.y * 0.01f;
   mVerticalAngle = mClampF(mVerticalAngle, -4.7f, -1.7f);
   return false;
}
bool TransformTool::onMouseMove(int x, int y)
{
   if (!mActive)
      return false;

   mMousePosition.set(x, y);
   if (!mGizmo.onMouseMove(x, y))
   {
      if (mMouseDown)
      {
         Point2I delta = mMousePosition - mMouseDownPosition;
         F32 dist = delta.len();
         if (dist > 5.0f)
            mBoxSelection = true;
      }
   }
   return false;
}
Example #5
0
bool GuiContainer::anchorControl( GuiControl *control, const Point2I &deltaParentExtent )
{
   GuiContainer *container = dynamic_cast<GuiContainer*>( control );
   if( !control || !container )
      return false;

   // If we're docked, we don't anchor to anything
   if( (container->getDocking() & Docking::dockAny) || !(container->getDocking() & Docking::dockInvalid)  )
      return false;

   if( deltaParentExtent.isZero() )
      return false;

   RectI oldRect = control->getBounds();
   RectI newRect = control->getBounds();

   F32 deltaBottom = mSizingOptions.mAnchorBottom ? (F32)deltaParentExtent.y : 0.0f;
   F32 deltaRight = mSizingOptions.mAnchorRight ? (F32)deltaParentExtent.x : 0.0f;
   F32 deltaLeft = mSizingOptions.mAnchorLeft ? 0.0f : (F32)deltaParentExtent.x;
   F32 deltaTop = mSizingOptions.mAnchorTop ? 0.0f : (F32)deltaParentExtent.y;

   // Apply Delta's to newRect
   newRect.point.x += (S32)deltaLeft;
   newRect.extent.x += (S32)(deltaRight - deltaLeft);
   newRect.point.y += (S32)deltaTop;
   newRect.extent.y += (S32)(deltaBottom - deltaTop);

   Point2I minExtent = control->getMinExtent();
   // Only resize if our minExtent is satisfied with it.
   if( !( newRect.extent.x >= control->getMinExtent().x && newRect.extent.y >= control->getMinExtent().y ) )
      return false;

   if( newRect.point == oldRect.point && newRect.extent == oldRect.extent )
      return false;

   // Finally Size the control
   control->resize( newRect.point, newRect.extent );

   // We made changes
   return true;
}
bool TransformTool::onMouseLeftUp(int x, int y)
{
   if (!mActive)
      return false;

   if (!mGizmo.onMouseLeftUp(x, y))
   {
      Point2I delta = mMousePosition - mMouseDownPosition;
      F32 dist = delta.len();

      if (mBoxSelection && mMousePosition.x != mMouseDownPosition.x && mMousePosition.y != mMouseDownPosition.y)
      {
         //mDebugBoxSelection = true;

         Torque::Rendering.screenToWorld(Point2I(mMouseDownPosition.x, mMouseDownPosition.y), mBoxNearPoint, mBoxFarPoint[0]);
         Torque::Rendering.screenToWorld(Point2I(mMousePosition.x, mMouseDownPosition.y), mBoxNearPoint, mBoxFarPoint[1]);
         Torque::Rendering.screenToWorld(Point2I(mMouseDownPosition.x, mMousePosition.y), mBoxNearPoint, mBoxFarPoint[2]);
         Torque::Rendering.screenToWorld(Point2I(mMousePosition.x, mMousePosition.y), mBoxNearPoint, mBoxFarPoint[3]);

         PlaneF planes[4];
         planes[0].set(mBoxNearPoint, mBoxFarPoint[2], mBoxFarPoint[0]);
         planes[1].set(mBoxNearPoint, mBoxFarPoint[1], mBoxFarPoint[3]);
         planes[2].set(mBoxNearPoint, mBoxFarPoint[0], mBoxFarPoint[1]);
         planes[3].set(mBoxNearPoint, mBoxFarPoint[3], mBoxFarPoint[2]);
         PlaneSetF planeSet(planes, 4);

         Vector<Scene::SceneObject*> objects = Torque::Scene.boxSearch(planeSet);
         if (objects.size() > 0)
         {
            wxTorqueObjectEvent evt(0, wxTORQUE_SELECT_OBJECT);

            for (S32 n = 0; n < objects.size(); ++n)
               evt.AddObject(objects[n]);

            if (mShiftDown)
            {
               if (mSelectedObject != NULL)
                  evt.AddObject(mSelectedObject);

               for (S32 n = 0; n < mSelectedObjects.size(); ++n)
                  evt.AddObject(mSelectedObjects[n]);

               if (mSelectedComponent != NULL)
                  evt.AddObject(mSelectedComponent);
            }

            // Broadcast the selections.
            mEditorManager->postEvent(evt);
         }
      }
      else 
      {
         Torque::Rendering.screenToWorld(Point2I(x, y), mLastRayStart, mLastRayEnd);
         Point3F editorPos = mEditorManager->mEditorCamera.getWorldPosition();

         //mDebugWorldRay = true;

         Scene::SceneObject* hit = Torque::Scene.raycast(mLastRayStart, mLastRayEnd);
         if (mSelectedObject != hit)
         {
            if (hit)
            {
               wxTorqueObjectEvent evt(0, wxTORQUE_SELECT_OBJECT);
               evt.AddObject(hit);

               if (mShiftDown)
               {
                  if ( mSelectedObject != NULL )
                     evt.AddObject(mSelectedObject);

                  for (S32 n = 0; n < mSelectedObjects.size(); ++n)
                     evt.AddObject(mSelectedObjects[n]);

                  if (mSelectedComponent != NULL)
                     evt.AddObject(mSelectedComponent);
               }

               // Broadcast the hit.
               mEditorManager->postEvent(evt);
            }
         }
      }
   }

   mMouseDown     = false;
   mBoxSelection  = false;

   return false;
}
Example #7
0
bool TerrainBlock::castRayBlock(const Point3F &pStart, const Point3F &pEnd, const Point2I &aBlockPos, U32 aLevel, F32 invDeltaX, F32 invDeltaY, F32 aStartT, F32 aEndT, RayInfo *info, bool collideEmpty)
{
   F32 invBlockSize = 1 / F32(BlockSquareWidth);

   static TerrLOSStackNode stack[BlockShift * 3 + 1];
   U32 stackSize = 1;

   stack[0].startT = aStartT;
   stack[0].endT = aEndT;
   stack[0].blockPos = aBlockPos;
   stack[0].level = aLevel;
   
   if(!mTile && !aBlockPos.isZero())
      return false;

   while(stackSize--)
   {
      TerrLOSStackNode *sn = stack + stackSize;
      U32 level  = sn->level;
      F32 startT = sn->startT;
      F32 endT   = sn->endT;
      Point2I blockPos = sn->blockPos;

      GridSquare *sq = findSquare(level, Point2I(blockPos.x & BlockMask, blockPos.y & BlockMask));

      F32 startZ = startT * (pEnd.z - pStart.z) + pStart.z;
      F32 endZ = endT * (pEnd.z - pStart.z) + pStart.z;

      F32 minHeight = fixedToFloat(sq->minHeight);
      if(startZ <= minHeight && endZ <= minHeight)
      {
         //drawLineTest(startT, sn->endT, false);
         continue;
      }
      F32 maxHeight = fixedToFloat(sq->maxHeight);
      if(startZ >= maxHeight && endZ >= maxHeight)
      {
         //drawLineTest(startT, endT, false);
         continue;
      }
      if (!collideEmpty && (sq->flags & GridSquare::Empty) &&
      	  blockPos.x == (blockPos.x & BlockMask) && blockPos.y == (blockPos.y & BlockMask))
      {
         //drawLineTest(startT, endT, false);
         continue;
      }
      if(level == 0)
      {
         F32 xs = blockPos.x * invBlockSize;
         F32 ys = blockPos.y * invBlockSize;

         F32 zBottomLeft = fixedToFloat(getHeight(blockPos.x, blockPos.y));
         F32 zBottomRight= fixedToFloat(getHeight(blockPos.x + 1, blockPos.y));
         F32 zTopLeft =    fixedToFloat(getHeight(blockPos.x, blockPos.y + 1));
         F32 zTopRight =   fixedToFloat(getHeight(blockPos.x + 1, blockPos.y + 1));

         PlaneF p1, p2;
         PlaneF divider;
         Point3F planePoint;

         if(sq->flags & GridSquare::Split45)
         {
            p1.set(zBottomLeft - zBottomRight, zBottomRight - zTopRight, invBlockSize);
            p2.set(zTopLeft - zTopRight, zBottomLeft - zTopLeft, invBlockSize);
            planePoint.set(xs, ys, zBottomLeft);
            divider.x = 1;
            divider.y = -1;
            divider.z = 0;
         }
         else
         {
            p1.set(zTopLeft - zTopRight, zBottomRight - zTopRight, invBlockSize);
            p2.set(zBottomLeft - zBottomRight, zBottomLeft - zTopLeft, invBlockSize);
            planePoint.set(xs + invBlockSize, ys, zBottomRight);
            divider.x = 1;
            divider.y = 1;
            divider.z = 0;
         }
         p1.setPoint(planePoint);
         p2.setPoint(planePoint);
         divider.setPoint(planePoint);

         F32 t1 = p1.intersect(pStart, pEnd);
         F32 t2 = p2.intersect(pStart, pEnd);
         F32 td = divider.intersect(pStart, pEnd);

         F32 dStart = divider.distToPlane(pStart);
         F32 dEnd = divider.distToPlane(pEnd);

         // see if the line crosses the divider
         if((dStart >= 0 && dEnd < 0) || (dStart < 0 && dEnd >= 0))
         {
            if(dStart < 0)
            {
               F32 temp = t1;
               t1 = t2;
               t2 = temp;
            }
            if(t1 >= startT && t1 && t1 <= td && t1 <= endT)
            {
               info->t = t1;
               info->normal = p1;
               return true;
            }
            if(t2 >= td && t2 >= startT && t2 <= endT)
            {
               info->t = t2;
               info->normal = p2;
               return true;
            }
         }
         else
         {
            F32 t;
            if(dStart >= 0) {
               t = t1;
               info->normal = p1;
            }
            else {
               t = t2;
               info->normal = p2;
            }
            if(t >= startT && t <= endT)
            {
               info->t = t;
               return true;
            }
         }
         continue;
      }
      int subSqWidth = 1 << (level - 1);
      F32 xIntercept = (blockPos.x + subSqWidth) * invBlockSize;
      F32 xInt = calcInterceptX(pStart.x, invDeltaX, xIntercept);
      F32 yIntercept = (blockPos.y + subSqWidth) * invBlockSize;
      F32 yInt = calcInterceptY(pStart.y, invDeltaY, yIntercept);

      F32 startX = startT * (pEnd.x - pStart.x) + pStart.x;
      F32 startY = startT * (pEnd.y - pStart.y) + pStart.y;

      if(xInt < startT)
         xInt = MAX_FLOAT;
      if(yInt < startT)
         yInt = MAX_FLOAT;

      U32 x0 = (startX > xIntercept) * subSqWidth;
      U32 y0 = (startY > yIntercept) * subSqWidth;
      U32 x1 = subSqWidth - x0;
      U32 y1 = subSqWidth - y0;
      U32 nextLevel = level - 1;

      // push the items on the stack in reverse order of processing
      if(xInt > endT && yInt > endT)
      {
         // only test the square the point started in:
         stack[stackSize].blockPos.set(blockPos.x + x0, blockPos.y + y0);
         stack[stackSize].level = nextLevel;
         stackSize++;
      }
      else if(xInt < yInt)
      {
         F32 nextIntersect = endT;
         if(yInt <= endT)
         {
            stack[stackSize].blockPos.set(blockPos.x + x1, blockPos.y + y1);
            stack[stackSize].startT = yInt;
            stack[stackSize].endT = endT;
            stack[stackSize].level = nextLevel;
            nextIntersect = yInt;
            stackSize++;
         }
         stack[stackSize].blockPos.set(blockPos.x + x1, blockPos.y + y0);
         stack[stackSize].startT = xInt;
         stack[stackSize].endT = nextIntersect;
         stack[stackSize].level = nextLevel;

         stack[stackSize+1].blockPos.set(blockPos.x + x0, blockPos.y + y0);
         stack[stackSize+1].startT = startT;
         stack[stackSize+1].endT = xInt;
         stack[stackSize+1].level = nextLevel;
         stackSize += 2;
      }
      else if(yInt < xInt)
      {
         F32 nextIntersect = endT;
         if(xInt <= endT)
         {
            stack[stackSize].blockPos.set(blockPos.x + x1, blockPos.y + y1);
            stack[stackSize].startT = xInt;
            stack[stackSize].endT = endT;
            stack[stackSize].level = nextLevel;
            nextIntersect = xInt;
            stackSize++;
         }
         stack[stackSize].blockPos.set(blockPos.x + x0, blockPos.y + y1);
         stack[stackSize].startT = yInt;
         stack[stackSize].endT = nextIntersect;
         stack[stackSize].level = nextLevel;

         stack[stackSize+1].blockPos.set(blockPos.x + x0, blockPos.y + y0);
         stack[stackSize+1].startT = startT;
         stack[stackSize+1].endT = yInt;
         stack[stackSize+1].level = nextLevel;
         stackSize += 2;
      }
      else
      {
         stack[stackSize].blockPos.set(blockPos.x + x1, blockPos.y + y1);
         stack[stackSize].startT = xInt;
         stack[stackSize].endT = endT;
         stack[stackSize].level = nextLevel;

         stack[stackSize+1].blockPos.set(blockPos.x + x0, blockPos.y + y0);
         stack[stackSize+1].startT = startT;
         stack[stackSize+1].endT = xInt;
         stack[stackSize+1].level = nextLevel;
         stackSize += 2;
      }
   }
   return false;
}