Changeset 88 for Include


Ignore:
Timestamp:
Feb 10, 2007, 12:25:38 AM (18 years ago)
Author:
NoWest
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/abgl.ab

    r80 r88  
    44#include <GL/gl.sbp>
    55#include <GL/glu.sbp>
     6
     7Class PositionOnly
     8    x As GLfloat
     9    y As GLfloat
     10    z As GLfloat
     11Public
     12End Class
     13
     14Class PositionColoered
     15    x As GLfloat
     16    y As GLfloat
     17    z As GLfloat
     18    r As GLfloat
     19    g As GLfloat
     20    b As GLfloat
     21    a As GLfloat
     22Public
     23End Class
    624
    725Type XY_FLOAT
     
    812830    End Sub
    813831
     832Public /* operator */
     833    Sub operator = (ByRef c As Color4f)
     834        This.R=c.R
     835        This.G=c.G
     836        This.B=c.B
     837        This.A=c.A
     838    End Sub
     839
     840Public /* method */
     841    ' HSBを求める式はhttp://ofo.jp/osakana/cgtips/hsb.phtmlを参考にした
     842    ' Drawwing\Color.abをさらに参考にしました。
     843    Function GetHue() As GLfloat
     844        Dim max As GLfloat, min As GLfloat, d As GLfloat
     845        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     846        min = Math.Min(Math.Min(rgb.r, rgb.g), rgb.b)
     847        d = max - min
     848        If rgb.g = max Then
     849            Return ((rgb.b - rgb.r) As Double / d * 60.0 + 120.0) As GLfloat
     850        ElseIf rgb.b = max Then
     851            Return ((rgb.r - rgb.g) As Double / d * 60.0 + 240.0) As GLfloat
     852        ElseIf rgb.g < rgb.b Then
     853            Return ((rgb.g - rgb.b) As Double / d * 60.0 + 360.0) As GLfloat
     854        Else
     855            Return ((rgb.g - rgb.b) As Double / d * 60.0) As GLfloat
     856        EndIf
     857    End Function
     858
     859    Function GetSaturation() As GLfloat
     860        Dim max As GLfloat, min As GLfloat
     861        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     862        min = Math.Min(Math.Min(rgb.r, rgb.g), rgb.b)
     863        Return (max - min) / max
     864    End Function
     865
     866    Function GetVolue() As GLfloat
     867        Dim max As GLfloat
     868        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     869        Return max
     870    End Function
     871
     872Public /* static method */
     873    Static Function FromRGB(r As GLbyte, g As GLbyte, b As GLbyte) As Color4f
     874        Dim ret As Color4f(r/255,g/255,b/255,1.0)
     875        Return ret
     876    End Function
     877    Static Function FromCOLORREF(c As COLORREF) As Color4f
     878        Dim ret As Color4f((c and &hff)/255,(c>>8 and &hff)/255,(c>>16 and &hff)/255,1.0)
     879        Return ret
     880    End Function
     881    Static Function FromHSV(h As GLfloat, s As GLfloat, v As GLfloat, a As GLfloat) As Color4f
     882        Dim r As GLfloat
     883        Dim g As GLfloat
     884        Dim b As GLfloat
     885        Dim a As GLfloat
     886        If h<0 Then h+=360.0
     887        If h>360.0 Then h-=360.0
     888        Select Case (h/60) As Long
     889            Case 0
     890                r=v
     891                g=v*(1-s*(1-(h/60-(h/60) As Long)))
     892                b=v*(1-s)
     893            Case 1
     894                r=v*(1-s*(h/60-(h/60) As Long))
     895                g=v
     896                b=v*(1-s)
     897            Case 2
     898                r=v*(1-s)
     899                g=v
     900                b=v*(1-s*(1-(h/60-(h/60) As Long)))
     901            Case 3
     902                r=v*(1-s)
     903                g=v*(1-s*(h/60-(h/60) As Long))
     904                b=v
     905            Case 4
     906                r=v*(1-s*(1-(h/60-(h/60) As Long)))
     907                g=v*(1-s)
     908                b=v
     909            Case 5
     910                r=v
     911                g=v*(1-s)
     912                b=v*(1-s*(h/60-(h/60) As Long))
     913            Case 6
     914                r=v
     915                g=v*(1-s*(1-(h/60-(h/60) As Long)))
     916                b=v*(1-s)
     917        End Select
     918
     919        Dim ret As Color4f(r,g,b,a)
     920        Return ret
     921    End Function
     922
    814923Public
    815924    rgba As RGBA_FLOAT
     
    855964        rgba.a = a
    856965    End Sub
     966
     967Public /* operator */
     968    Sub operator = (ByRef c As Color4d)
     969        This.R=c.R
     970        This.G=c.G
     971        This.B=c.B
     972        This.A=c.A
     973    End Sub
     974
     975Public /* method */
     976    ' HSBを求める式はhttp://ofo.jp/osakana/cgtips/hsb.phtmlを参考にした
     977    ' Drawwing\Color.abをさらに参考にしました。
     978    Function GetHue() As GLfloat
     979        Dim max As GLfloat, min As GLfloat, d As GLfloat
     980        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     981        min = Math.Min(Math.Min(rgb.r, rgb.g), rgb.b)
     982        d = max - min
     983        If rgb.g = max Then
     984            Return ((rgb.b - rgb.r) As Double / d * 60.0 + 120.0) As GLdouble
     985        ElseIf rgb.b = max Then
     986            Return ((rgb.r - rgb.g) As Double / d * 60.0 + 240.0) As GLdouble
     987        ElseIf rgb.g < rgb.b Then
     988            Return ((rgb.g - rgb.b) As Double / d * 60.0 + 360.0) As GLdouble
     989        Else
     990            Return ((rgb.g - rgb.b) As Double / d * 60.0) As GLdouble
     991        EndIf
     992    End Function
     993
     994    Function GetSaturation() As GLdouble
     995        Dim max As GLdouble, min As GLdouble
     996        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     997        min = Math.Min(Math.Min(rgb.r, rgb.g), rgb.b)
     998        Return (max - min) / max
     999    End Function
     1000
     1001    Function GetVolue() As GLdouble
     1002        Dim max As GLdouble
     1003        max = Math.Max(Math.Max(rgb.r, rgb.g), rgb.b)
     1004        Return max
     1005    End Function
     1006
     1007Public /* static method */
     1008    Static Function FromRGB(r As GLbyte, g As GLbyte, b As GLbyte) As Color4d
     1009        Dim ret As Color4d(r/255,g/255,b/255,1.0)
     1010        Return ret
     1011    End Function
     1012    Static Function FromCOLORREF(c As COLORREF) As Color4d
     1013        Dim ret As Color4d((c and &hff)/255,(c>>8 and &hff)/255,(c>>16 and &hff)/255,1.0)
     1014        Return ret
     1015    End Function
     1016    Static Function FromHSV(h As GLdouble, s As GLdouble, v As GLdouble, a As GLdouble) As Color4d
     1017        Dim r As GLdouble
     1018        Dim g As GLdouble
     1019        Dim b As GLdouble
     1020        Dim a As GLdouble
     1021        If h<0 Then h+=360.0
     1022        If h>360.0 Then h-=360.0
     1023        Select Case (h/60) As Long
     1024            Case 0
     1025                r=v
     1026                g=v*(1-s*(1-(h/60-(h/60) As Long)))
     1027                b=v*(1-s)
     1028            Case 1
     1029                r=v*(1-s*(h/60-(h/60) As Long))
     1030                g=v
     1031                b=v*(1-s)
     1032            Case 2
     1033                r=v*(1-s)
     1034                g=v
     1035                b=v*(1-s*(1-(h/60-(h/60) As Long)))
     1036            Case 3
     1037                r=v*(1-s)
     1038                g=v*(1-s*(h/60-(h/60) As Long))
     1039                b=v
     1040            Case 4
     1041                r=v*(1-s*(1-(h/60-(h/60) As Long)))
     1042                g=v*(1-s)
     1043                b=v
     1044            Case 5
     1045                r=v
     1046                g=v*(1-s)
     1047                b=v*(1-s*(h/60-(h/60) As Long))
     1048            Case 6
     1049                r=v
     1050                g=v*(1-s*(1-(h/60-(h/60) As Long)))
     1051                b=v*(1-s)
     1052        End Select
     1053
     1054        Dim ret As Color4f(r,g,b,a)
     1055        Return ret
     1056    End Function
    8571057
    8581058Public
     
    16691869        glColor4d(red,green,blue,alpha)
    16701870    End Sub
    1671 
    16721871    Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat)
    16731872        glColor3f(red,green,blue)
    16741873    End Sub
     1874    Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
     1875        glColor4f(red,green,blue,alpha)
     1876    End Sub
    16751877    Sub Color(c As Color3f)
    16761878        glColor3fv(VarPtr(c.rgb))
    16771879    End Sub
    1678     Sub Color(red As GLfloat, green As GLfloat, blue As GLfloat, alpha As GLfloat)
    1679         glColor4f(red,green,blue,alpha)
     1880    Sub Color(c As Color4f)
     1881        glColor4fv(VarPtr(c.rgba))
     1882    End Sub
     1883    Sub Color(c As Color3d)
     1884        glColor3dv(VarPtr(c.rgb))
     1885    End Sub
     1886    Sub Color(c As Color4d)
     1887        glColor4dv(VarPtr(c.rgba))
    16801888    End Sub
    16811889
Note: See TracChangeset for help on using the changeset viewer.