2022-03-16 17:48:18 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaConvexPolygon,
|
|
|
|
#superclass : #DiyaPolygon,
|
|
|
|
#category : #'Diya-Graphics'
|
|
|
|
}
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaConvexPolygon >> calculateVertices [
|
|
|
|
|size index p texcoord|
|
|
|
|
size := (points size + 1) << 2.
|
|
|
|
vbuffer ifNotNil: [ vbuffer free ].
|
|
|
|
vbuffer := FFIExternalArray externalNewType: GLfloat size:size.
|
|
|
|
vbuffer autoRelease.
|
2022-08-06 03:11:36 +02:00
|
|
|
points sort:[:a :b| a angle > b angle].
|
2022-03-16 17:48:18 +01:00
|
|
|
index := 1.
|
|
|
|
points do:[:point|
|
|
|
|
texcoord := self texcoordOf: point.
|
|
|
|
vbuffer
|
|
|
|
at: index put: point x;
|
|
|
|
at: index + 1 put: point y;
|
|
|
|
at: index + 2 put: texcoord x;
|
2022-08-06 03:11:36 +02:00
|
|
|
at: index + 3 put: texcoord y.
|
2022-03-16 17:48:18 +01:00
|
|
|
index := index + 4.
|
|
|
|
].
|
|
|
|
p := points at: 2.
|
|
|
|
texcoord := self texcoordOf: p.
|
|
|
|
vbuffer
|
|
|
|
at: index put: p x;
|
|
|
|
at: index + 1 put: p y;
|
|
|
|
at: index + 2 put: texcoord x;
|
2022-08-06 03:11:36 +02:00
|
|
|
at: index + 3 put: texcoord y.
|
2022-03-16 17:48:18 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaConvexPolygon >> drawLines [
|
|
|
|
OpenGL drawArrays: GL_LINE_LOOP first:0 count: (vbuffer size >> 2) - 1.
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #initialization }
|
|
|
|
DiyaConvexPolygon >> initialize [
|
|
|
|
super initialize.
|
|
|
|
type := GL_TRIANGLE_FAN
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #accessing }
|
|
|
|
DiyaConvexPolygon >> texcoordOf: point [
|
|
|
|
^ (point / (self extent )) asFloatPoint
|
|
|
|
]
|