/*
 * Copyright (c) 2011-2024 Ross Cunniff
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
/* Significant portions of this code were adapted from Hoverware, whose
 * GPL copyright is: */
/* (c) Copyright Hewlett-Packard Company 2001
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

namespace o3d {

/******************************************************************************
* Various flags
******************************************************************************/

/* Flags for o3dCallback */
const
    CB_ACTIVATE              = 1,
    CB_TRACK                 = 2,
    CB_DEACTIVATE            = 3,
    CB_COMPLETE              = 4;

/* Errors from o3dGetError */
const
    ERROR_NO_MEMORY          = 1,
    ERROR_BAD_PROP           = 2,
    ERROR_BAD_TYPE           = 3,
    ERROR_INTERNAL           = 4;

/* Flags for o3dChooseVisual */
const
    VIS_DBUFF                = 0x00000001,
    VIS_DEPTH                = 0x00000002,
    VIS_ALPHA                = 0x00000004,
    VIS_STENCIL              = 0x00000008,
    VIS_TEXTURE              = 0x00000010,
    VIS_OVERLAY              = 0x00000020,
    VIS_STEREO               = 0x00000040,
    VIS_ACCUM                = 0x00000080,
    VIS_AA                   = 0x00000100,
    VIS_AA_MED               = 0x00000200,
    VIS_AA_HI                = 0x00000400,
    VIS_SUCCESS              = 0x20000000;   // OADL has 30-bit ints

/* Flags for disp->createWindow */
const
    WIN_INPUT                = 0x00000001,
    WIN_FULLSCREEN           = 0x00000002,
    WIN_BORDERLESS           = 0x00000004,
    WIN_HIDE_CURSOR          = 0x00000004;

/* Values for disp->getInfo */
const
    INFO_O3D                 = 0,
    INFO_VENDOR              = 1,
    INFO_RENDERER            = 2,
    INFO_VERSION             = 3,
    INFO_EXTENSIONS          = 4,
    INFO_JOYSTICK            = 5;

/* Texture parameters */
const
    TM_MODULATE              = 0,
    TM_BUMP                  = 1,
    TM_RELIEF                = 2,
    TM_GLOSS                 = 3,
    TM_SHADOW                = 4,
    TM_SHADOW_VAR            = 5,

    TM_REPEAT                = 0,
    TM_CLAMP                 = 1,

    TM_EXPLICIT              = 0,
    TM_PLANAR                = 1,
    TM_SPHERE                = 2,
    TM_CYLINDER              = 3,
    TM_ENVMAP                = 4,
    TM_STAGE_0               = 5,

    TM_POINT                 = 0,
    TM_LINEAR                = 1,
    TM_MIP                   = 2,
    TM_TRILINEAR             = 3,

    TM_COLOR                 = 0,
    TM_ALPHA                 = 1,
    TM_INTENSITY             = 2,
    TM_HEIGHT                = 3,
    TM_NORMAL                = 4,
    TM_NORMAL_HEIGHT         = 5,
    TM_DEPTH                 = 6,
    TM_DEPTH_VAR             = 7,

    MAX_TEXTURES             = 8;

/* Fog parameters */
const
    FOG_LINEAR               = 0,
    FOG_EXP                  = 1,
    FOG_EXP2                 = 2;

/* Text alignment parameters */
const
    TEXT_ALIGN_LEFT = 1,
    TEXT_ALIGN_CENTER = 2,
    TEXT_ALIGN_RIGHT = 3,

    TEXT_ALIGN_TOP = 4,
    TEXT_ALIGN_BOTTOM = 5,

    TEXT_ALIGN_FRONT = 6,
    TEXT_ALIGN_BACK = 7;

/* GUI placement flags */
const
    GUI_REL_RIGHT            = 0x00000001,
    GUI_REL_BOT              = 0x00000002,
    GUI_REL_WIDTH            = 0x00000004,
    GUI_REL_HEIGHT           = 0x00000008,
    GUI_FRACTIONAL           = 0x00000010,
    GUI_CENTER               = 0x00000020,
    GUI_POS_MASK             = 0x0000003F,
    GUI_LABEL_LEFT           = 0x00000040,
    GUI_LABEL_RIGHT          = 0x00000080,
    GUI_LABEL_TOP            = 0x00000100,
    GUI_LABEL_BOTOTM         = 0x00000200,
    GUI_TOGGLE_RIGHT         = 0x00000400,
    GUI_FONT_FRACTIONAL      = 0x00000800,
    GUI_FONT_FRACT_W         = 0x00001000,
    GUI_DO_NOT_USE_BITS      = 0x3F800000;

/* Vertex data flags */
const                               /* XYZ,                 3 words */
    DATA_W                   = 0x00000001,           // +1 = 4
    DATA_RGB                 = 0x00000002,
    DATA_ALPHA               = 0x00000004,           // +4 = 8
    DATA_NORMALS             = 0x00000008,           // +3 = 11
    DATA_MD_FLAGS            = 0x00000010,           // +1 = 12
    DATA_TANGENT             = 0x00000020,           // +3 = 15
    DATA_ST                  = 0x00000040,
    DATA_R                   = 0x00000080,
    DATA_Q                   = 0x00000100,           // +4 = 19
    DATA_ST1                 = 0x00000200,
    DATA_R1                  = 0x00000400,
    DATA_Q1                  = 0x00000800,           // +4 = 23
    DATA_ST2                 = 0x00001000,
    DATA_R2                  = 0x00002000,
    DATA_Q2                  = 0x00004000,           // +4 = 27
    DATA_ST3                 = 0x00008000,
    DATA_R3                  = 0x00010000,
    DATA_Q3                  = 0x00020000,           // +4 = 31
    DATA_ST4                 = 0x00040000,
    DATA_R4                  = 0x00080000,
    DATA_Q4                  = 0x00100000,           // +4 = 35
    DATA_ST5                 = 0x00200000,
    DATA_R5                  = 0x00400000,
    DATA_Q5                  = 0x00800000,           // +4 = 39
    DATA_ST6                 = 0x01000000,
    DATA_R6                  = 0x02000000,
    DATA_Q6                  = 0x04000000,           // +4 = 43
    DATA_ST7                 = 0x08000000,
    DATA_R7                  = 0x10000000,
    DATA_Q7                  = 0x20000000,           // +4 = 47
    DATA_TEXCOORD            = 0x3FFFFFC0,           // All texcoords


    DATA_MAX_WPV             = 47;

/* Optimization flags */
const
    OPT_SAFE_USER_DATA       = 0x00000001,
    OPT_CACHE_DATA           = 0x00000002,
    OPT_USE_DL               = 0x00000004,
    OPT_DL_ATTRS             = 0x00000008,
    OPT_DEFAULT              = OPT_USE_DL;

/* Spinner motion types */
const
    SPIN_CONSTANT = 0,
    SPIN_LINEAR = 1,
    SPIN_SMOOTH = 2;

/* Surface flags */
const
    SURF_BACKFACE            = 0x00000001,
    SURF_TWOSIDED            = 0x00000002,
    SURF_UNCOLORED           = 0x00000004,
    SURF_EMISSIVE            = 0x00000008,
    SURF_INVISIBLE           = 0x00000010,
    SURF_WIREFRAME           = 0x00000020,
    SURF_PRUNE_PRIM          = 0x00000040,
    SURF_BLEND               = 0x00000080,
    SURF_FLIP_NORMALS        = 0x00000100,
    SURF_TEX_SAMP            = 0x00000200;

/* Flags for GUI lines / triangles */
const
    GUI_BLEND                = 0x00000001,
    GUI_SMOOTH               = 0x00000002;

/* Update flags */
const
    UPDATE_SWAP              = 0x00000001,
    UPDATE_CLEAR             = 0x00000006,
    UPDATE_CLEAR_COLOR       = 0x00000002,
    UPDATE_CLEAR_DEPTH       = 0x00000004,
    UPDATE_MATRIX            = 0x00000008,
    UPDATE_TIME              = 0x00000010,
    UPDATE_GUI               = 0x00000020,
    CLEAR_GUI                = 0x00000040,
    CHECK_EVENTS             = 0x00000080,
    UPDATE_ALL               = 0x3FFFFFFF;

/* Window input event */
const
    INPUT_EXPOSE             = 0,
    INPUT_CONFIG             = 1,
    INPUT_DESTROY            = 2,
    INPUT_FOCUS              = 3,
    INPUT_KEYBOARD           = 4,
    INPUT_POINTER            = 5,
    INPUT_BUTTON_PRESS       = 6,
    INPUT_BUTTON_RELEASE     = 7,
    INPUT_JOY_PRESS          = 8,
    INPUT_JOY_RELEASE        = 9,
    INPUT_JOY_AXIS           = 10;

/* Keyboard modifiers */
const
    KBD_MOD_SHIFT            = 0x0001,
    KBD_MOD_CTRL             = 0x0002,
    KBD_MOD_ALT              = 0x0004;

/* Special keys */
const
    KEY_LEFT                 = 0x10000,
    KEY_RIGHT                = 0x10001,
    KEY_UP                   = 0x10002,
    KEY_DOWN                 = 0x10003,
    KEY_PREV                 = 0x10004,
    KEY_NEXT                 = 0x10005,
    KEY_HOME                 = 0x10006,
    KEY_END                  = 0x10007,
    KEY_F1                   = 0x10008,
    KEY_F2                   = 0x10009,
    KEY_F3                   = 0x1000A,
    KEY_F4                   = 0x1000B,
    KEY_F5                   = 0x1000C,
    KEY_F6                   = 0x1000D,
    KEY_F7                   = 0x1000E,
    KEY_F8                   = 0x1000F,
    KEY_F9                   = 0x10010,
    KEY_F10                  = 0x10011,
    KEY_F11                  = 0x10012,
    KEY_F12                  = 0x10013;

/******************************************************************************
* "Structure" offsets
******************************************************************************/
/* Needs to be kept in-sync with libo3d_i.h */
const
    CAM_PERSP            = 0,
    CAM_MIRROR           = 1,
    CAM_POS              = 2,
    CAM_DIR              = 5,
    CAM_UP               = 8,
    CAM_JITTER           = 11,
    CAM_SKEW             = 13,
    CAM_FIELD            = 15,
    CAM_ASPECT           = 16,
    CAM_PLANES           = 17,
    CAM_SIZE             = 19,

    SURF_COLOR           = 0,
    SURF_TRANSP          = 3,
    SURF_SPEC            = 4,
    SURF_SHININESS       = 7,
    SURF_PRIM_SIZE       = 8,
    SURF_VISIBILITY      = 9,
    SURF_FLAGS           = 10,
    SURF_NUM_TEX         = 11,
    SURF_TEXTURE_IDS     = 12,
    SURF_SIZE            = (SURF_TEXTURE_IDS+8),

    IMG_WIDTH            = 0,
    IMG_HEIGHT           = 1,
    IMG_DEPTH            = 2,
    IMG_COMPONENTS       = 3,
    IMG_TYPE             = 4,
    IMG_TMID             = 5,
    IMG_FILENAME         = 6,
    IMG_DATA             = 7,
    IMG_SIZE             = 8,

    TEXT_UP              = 0,
    TEXT_DIR             = 3,
    TEXT_ORIENT          = 6,
    TEXT_SCALE           = 22,
    TEXT_SCALE_ORIENT    = 23,
    TEXT_EXTRUDE         = 39,
    TEXT_HORIZ_ALIGN     = 42,
    TEXT_VERT_ALIGN      = 43,
    TEXT_DEPTH_ALIGN     = 44,
    TEXT_FRONT_SURF      = 45,
    TEXT_SIDE_SURF       = (TEXT_FRONT_SURF+SURF_SIZE),
    TEXT_BACK_SURF       = (TEXT_SIDE_SURF+SURF_SIZE),
    TEXT_SIZE            = (TEXT_BACK_SURF+SURF_SIZE),

    ORIENT_SCALE         = 0,
    ORIENT_ROTATE        = 3,
    ORIENT_POS           = 6,
    ORIENT_SIZE          = 9;


/******************************************************************************
* Attributes
******************************************************************************/
class Surface;
public
    Color,
    Transparency,
    SpecColor,
    Shininess,
    Backface,
    TwoSided,
    Bright,
    Invisible,
    Wireframe,
    Visibility,
    Texture,
    Uncolored;

class Orient;
public
    Scale,
    Rotate,
    Pos;

class DataFlags;
public
    HasNormals,
    HasTangent,
    HasRGB,
    HasAlpha,
    HasUV,
    HasST0, HasST1, HasST2, HasST3, HasST4, HasST5, HasST6, HasST7,
    HasR0,  HasR1,  HasR2,  HasR3,  HasR4,  HasR5,  HasR6,  HasR7,
    HasQ0,  HasQ1,  HasQ2,  HasQ3,  HasQ4,  HasQ5,  HasQ6,  HasQ7;

class Image;
public
    Rows,
    Columns,
    Components,
    Image,
    FileName,
    TransparentColor,
    PosX,
    PosY,
    Width,
    Height,
    Color,
    Align;

class Texture; //(o3dImage,o3dOrient)
public
    Apply,
    Bound,
    CoordMode,
    Filter,
    SampVert,
    ReliefScale,
    InternalFormat;

/******************************************************************************
* Primitive drawable classes
******************************************************************************/

class Drawable; // (o3dSurface, o3dOrient)
public
    OptFlags,
    draw,
    bounds;

class Box; // (o3dDrawable)
public
    Data,
    OptLevel;

class Mesh; // (o3dDrawable,o3dDataFlags)
public
    GraphN,
    GraphM,
    Resolution,
    Data;

class Polygon; // (o3dDrawable,o3dDataFlags)
public
    Data;

class Quads; // (o3dDrawable,o3dDataFlags)
public
    Data;

class Polyline; // (o3dOrient)
public
    Invisible,
    Visibility,
    Color,
    OptLevel,
    Data;

class Polymarker; // (o3dOrient)
public
    Invisible,
    Visibility,
    Color,
    OptLevel,
    Data;

class Triangles; // (o3dDrawable,o3dDataFlags)
public
    Data;

class Group; // (o3dOrient)
public
    Invisible,
    Visibility,
    Children,
    bounds,
    draw;

class Text; // (o3dDrawable)
public
    Data,
    Surface,
    Pos,
    Dir,
    Up,
    Scale,
    Extrude,
    Align;

class Text2D;

/******************************************************************************
* Derived drawable classes
******************************************************************************/

class Cone; // (o3dMesh)
public
    GraphN,
    GraphM,
    Radius,
    Height,
    LonRange,
    HasNormals;

class Disc; // (o3dPolygon)
public
    GraphN,
    Radius;

class Ring; // (o3dMesh)
public
    GraphN,
    GraphM,
    Radius,
    LonRange;

class Sphere; // (o3dMesh)
public
    GraphN,
    GraphM,
    Radius,
    LatRange,
    LonRange,
    HasNormals;

class SurfRev; // (o3dMesh)
public
    LonRange,
    HasNormals;

class Torus; // (o3dMesh)
public
    GraphN,
    GraphM,
    Radius,
    LatRange,
    LonRange,
    HasNormals;

/******************************************************************************
* Lights/camera/environ/etc
******************************************************************************/

class Camera;
public
    Pos,
    Dir,
    Up,
    Field,
    Aspect,
    Planes,
    Perspective,
    Jitter,
    Skew,
    Mirror;

class Environ;
public
    BackgroundColor,
    AmbientFactor,
    AmbientColor,
    Fog,
    FogColor,
    FogPlanes,
    FogType,
    Lighting;

class File;
public
    FileName;

class Light;
public
    Color,
    Positional,
    Pos,
    Dir,
    Cutoff,
    LightExp,
    Atten;

/******************************************************************************
* Action!
******************************************************************************/

class Spinner;
public
    Children,
    Invisible,
    Visibility,
    PosType,
    DirType,
    UpType,
    TransType,
    ColorType,
    ScaleType,
    PosParams,
    DirParams,
    UpParams,
    TransParams,
    ColorParams,
    ScaleParams,
    PosTimes,
    DirTimes,
    UpTimes,
    TransTimes,
    ColorTimes,
    ScaleTimes,
    Lifetime,
    CycleType,
    Offset,
    Delay;

class Timer;
public
    Lifetime,
    Equation,
    CycleTime,
    Children,
    Invisible,
    Visibility;

/******************************************************************************
* GUI
******************************************************************************/
class Font;
class Button;
class Gauge;
class Label;
class Layout;
class RowCol;
class Toggle;

class Display;
public
    o3dDefaultOptFlags,
    chooseVisual, 
    createWindow, 
    inputHandler, 
    getMousePos, 
    makeCurrent, 
    getInfo, 
    viewport, 
    scissor,
    setCamera, 
    pushMatrix, 
    popMatrix, 
    update, 
    positionalLight, 
    directionalLight, 
    doFog, 
    fogParams, 
    ambientLight, 
    enableLighting, 
    backgroundColor, 
    createTexture, 
    destroyTexture, 
    currentTexture, 
    surfAttrs, 
    setVisibility, 
    setInvisibility, 
    getVisibility, 
    boundsVisible, 
    boundsSize, 
    drawMesh, 
    drawStrip, 
    drawPolygon, 
    drawPolyline, 
    drawQuads, 
    drawIndexedTriangles, 
    drawMarkers, 
    guiText, 
    guiRaster, 
    guiRectangle, 
    guiPolyline, 
    guiLines, 
    guiPolygon, 
    openGuiList, 
    closeGuiList, 
    callGuiList, 
    destroyGuiList, 
    openList, 
    closeList, 
    callList, 
    destroyList,
    _intGetHandle;

/******************************************************************************
* Utilities
******************************************************************************/

/* Matrix utilities - a "mat" is a packed Float array of at least 16 elements,
 * an "XYZ" is* a packed Float array of at least 3 elements, and an
 * "XYZW" is a packed Float array of at least 4 elements
 */
extern
    Identity, /* mat */
    Scale, /* mat, sx, sy, sz */
    RotateX, /* mat, ang */
    RotateY, /* mat, ang */
    RotateZ, /* mat, ang */
    RotateAxis, /* mat, ang, xyz */
    MatMult, /* matRes, matA, matB */
    MakeMatrix, /* orient, mat */
    Transform, /* mat, xyz */
    Transform4d, /* dstXYZW, srcXYZW, mat */
    TransformPersp, /* dstXYZ, srcXYZ, mat */
    TransformData, /* mat, data, count, dataFlags */
    InvertMat; /* matSrc, matDst */

/*  Misc utilities */
extern
    GetError, /* (void) */
    CalcWPV; /* dataFlags */

/* Object functions */
extern
    FindClass, /* objPtr = className */
    FindObject, /* objPtr = objName */
    ParseFile, /* fileName */
    ParseArray, /* stringArray */
    WriteAscii; /* fileName, objList */

}