News:

Function Finder  Find all the functions within source code files

Main Menu

2D Shape - Making a library for PlayBASIC2DLL

Started by kevin, February 15, 2021, 07:23:53 AM

Previous topic - Next topic

kevin

 2D Shapes - Making a library for PlayBASIC2DLL

   This example includes two projects, the first is the master project that we intend to build into a DLL via PlayBASIC2DLL and the second is the final compiled code.

   The code in the example is emulating the internal PlayBASIC shapes library as that's all I could come up with on the spot,  what it does is not really the interesting part, as your library could do anything (that you can code) the interesting part is how the 2DShapes file is setup.  



Videos:


 


 





Related Links



    - Download PlayBASIC2DLL Free Edition
    - PlayBASIC2DLL Tutorial -  Making your first DLL  (2019-05-30 )
    - Sinus Render (PB2DLL example)
    - G2D - 2D OpenGL library for PlayBASIC V1.64P
     - PlayBASIC2DLL - Questions




2D Shapes Library Example Code


       This is the library that is build into the Shapes.DLL via PlayBASIC2DLL.   The library is simply a function interface to some resource, in this example that resources are ists of vertex and edge data.   To build an effective library you need to manage the data for the user while providing functions to manipulate these resources.  

       Pick through the code and get some ideas about how I do it..    

PlayBASIC Code: [Select]
; PROJECT : 2021-02-14 - Shape library Master
; EDITED : 16/02/2021
; ---------------------------------------------------------------------

` *=---------------------------------------------------------------------=*
`
` >> Shape Library Mock Up <<
`
` By: Kevin Picone
`
` Started: (14th,Feb,2021)

` Last Updated: (15th,Feb,2021)
`
` (c) copyright 2021 Kevin Picone, All rights reserved
`
` *=---------------------------------------------------------------------=*
`
` This library external scripting support for 64bit Math operations
`
`
` Functions:
`
` Index=New2DShape(VertexCount,EdgeCount)
` Create2DShape(Index,VertexCount,EdgeCount)
` Delete2DShape(Index)
`
` Draw2DShape(Index,BaseX#,BaseY#)
`
` Scale2DShape(Index,Scale#)
` Scale#=Get2DShapeScale(index)
`
` Rotate2DShape(Index,Angle#)
` Angle#=Get2DShapeAngle(Index)
`
` Set2DShapeVertex(index,VertexIndex,X#,Y#)
` x#=Get2DShapeVertexX(index,VertexIndex)
` y#=Get2DShapeVertexY(index,VertexIndex)
`
` Set2DShapeEdge(index,EdgeIndex,StartVertex,EndVertex)
` StartingVertex = Get2DShapeEdgeStartingVertex(index,EdgeIndex)
` EndingVertex =Get2DShapeEdgeEndingVertex(index,EdgeIndex)
`
` Status = Get2DShapeStatus(index)

` *=---------------------------------------------------------------------=*

constant PB_2DSHAPE_LIBRARY_ExplicitState = PBExplicitState

Explicit true

; Manage PB's Debug/Trace mode, so ti won't trace through these functions
#IF PBDebug=True
#IF PBDebugMode=2
Constant PB_2DSHAPE_LIBRARY_PreviousTraceState=PBTraceState
#Trace Off
#ENDIF
#ENDIF



// The structure of a vertex used in our shape
Type tVector2D
x#,y#
EndType


// The structure of the Edge.. Which are joints between vertexs
Type tShapeEdge
Status
StartVertex
EndVertex
EndType

// The 2D Shape structure that holds all the info about this shape
type t2DSHAPE


// number of Vertex in this Shape
VertexCount

// number of edges in this shape
EdgeCount

// Rotation Angle
Angle#


// Rotation Status / Holds the status
// 0 = no rotation required
// 1 = vertex need to be rotated
Rotation_Status


// Scale of this shape
Scale#


// bank that stores the original Vertex data
VertexBufferBank
VertexBufferPtr

// bank that stores the rotated vertex.
RotatedVertexBufferBank
RotatedVertexBufferPtr


// bank that stores the Edge data (vertex connections)
EdgeBufferBank
EdgeBufferPtr
endtype



// Declare our global Container that all objects will be stored
// within
DIm _SHAPES(1000) as t2DSHAPE



function DLL_New2DShape(VertexCount,EdgeCount)
Index = GetFreeCell(_SHAPES())
DLL_Create2DShape(Index,VertexCount,EdgeCount)
EndFunction Index


function DLL_Create2DShape(Index,VertexCount,EdgeCount)

// Check if it aleady exists, if so, just delete it.
// Note: What you could do here is reuse the buffer
// if the new shape is the same size or smaller.
if DLL_Get2DShapeStatus(index)
DLL_Delete2DShape(Index)
endif

// Alloc this buffer within the containing array
_SHAPES(Index) = new t2DSHAPE

// get a pointer to the actual structure, so now we can
// just access this data directly through the local ME typed pointer
dim Me as t2DSHAPE pointer
me = _SHAPES(Index).t2DSHAPE

// remember the number of vertex in this shape
me.VertexCount = VertexCount

// Default rotation angle
me.Angle =0

Login required to view complete source code



Download


     Attached bellow.       This code requires a PlayBASIC V1.64P revision