//----------------------------------------------------------------// void MOAIDraw::DrawGrid ( const ZLRect& rect, u32 xCells, u32 yCells ) { if ( xCells > 1 ) { float xStep = rect.Width () / ( float )xCells; for ( u32 i = 1; i < xCells; ++i ) { float x = rect.mXMin + (( float )i * xStep ); USVec2D v0 ( x, rect.mYMin ); USVec2D v1 ( x, rect.mYMax ); MOAIDraw::DrawLine ( v0, v1 ); } } if ( yCells > 1 ) { float yStep = rect.Height () / ( float )yCells; for ( u32 i = 1; i < yCells; ++i ) { float y = rect.mYMin + (( float )i * yStep ); USVec2D v0 ( rect.mXMin, y ); USVec2D v1 ( rect.mXMax, y ); MOAIDraw::DrawLine ( v0, v1 ); } } MOAIDraw::DrawRectOutline ( rect ); }
//----------------------------------------------------------------// void MOAIGfxDeviceStateCache::SetScissorRect ( ZLRect rect ) { rect.Bless (); this->mViewRect.Clip ( rect ); ZLRect& current = this->mScissorRect; if ( ( current.mXMin != rect.mXMin ) || ( current.mYMin != rect.mYMin ) || ( current.mXMax != rect.mXMax ) || ( current.mYMax != rect.mYMax )) { this->OnGfxStateWillChange (); ZLRect deviceRect = this->mCurrentFrameBuffer->WndRectToDevice ( rect ); s32 x = ( s32 )deviceRect.mXMin; s32 y = ( s32 )deviceRect.mYMin; u32 w = ( u32 )( deviceRect.Width () + 0.5f ); u32 h = ( u32 )( deviceRect.Height () + 0.5f ); w = h == 0 ? 0 : w; h = w == 0 ? 0 : h; zglScissor ( x, y, w, h ); this->mScissorRect = rect; zglEnable ( ZGL_PIPELINE_SCISSOR ); } }
//----------------------------------------------------------------// ZLRect MOAIQuadBrush::GetVtxBounds () { ZLRect rect; rect.Init ( this->mModelQuad.mV [ 0 ]); rect.Grow ( this->mModelQuad.mV [ 1 ]); rect.Grow ( this->mModelQuad.mV [ 2 ]); rect.Grow ( this->mModelQuad.mV [ 3 ]); return rect; }
/** @name getRect @text Returns the two dimensional boundary of the frame. @in MOAIProfilerReportBox self @out number xMin @out number yMin @out number xMax @out number yMax */ int MOAIProfilerReportBox::_getRect ( lua_State* L ) { MOAI_LUA_SETUP ( MOAIProfilerReportBox, "U" ) ZLRect rect = self->mFrame; rect.Bless (); lua_pushnumber ( state, rect.mXMin ); lua_pushnumber ( state, rect.mYMin ); lua_pushnumber ( state, rect.mXMax ); lua_pushnumber ( state, rect.mYMax ); return 4; }
//----------------------------------------------------------------// bool ZLFrustum::GetXYSectRect ( const ZLAffine3D& mtx, ZLRect& rect ) const { u32 nHits = 0; ZLVec2D hits [ 12 ]; ZLVec3D nlt = this->mPoints [ NEAR_LT_POINT ]; ZLVec3D nrt = this->mPoints [ NEAR_RT_POINT ]; ZLVec3D nrb = this->mPoints [ NEAR_RB_POINT ]; ZLVec3D nlb = this->mPoints [ NEAR_LB_POINT ]; ZLVec3D flt = this->mPoints [ FAR_LT_POINT ]; ZLVec3D frt = this->mPoints [ FAR_RT_POINT ]; ZLVec3D frb = this->mPoints [ FAR_RB_POINT ]; ZLVec3D flb = this->mPoints [ FAR_LB_POINT ]; mtx.Transform ( nlt ); mtx.Transform ( nrt ); mtx.Transform ( nrb ); mtx.Transform ( nlb ); mtx.Transform ( flt ); mtx.Transform ( frt ); mtx.Transform ( frb ); mtx.Transform ( flb ); if ( _vecToXYPlane ( nlt, flt, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nrt, frt, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nrb, frb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nlb, flb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nlt, nrt, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nrt, nrb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nrb, nlb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( nlb, nlt, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( flt, frt, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( frt, frb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( frb, flb, hits [ nHits ])) ++nHits; if ( _vecToXYPlane ( flb, flt, hits [ nHits ])) ++nHits; if ( nHits ) { rect.Init ( hits [ 0 ]); for ( u32 i = 1; i < nHits; ++i ) { rect.Grow ( hits [ i ]); } return true; } return false; }
//----------------------------------------------------------------// ZLBox MOAIGridDeck2D::GetItemBounds ( u32 idx ) { ZLBox bounds; u32 size = this->mBrushes.Size (); if ( this->mGrid && size ) { // TODO: handle oversized decks (don't assume unit sized deck items) idx = ( idx - 1 ) % size; MOAIGridDeckBrush& brush = this->mBrushes [ idx ]; ZLRect rect = this->mGrid->GetBounds ( brush.mMin, brush.mMax ); rect.Offset ( brush.mOffset.mX - rect.mXMin, brush.mOffset.mY - rect.mYMin ); bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; } bounds.Init ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// ZLBox MOAIScriptDeck::ComputeMaxBounds () { ZLRect rect = this->mRect; if ( this->mOnTotalRect ) { MOAILuaStateHandle state = MOAILuaRuntime::Get ().State (); this->PushLocal ( state, this->mOnTotalRect ); state.DebugCall ( 0, 4 ); rect.mXMin = state.GetValue < float >( -4, 0.0f ); rect.mYMin = state.GetValue < float >( -3, 0.0f ); rect.mXMax = state.GetValue < float >( -2, 0.0f ); rect.mYMax = state.GetValue < float >( -1, 0.0f ); rect.Bless (); } ZLBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// void MOAIDraw::DrawRay ( float x, float y, float dx, float dy ) { USVec2D loc ( x, y ); USVec2D vec ( dx, dy ); ZLMatrix4x4 mtx = MOAIGfxDevice::Get ().GetViewProjMtx (); ZLMatrix4x4 invMtx; invMtx.Inverse ( mtx ); mtx.Transform ( loc ); mtx.TransformVec ( vec ); ZLRect viewRect; viewRect.Init ( -1.0f, -1.0f, 1.0f, 1.0f ); USVec2D p0; USVec2D p1; if ( viewRect.GetIntersection ( loc, vec, p0, p1 )) { invMtx.Transform ( p0 ); invMtx.Transform ( p1 ); MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get (); gfxDevice.BeginPrim ( ZGL_PRIM_LINES ); gfxDevice.WriteVtx ( p0.mX, p0.mY, 0.0f ); gfxDevice.WriteFinalColor4b (); gfxDevice.WriteVtx ( p1.mX, p1.mY, 0.0f ); gfxDevice.WriteFinalColor4b (); gfxDevice.EndPrim (); } }
//----------------------------------------------------------------// ZLBox MOAIScriptDeck::GetItemBounds ( u32 idx ) { ZLRect rect = this->mRect; if ( this->mOnRect ) { MOAILuaStateHandle state = MOAILuaRuntime::Get ().State (); this->PushLocal ( state, this->mOnRect ); lua_pushnumber ( state, idx ); state.DebugCall ( 1, 4 ); rect.mXMin = state.GetValue < float >( -4, 0.0f ); rect.mYMin = state.GetValue < float >( -3, 0.0f ); rect.mXMax = state.GetValue < float >( -2, 0.0f ); rect.mYMax = state.GetValue < float >( -1, 0.0f ); rect.Bless (); } ZLBox bounds; bounds.Init ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMin, 0.0f, 0.0f ); return bounds; }
//----------------------------------------------------------------// ZLRect MOAIScissorRect::GetScissorRect ( const ZLMatrix4x4& worldToWndMtx ) const { ZLVec3D vtx3D [ 4 ]; vtx3D [ 0 ].mX = this->mRect.mXMin; vtx3D [ 0 ].mY = this->mRect.mYMin; vtx3D [ 0 ].mZ = 0.0f; vtx3D [ 1 ].mX = this->mRect.mXMin; vtx3D [ 1 ].mY = this->mRect.mYMax; vtx3D [ 1 ].mZ = 0.0f; vtx3D [ 2 ].mX = this->mRect.mXMax; vtx3D [ 2 ].mY = this->mRect.mYMax; vtx3D [ 2 ].mZ = 0.0f; vtx3D [ 3 ].mX = this->mRect.mXMax; vtx3D [ 3 ].mY = this->mRect.mYMin; vtx3D [ 3 ].mZ = 0.0f; ZLMatrix4x4 mtx; mtx.Init ( this->GetLocalToWorldMtx ()); mtx.Append ( worldToWndMtx ); mtx.Project ( vtx3D [ 0 ]); mtx.Project ( vtx3D [ 1 ]); mtx.Project ( vtx3D [ 2 ]); mtx.Project ( vtx3D [ 3 ]); ZLRect scissorRect; scissorRect.Init ( vtx3D [ 0 ]); scissorRect.Grow ( vtx3D [ 1 ]); scissorRect.Grow ( vtx3D [ 2 ]); scissorRect.Grow ( vtx3D [ 3 ]); if ( this->mScissorRect ) { ZLRect parentRect = this->mScissorRect->GetScissorRect ( worldToWndMtx ); parentRect.Clip ( scissorRect ); } return scissorRect; }
//----------------------------------------------------------------// void MOAIDraw::DrawRectEdges ( ZLRect rect, u32 edges ) { rect.Bless (); // right if ( edges & ZLRect::kRight ) { MOAIDraw::DrawLine ( rect.mXMax, rect.mYMin, rect.mXMax, rect.mYMax ); } // top if ( edges & ZLRect::kTop ) { MOAIDraw::DrawLine ( rect.mXMin, rect.mYMin, rect.mXMax, rect.mYMin ); } // left if ( edges & ZLRect::kLeft ) { MOAIDraw::DrawLine ( rect.mXMin, rect.mYMin, rect.mXMin, rect.mYMax ); } // bottom if ( edges & ZLRect::kBottom ) { MOAIDraw::DrawLine ( rect.mXMin, rect.mYMax, rect.mXMax, rect.mYMax ); } }
//----------------------------------------------------------------// bool MOAICollisionShape::Overlap ( const ZLRect& s0, const ZLRect& s1 ) { return s0.Overlap ( s1 ); }
//----------------------------------------------------------------// void MOAIDraw::DrawAxisGrid ( USVec2D loc, USVec2D vec, float size ) { ZLMatrix4x4 mtx = MOAIGfxDevice::Get ().GetViewProjMtx (); ZLMatrix4x4 invMtx; invMtx.Inverse ( mtx ); // Set the axis to the grid length so we can get the length back post-transform vec.SetLength ( size ); mtx.Transform ( loc ); mtx.TransformVec ( vec ); // Get the axis unit vector USVec2D norm = vec; size = norm.NormSafe (); // Get the axis normal USVec2D perpNorm ( norm.mY, -norm.mX ); // Project the corners of the viewport onto the axis to get the mix/max bounds float dot; float min; float max; USVec2D corner; // left, top corner.Init ( -1.0f, 1.0f ); corner.Sub ( loc ); dot = norm.Dot ( corner ); min = dot; max = dot; // right, top corner.Init ( 1.0f, 1.0f ); corner.Sub ( loc ); dot = norm.Dot ( corner ); min = ( dot < min ) ? dot : min; max = ( dot > max ) ? dot : max; // right, bottom corner.Init ( 1.0f, -1.0f ); corner.Sub ( loc ); dot = norm.Dot ( corner ); min = ( dot < min ) ? dot : min; max = ( dot > max ) ? dot : max; // left, bottom corner.Init ( -1.0f, -1.0f ); corner.Sub ( loc ); dot = norm.Dot ( corner ); min = ( dot < min ) ? dot : min; max = ( dot > max ) ? dot : max; // Get the start andstop grids s32 start = ( s32 )( min / size ) - 1; s32 stop = ( s32 )( max / size ) + 1; // Set the pen to the first... USVec2D pen = norm; pen.Scale (( float )start * size ); pen.Add ( loc ); // Step along the axis to draw perpendicular grid lines ZLRect viewRect; viewRect.Init ( -1.0f, -1.0f, 1.0f, 1.0f ); for ( ; start < stop; ++start ) { USVec2D p0; USVec2D p1; if ( viewRect.GetIntersection ( pen, perpNorm, p0, p1 )) { invMtx.Transform ( p0 ); invMtx.Transform ( p1 ); MOAIDraw::DrawLine ( p0, p1 ); } pen.Add ( vec ); } }
//----------------------------------------------------------------// void MOAIDraw::DrawRectFill ( ZLRect rect, bool asTriStrip ) { rect.Bless (); MOAIDraw::DrawRectFill ( rect.mXMin, rect.mYMin, rect.mXMax, rect.mYMax, asTriStrip ); }