a3dAPI
Interface anfy3dAPI

All Known Implementing Classes:
a3dCORE

public interface anfy3dAPI

Common interface for the anfy3dAPI system

Author:
Andrea Fasce

Method Summary
 int addChild(int ID, int childID)
          adds a child item (it may be a Light, a Mesh or a Transform) to a Transform
 void beginScene()
          beginning of a scene modifies.
 void clearScene()
          clears all the items contained inside a scene.
 int createCamera()
          Create a new default Camera
 int createLightDirectional()
          create a new default Directional light
 int createLightOmni()
          create a new default Omni light
 int createMaterial()
          create a new default material with diffuse(0,0,0) emissive(0,0,0) transparency(0)
 int createMesh(float[] vertex, int[] vertexI, float[] color, int[] colorI, float[] map0, int[] map0I, float[] normal, int[] normalI, int[] materialI, int[] textureI)
          create a new Mesh
 int createTexture()
          create a new default (null) Texture
 int createTransform()
          create a unit transformation
 void delete(int ID)
          delete an item from memory.
 void endScene()
          ends of a scene modifies (and also renders)
 java.lang.String getAuthor()
          returns the author of the engine
 java.awt.Component getComponent()
          return the Component object that will be used for rendering.
 float[] getMeshNormalTransformed(int ID, int subID)
          gets the rotated array of normals.
 float[] getMeshVertexTransformed(int ID, int subID)
          gets the rotated array of vertices.
 java.lang.String getSystem()
          returns the subsystem of the engine
 java.lang.String getVersion()
          returns the version of the engine
 int pick(float x, float y, float z, float nx, float ny, float nz, float[] info, int[] matInfo, float[] texInfo, float[] normalInfo)
          picks the object that intersect a ray.
 int pick(int mousex, int mousey, float[] info, int[] matInfo, float[] texInfo, float[] normalInfo)
          picks the object that is under the mouse
 void remChild(int ID, int childID)
          remove a child item from a Transform
 void render()
          renders a scene.
 void setAmbientColor(float r, float g, float b)
          set ambient light color (default is 0 0 0)
 void setBackgroundColor(float r, float g, float b)
          set the color of the background
 void setBackgroundImage(int[] pix, int width, int height)
          set as background an Image.
 void setBilinear(boolean bilinear)
          sets bilinear filtering on and off for all the scene
 void setCameraFov(int ID, float fov)
          set the fov (field of view) of a Camera (the fov should be int the interval (0,179] (default is 48)
 void setCameraLookAt(int ID, float lx, float ly, float lz, float upx, float upy, float upz)
          set the orientation of a Camera
 void setCameraMatrix(int ID, float[] m)
          set the camera transformation directly
 void setCameraOrientation(int ID, float x, float y, float z, float w)
          set the orientation of a Camera (default is 0,0,1,0)
 void setCameraPlanes(int ID, float near, float far)
          set the near and far planes of a Camera (default near is 0.1 and far is +infinite)
 void setCameraPosition(int ID, float x, float y, float z)
          set the position of a Camera (default is 0,0,10)
 void setFilter(int filter)
          sets a post-processing filter
 void setFogActive(boolean flag)
          switch fog on/off
 void setFogLinear(float near, float far, float r, float g, float b)
          set fog parameters
 void setKeyCode(java.lang.String key)
          sets the keyCode to register this engine
 void setLightActive(int ID, boolean flag)
          switch on/off a Light
 void setLightAttenuation(int ID, float a, float b, float c)
          set the attenuation of an Omni Light; as attenuation formula is used: atten = 1/max(a+b*d+c*d*d,1) where d is the distance of a point from the light
 void setLightColor(int ID, float r, float g, float b)
          set the color of a Light
 void setLightDirection(int ID, float x, float y, float z)
          set the direction of a Directional Light
 void setLightIntensity(int ID, float i)
          set the intensity of a Light
 void setLightPosition(int ID, float x, float y, float z)
          set the position of an Omni Light
 void setLightRadius(int ID, float r)
          set the radius of illumination of an Omni Light
 void setMaterialDiffuse(int ID, float r, float g, float b)
          set the diffuse color of a Material
 void setMaterialEmissive(int ID, float r, float g, float b)
          set the emissive color of a Material
 void setMaterialTransparency(int ID, float n)
          set the transparency of a Material
 void setMeshActive(int ID, boolean flag)
          switch on/off a Mesh
 void setMeshColor(int ID, float[] color)
          change the vertex colors of a Mesh
 void setMeshMap(int ID, float[] map)
          change the mapping coords of a Mesh
 void setMeshMaterial(int ID, int matID)
          set the Material of a Mesh
 void setMeshNormal(int ID, float[] normal)
          change the normals of a Mesh
 void setMeshTexture(int ID, int texID)
          set the Texture of a Mesh
 void setMeshVertex(int ID, float[] vertex)
          change the vertices of a Mesh (useful for morphing etc)
 void setSceneCamera(int ID)
          set the active Camera for the scene
 void setSceneRoot(int ID)
          set the root Transform for the scene
 void setTextureBilinear(int ID, boolean bilinear)
          set bilinear filtering for a texture
 void setTextureImage(int ID, int[] pix, int width, int height)
          set the new image for a Texture
 void setTransformMatrix(int ID, float[] matrix)
          set the 3x4 affine transformation matrix of a Transform item
 

Method Detail

getComponent

public java.awt.Component getComponent()
return the Component object that will be used for rendering. Consider that you can cast this component object to a driver type if you want to access extended (ext functions) example: a3dSWH softwareEngine = (a3dSWH)a3dCore.getComponent())

getVersion

public java.lang.String getVersion()
returns the version of the engine

getAuthor

public java.lang.String getAuthor()
returns the author of the engine

getSystem

public java.lang.String getSystem()
returns the subsystem of the engine

setKeyCode

public void setKeyCode(java.lang.String key)
sets the keyCode to register this engine

beginScene

public void beginScene()
beginning of a scene modifies. All changes of a scene MUST be done inside a beginScene()/endScene()

render

public void render()
renders a scene. You must always call this between a beginScene() and an endScene() Please note that even if you call render() you don't know when the scene will be really rendered. For example under the software version you're sure that: 1- when you call beginScene() the screen will be cleared (and background will be copied) 2- when you call render() the scene will be rendered 3- when you call endScene() the scene will be copied to the screen So you must animate etc between a beginScene() and a render() and it will always work under any implementation of the engine. (Anyway you can use its real behaviour for example if you're using the rSOFTWARE engine)

endScene

public void endScene()
ends of a scene modifies (and also renders)

createTransform

public int createTransform()
create a unit transformation
Returns:
the ID that identify the transformation

createMaterial

public int createMaterial()
create a new default material with diffuse(0,0,0) emissive(0,0,0) transparency(0)
Returns:
the ID of the new material

createMesh

public int createMesh(float[] vertex,
                      int[] vertexI,
                      float[] color,
                      int[] colorI,
                      float[] map0,
                      int[] map0I,
                      float[] normal,
                      int[] normalI,
                      int[] materialI,
                      int[] textureI)
create a new Mesh
Parameters:
vertex - an array containing all the vertices in (x,y,z) format
vertexI - an array containing the vertexIndices in the format (p0,p1,p2) to connect the faces. Faces are always triangules
color - an array containing the colors in (r,g,b) format. If null every vertex will has the color of the material for that face
colorI - an array containing informations for the color of every vertex of a face. The length of this array must be the same of the vertexI array. If null the vertexI array will be used
map0 - an array containing the mappings in (u,v) format. If null no texturemapping will be used
map0I - an array containing informations for the mapping of every vertex of a face. The length of this array must be the same of the vertexI array. If null the vertexI array will be used
normal - an array containing the normals in (nx,ny,nz) format. If null no normals will be used (and no illumination will be performed)
normalI - an array containing informations for the normal of every vertex of a face. The length of this array must be the same of the vertexI array. If null the vertexI array will be used
materialI - an array containing information for the material to use for every face. Every entry of this array MUST be a valid Material ID. If an entry is -1 no material will be used
textureI - an array containing information for the texture to use for every face. If an entry is -1 no texture will be used
Returns:
the ID of the new Mesh

createCamera

public int createCamera()
Create a new default Camera
Returns:
the ID of the new Camera

createLightOmni

public int createLightOmni()
create a new default Omni light
Returns:
the ID of the new light

createLightDirectional

public int createLightDirectional()
create a new default Directional light
Returns:
the ID of the new light

createTexture

public int createTexture()
create a new default (null) Texture
Returns:
the ID of the new Texture

delete

public void delete(int ID)
delete an item from memory. Please note that the item should not be used anymore by the scene
Parameters:
ID - the ID of the item to delete

clearScene

public void clearScene()
clears all the items contained inside a scene. Totally frees the scene

setBackgroundColor

public void setBackgroundColor(float r,
                               float g,
                               float b)
set the color of the background
Parameters:
r - red component
g - green component
b - blue component

setBackgroundImage

public void setBackgroundImage(int[] pix,
                               int width,
                               int height)
set as background an Image. Image is automatically stretched to fit the size of the screen
Parameters:
pix - an array containing a argb image (alpha is used !)
width - width of the image
height - height of the image

setTransformMatrix

public void setTransformMatrix(int ID,
                               float[] matrix)
set the 3x4 affine transformation matrix of a Transform item
Parameters:
ID - the ID of the Transform item to modify
matrix - the new 4x3 affine matrix that will be used for that Transform

addChild

public int addChild(int ID,
                    int childID)
adds a child item (it may be a Light, a Mesh or a Transform) to a Transform
Parameters:
ID - the ID of the parent Transform
childID - the ID of the child item
Returns:
the subID of the added object (useful when using multiple instances)

remChild

public void remChild(int ID,
                     int childID)
remove a child item from a Transform
Parameters:
ID - the ID of the parent Transform
childID - the ID of the child item

setMaterialDiffuse

public void setMaterialDiffuse(int ID,
                               float r,
                               float g,
                               float b)
set the diffuse color of a Material
Parameters:
ID - the ID of the Material
r - red component
g - green component
b - blue component

setMaterialEmissive

public void setMaterialEmissive(int ID,
                                float r,
                                float g,
                                float b)
set the emissive color of a Material
Parameters:
ID - the ID of the Material
r - red component
g - green component
b - blue component

setMaterialTransparency

public void setMaterialTransparency(int ID,
                                    float n)
set the transparency of a Material
Parameters:
ID - the ID of the Material
n - the transparency (range 0.0-1.0)

setTextureImage

public void setTextureImage(int ID,
                            int[] pix,
                            int width,
                            int height)
set the new image for a Texture
Parameters:
ID - the ID of the Texture
pix - an array of data in format ARGB
width - width of the image
height - height of the image

setTextureBilinear

public void setTextureBilinear(int ID,
                               boolean bilinear)
set bilinear filtering for a texture
Parameters:
ID - the ID of the Texture
bilinear - true/false to switch bilinear on/off

setMeshActive

public void setMeshActive(int ID,
                          boolean flag)
switch on/off a Mesh
Parameters:
ID - the ID of the Mesh
flag - true-visible, false-invisible

setMeshMaterial

public void setMeshMaterial(int ID,
                            int matID)
set the Material of a Mesh
Parameters:
ID - the ID of the Mesh
matID - the ID of the Material or -1 to switch off illumination for that mesh

setMeshTexture

public void setMeshTexture(int ID,
                           int texID)
set the Texture of a Mesh
Parameters:
ID - the ID of the Mesh
texID - the ID of the Texture or -1 to switch texture off for the Mesh

setMeshVertex

public void setMeshVertex(int ID,
                          float[] vertex)
change the vertices of a Mesh (useful for morphing etc)
Parameters:
ID - the ID of the Mesh
vertex - an array of float that will replace the old vertex list; the length of this array should be the same length of the original vertex array

setMeshColor

public void setMeshColor(int ID,
                         float[] color)
change the vertex colors of a Mesh
Parameters:
ID - the ID of the Mesh
color - an array of float that will replace the old color list; the length of this array should be the same length of the original color array

setMeshNormal

public void setMeshNormal(int ID,
                          float[] normal)
change the normals of a Mesh
Parameters:
ID - the ID of the Mesh
normal - an array of float that will replace the old normal list; the length of this array should be the same length of the original normal array

setMeshMap

public void setMeshMap(int ID,
                       float[] map)
change the mapping coords of a Mesh
Parameters:
ID - the ID of the Mesh
map - an array of float that will replace the old mapping coords list; the length of this array should be the same length of the original array

getMeshNormalTransformed

public float[] getMeshNormalTransformed(int ID,
                                        int subID)
gets the rotated array of normals. The normals are in camera space coords
Parameters:
ID - the ID of the Mesh
subID - the subID of the instance of the Mesh (returned by addChild)
Returns:
an array of normals

getMeshVertexTransformed

public float[] getMeshVertexTransformed(int ID,
                                        int subID)
gets the rotated array of vertices. The vertices are in camera space coords
Parameters:
ID - the ID of the Mesh
subID - the subID of the instance of the Mesh (returned by addChild)
Returns:
an array of vertices

setCameraOrientation

public void setCameraOrientation(int ID,
                                 float x,
                                 float y,
                                 float z,
                                 float w)
set the orientation of a Camera (default is 0,0,1,0)
Parameters:
ID - the ID of the Camera
x - x component of axis
y - y component of axis
z - z component of axis
w - angle

setCameraLookAt

public void setCameraLookAt(int ID,
                            float lx,
                            float ly,
                            float lz,
                            float upx,
                            float upy,
                            float upz)
set the orientation of a Camera
Parameters:
ID - the ID of the Camera
lx - x component of LookAt vector
ly - y component of LookAt vector
lz - z component of LookAt vector
upx - x component of Up vector
upy - y component of Up vector
upz - z component of Up vector

setCameraPosition

public void setCameraPosition(int ID,
                              float x,
                              float y,
                              float z)
set the position of a Camera (default is 0,0,10)
Parameters:
ID - the ID of the Camera
x - x position
y - y position
z - z position

setCameraFov

public void setCameraFov(int ID,
                         float fov)
set the fov (field of view) of a Camera (the fov should be int the interval (0,179] (default is 48)
Parameters:
ID - the ID of the Camera
fov - the fov expressed in degrees

setCameraPlanes

public void setCameraPlanes(int ID,
                            float near,
                            float far)
set the near and far planes of a Camera (default near is 0.1 and far is +infinite)
Parameters:
ID - the ID of the Camera
near - the near plane (must be greater that 0)
far - the far plane (must be greater than near; -1 means infinite)

setCameraMatrix

public void setCameraMatrix(int ID,
                            float[] m)
set the camera transformation directly
Parameters:
ID - the ID of the Camera
m - a 4x3 matrix that contains the transformation

setSceneRoot

public void setSceneRoot(int ID)
set the root Transform for the scene
Parameters:
ID - the ID of the Transform that will be the root of all the scene

setSceneCamera

public void setSceneCamera(int ID)
set the active Camera for the scene
Parameters:
ID - the ID of the Camera that will be used to render the scene

setLightColor

public void setLightColor(int ID,
                          float r,
                          float g,
                          float b)
set the color of a Light
Parameters:
ID - the ID of the Light
r - red component
g - green component
b - blue component

setLightIntensity

public void setLightIntensity(int ID,
                              float i)
set the intensity of a Light
Parameters:
ID - the ID of the Light
i - the intensity (range 0.0-1.0)

setLightActive

public void setLightActive(int ID,
                           boolean flag)
switch on/off a Light
Parameters:
ID - the ID of the Light
flag - true-on, false-off

setLightDirection

public void setLightDirection(int ID,
                              float x,
                              float y,
                              float z)
set the direction of a Directional Light
Parameters:
ID - the ID of a Directional Light
x - x axis component
y - y axis component
z - z axis component

setLightAttenuation

public void setLightAttenuation(int ID,
                                float a,
                                float b,
                                float c)
set the attenuation of an Omni Light; as attenuation formula is used: atten = 1/max(a+b*d+c*d*d,1) where d is the distance of a point from the light
Parameters:
ID - the ID of the Omni Light
a -  
b -  
c -  

setLightPosition

public void setLightPosition(int ID,
                             float x,
                             float y,
                             float z)
set the position of an Omni Light
Parameters:
ID - the ID of the Omni Light
x - x position
y - y position
z - z position

setLightRadius

public void setLightRadius(int ID,
                           float r)
set the radius of illumination of an Omni Light
Parameters:
ID - the ID of the Omni Light
r - the radius

pick

public int pick(int mousex,
                int mousey,
                float[] info,
                int[] matInfo,
                float[] texInfo,
                float[] normalInfo)
picks the object that is under the mouse
Parameters:
mousex - x mouse position
mousey - y mouse position
info - a float array of dimension 4 to store distance and intersecting point or null
matInfo - an int array of dimension 2 that will contain the material and texture picked (or -1 if mesh has not material or texture) if null these datas will not be returned
normalInfo - a float array of dimension 3 that will contain the normal of the face picked or null
Returns:
the ID of the picked Mesh or -1 if no Mesh has been picked

pick

public int pick(float x,
                float y,
                float z,
                float nx,
                float ny,
                float nz,
                float[] info,
                int[] matInfo,
                float[] texInfo,
                float[] normalInfo)
picks the object that intersect a ray. After this call the info array will contain: info[0]=distance,info[1]=x,info[2]=y,info[3]=z
Parameters:
x - x start position of the ray
y - y start position of the ray
z - z start position of the ray
nx - x axis direction of the ray
ny - y axis direction of the ray
nz - z axis direction of the ray
info - a float array of dimension 4 to store distance and intersecting point or null if you don't want these datas o be calculated
matInfo - an int array of dimension 2 that will contain the material and texture picked (or -1 if mesh has not material or texture) if null these datas will not be returned
texInfo - a float array of dimension 2 that will contain the coordinate of the texel picked on the texture or null
normalInfo - a float array of dimension 3 that will contain the normal of the face picked or null
Returns:
the ID of the picked Mesh or -1 if no Mesh has been picked

setBilinear

public void setBilinear(boolean bilinear)
sets bilinear filtering on and off for all the scene
Parameters:
bilinear - true to switch bilinear filtering on

setFilter

public void setFilter(int filter)
sets a post-processing filter
Parameters:
filter - can be: 0-none 1-antialias 2-blurmotion

setFogActive

public void setFogActive(boolean flag)
switch fog on/off
Parameters:
flag - true-fog on, false-fog off

setFogLinear

public void setFogLinear(float near,
                         float far,
                         float r,
                         float g,
                         float b)
set fog parameters
Parameters:
type - 0-linear fog 1-exponential fog
near - near fog plane
far - far fog plane
r - fog r color
g - fog g color
b - fog b color

setAmbientColor

public void setAmbientColor(float r,
                            float g,
                            float b)
set ambient light color (default is 0 0 0)
Parameters:
r - red ambient component
g - green ambient component
b - blue ambient component


(C)2000 by Andrea Fasce