Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Arrays in User Defined Types
#21
Hmmm.... This wont run. :???:


Code:
Type Surface_Properties
RGBA(3) as Single  
Spec(3) as Single  
End Type

Type Vector3DType
   X as Single
   Y as Single
   Z as Single
End Type

Type Model_Type
   Num_Verts as Integer
   Num_Faces as Integer
   Vec as Vector3DType
   Surf as Surface_Properties
end Type


Dim Model(1 to 10) as Model_Type Ptr


Model(1)->Num_Verts = 100
Model(1)->Vec = allocate(Model(1)->Num_Verts * Len(Vector3DType))
Reply
#22
Ptr.

Code:
Vec as Vector3DType ptr

You forgot to declare as Ptr
Big Grin
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#23
He he he... now this crashes. :roll:


Code:
Type Surface_Properties
RGBA(3) as Single  
Spec(3) as Single  
End Type

Type Vector3DType
   X as Single
   Y as Single
   Z as Single
End Type

Type Model_Type
   Num_Verts as Integer
   Num_Faces as Integer
   Num_Surfaces as Integer
   Vec as Vector3DType Ptr
   Surf as Surface_Properties ptr
end Type


Dim Model(1 to 10) as Model_Type ptr


Model(1)->Num_Verts = 100
Model(1)->Num_Surfaces = 3
Model(1)->Vec = Callocate(Model(1)->Num_Verts * Len(Vector3DType))
Model(1)->Surf = Callocate(Model(1)->Num_Surfaces * Len(Surface_Properties))
Reply
#24
You forgot to allocate model_type ptr

Code:
Dim Model(1 to 10) as Model_Type ptr

for i = 1 to 10
   model(i) = allocate(Len(Model_type))
next i
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#25
Oh, Thanks!!! I didn't know I had to do that too. :rotfl:

EDIT:

It seems to work good and that's a nice clean structure. Thanks again. Tongue
Reply
#26
BTW, for Matrices you can also use a 2D pointer array. This is what I'm using in my bootleg 3d math library

Code:
#define MATRIX4X4 Single Ptr Ptr

'PtrArray2D part of Extra Lib (library of extra functions I'm working on.)
Function PtrArray2D(Byval rows As Integer, Byval cols As Integer,Byval bytes As Integer) As Any Ptr Ptr
         Dim tempptr As Any Ptr Ptr
         tempptr = Callocate(rows * bytes)
         For i = 0 To rows - 1
             tempptr[i] = Callocate(cols * bytes)
         Next i
         PtrArray2D = tempptr
End Function

Dim global As MATRIX4X4

global = PtrArray2D(4, 4, Len(Single))

global[1][1] = 24.653
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)