3d_engine
所属分类:3D图形编程
开发工具:C/C++
文件大小:830KB
下载次数:58
上传日期:2008-09-04 14:58:08
上 传 者:
colin_shao
说明: 3D引擎,包含读取3DS文件,是个比较好的C语言实现3D的范例
(3D engine, contains the read 3DS file, is a relatively good C language example of the realization of 3D)
文件列表:
3d_engine\DEMO\3DSVIEW.C (23743, 1997-04-18)
3d_engine\DEMO\3DSVIEW.DOC (15019, 1997-04-20)
3d_engine\DEMO\3DSVIEW.EXE (289226, 1997-04-20)
3d_engine\DEMO\3DSVIEW.LNK (207, 1997-04-20)
3d_engine\DEMO\ART\BODYCOW.RAW (66304, 1996-09-02)
3d_engine\DEMO\ART\BUF.3DS (62936, 1995-03-12)
3d_engine\DEMO\ART\CITY05.3DS (47538, 1996-04-21)
3d_engine\DEMO\ART\CONTR04.RAW (66304, 1997-02-09)
3d_engine\DEMO\ART\COOL.JPG (22883, 1996-12-20)
3d_engine\DEMO\ART\CORNES.RAW (66304, 1997-02-26)
3d_engine\DEMO\ART\COWSOL1.3DS (94212, 1996-04-22)
3d_engine\DEMO\ART\ESSAI2.JPG (22461, 1996-12-20)
3d_engine\DEMO\ART\ESSAI3.JPG (25500, 1996-12-20)
3d_engine\DEMO\ART\ESSAI4.JPG (22712, 1996-12-20)
3d_engine\DEMO\ART\GRASS.RAW (66304, 1996-09-02)
3d_engine\DEMO\ART\HIGHWALL.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\LARGWALL.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\PANEAU.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\PIS.RAW (66304, 1997-02-26)
3d_engine\DEMO\ART\ROUGE.JPG (33439, 1996-12-20)
3d_engine\DEMO\ART\ROUGE1.JPG (53511, 1996-12-20)
3d_engine\DEMO\ART\SKY.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\STATUE.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\STOMACH.3DS (31731, 1996-04-17)
3d_engine\DEMO\ART\STOMACH.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\TOWER.RAW (66304, 1997-02-23)
3d_engine\DEMO\ART\TREE.RAW (66304, 1996-10-21)
3d_engine\DEMO\ART\WALL.RAW (66304, 1997-02-23)
3d_engine\DEMO\BMP2RAW.EXE (4826, 1995-12-09)
3d_engine\DEMO\CITY.DEF (1128, 1997-03-23)
3d_engine\DEMO\COWS.DEF (832, 1997-04-03)
3d_engine\DEMO\COWSRGB.DEF (824, 1997-04-20)
3d_engine\DEMO\DEMO1.BAT (40, 1997-03-28)
3d_engine\DEMO\DEMO2.BAT (48, 1997-03-28)
3d_engine\DEMO\DEMO3.BAT (42, 1997-03-28)
3d_engine\DEMO\DEMO4.BAT (46, 1997-03-23)
3d_engine\DEMO\DEMO5.BAT (47, 1997-03-23)
3d_engine\DEMO\GETOPT.C (12810, 1997-02-21)
3d_engine\DEMO\GETOPT.H (2155, 1997-02-21)
3d_engine\DEMO\INCLUDE\CDERROR.H (5372, 1994-10-07)
... ...
PANARD VISION
3D Realtime Portable Engine
SDK 0.95
-------------------------------------------------------------------------
DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT DRAFT
------------------------------------------------------------------------
Opening words
-------------
I release linkable libraries for Panard vision, but of course I've got no
time for writing docs right now :) I'm really sorry of this.
What you are readding now is far from a draft of a doc but it may enlight
some details and concepts, maybe not.
So I release source of the 3DSVIEW program and sources of the 3DStudio
drivers (for reading meshes and animations). You should look in these
sources like a tutorial. They are pretty straight forward to understand.
In my opinion all the Panard Vision API is pretty simple. Of course
look in pvision.h.
Don't look for classes, this API is not Object Oriented, maybe one day I will
encapsulate everything in some nice classes, but when I see the result with
Direct3D's API ...... It's not planned yet :)
If you want an interface with Java, you're on your own :)
If you code interesting drivers for popular formats (LightWave, Alias or so...)
drop me a line.
DON'T FORGET : This is the first public release of this lib. Hence it's very
likely buggy in some ways. If you find some "undocumented features" please
contact me (see end of this text). API is subject to changes in future release.
PV is designed for fast processors with fast floating point operations.
---------------------------------------------------------
Panard Vision
---------------------------------------------------------
Usage
-----
It's very simple, include "pvision.h" (eventually 3dsread.h if you plan to use
3DS file, compile, and link with pvision.lib. That's it :)
See included makefiles to see how it is simple.
Working modes
-------------
Panard vision support different working modes. The mode flag is a bit
field.
Modes are selected by PV_SetMode()
Options are:
PVM_PALETIZED8
PVM_RGB16
PVM_RGB
OR
PVM_SBUFFER
OR
PVM_MIPMAPPING
PVM_PALETIZED8 is used to generate paletized output (up to 256 colors)
PVM_RGB16 is used to generate 15 or 16 bits images, but coloured lights
are ignored (assumed to be white). The textures used for
lighted materials *MUST* be 256 colors
PVM_RGB is used to generate true RGB (15,16,24,32 bits) output
These 3 flags are exclusive, you must only specify one of them, and you
*MUST* set one of these flag before the material compilation (see below)
and not change it after.
You can add PVM_SBUFFER to render from front to back, faster when
pixel overdraw is important.
You can add PVM_MIPMAPPING to enable MipMapping on mipmapped materials.
Cameras handling
----------------
You can create as much camera as you want, but only one at a time is
active. You can change active camera by PV_SetCurrentCam().
A camera isn't linked with a world, ie you can render two world with
the same camera.
A texture (PVTexture struct)
----------------------------
typedef struct _Texture
{
unsigned Width,Height;
unsigned ShiftHeight,ShiftWidth;
UPVD8 *Texture;
} PVTexture;
Nothing to say here. Just use the API to set each public field (Width, Height and Texture) in order
to maintain Shift???? fields valid.
AND REMEMBER TEXTURES MUST HAVE THEIR SIZE A POWER OF 2 (256**** but not 53*8)
A material (PVMaterial struct)
-----------------------
typedef struct _BumpInfo
{
PVD8 nx,ny;
}PVBumpInfo;
typedef struct _BumpMap
{
unsigned Width,Height;
PVBumpInfo *Map;
} PVBumpMap;
typedef struct _Mat
{
char *Name;
PVFLAGS Type;
unsigned char NbrMipMaps;
PVFLAGS TextureFlags;
RGB *Pal;
PVTexture *Tex;
PVTexture AuxiliaryTexture;
PVBumpMap BumpMap;
UPVD8 StartingColorIndex,EndingColorIndex; // for pure colors
RGBF Diffuse,Specular,Emissive;
unsigned SpecularPower;
UPVD8 *PaletteTranscodeTable;
UPVD16 *RGB16TranscodeTable;
RGBF Color;
PVD32 UserData; // Used to handle special FX by users routines
struct _Mat *Next;
} PVMaterial;
A material is a rendering type, a shading type, a name, eventually a Primary Texture, eventually
an ambiant texture, eventually a BumpMap.
The main thing to understand is the flags used to set rendering and shading type.
Avialable flags are listed in pvision.h.
By example you can combine flags like this: GOURAUD|MAPPING to obtain a surface with a texture
gouraud shaded.
These flags are stored in the 'Type' field.
NbrMipMaps is the number of desired mipmaps foir this texture (ignored if the MIPMAP flag is not
present in the 'Type' field) by default it's 4.
TextureFlags indicates the type of the texture provided by the user (Paletized or RGB 24 bits) the
Pal fields point to the palettte if the texture is not RGB.
Color, indicates the color of the materials (in non-mapped modes).
UserData, is left to the user wishes.
Don't forget to set an unique name for each material in a world ! This name will be used to attach
faces to this material during the mesh compilation.
You can also describe specular, diffuse, emissive coefficient to obtain psychedelik materials.
StartingColorIndex and EndingColorIndexFields are used to when rebdering GOURAUD in paletized
output mode, they indicates the starting color and ending color number of the ramp.
AuxiliaryTexture is used in AmbiantMapping, it's the light texture.
BumpMap is the bump map for BUMP enabled materials (use PV_BuildBumpMap())
Aviallable combination for the Type field are:
(in fake 16 bits modes, PVM_RGB16)
FLAT|NOTHING
PHONG|NOTHING
BUMP|NOTHING
NOTHING|MAPPING
FLAT|MAPPING
GOURAUD|MAPPING
BUMP|MAPPING
PHONG|MAPPING
NOTHING|PERSPECTIVE_MAPPING
FLAT|PERSPECTIVE_MAPPING
GOURAUD|PERSPECTIVE_MAPPING
BUMP|PERSPECTIVE_MAPPING
PHONG|PERSPECTIVE_MAPPING
FLAT|AMBIANT_MAPPING
NOTHING|AMBIANT_MAPPING
GOURAUD|AMBIANT_MAPPING
PHONG|AMBIANT_MAPPING
REMEMBER!!!!! In fake 16 bits mode it's impossible to use texture with
more than 256 colors when using shaded modes. But it's possible when
using not shaded modes.
ie FLAT|MAPPING ---> Texture MUST be 256 colors
NOTHING|PERSPECTIVE_MAPPING ---> Texture could be 256 colors or more
(in 8 bits modes, ie 256 color modes (PVM_PALETIZED8))
FLAT|NOTHING
GOURAUD|NOTHING
PHONG|NOTHING
BUMP|NOTHING
FLAT|MAPPING
NOTHING|MAPPING
GOURAUD|MAPPING
BUMP|MAPPING
PHONG|MAPPING
FLAT|PERSPECTIVE_MAPPING
NOTHING|PERSPECTIVE_MAPPING
GOURAUD|PERSPECTIVE_MAPPING
BUMP|PERSPECTIVE_MAPPING
PHONG|PERSPECTIVE_MAPPING
FLAT|AMBIANT_MAPPING
NOTHING|AMBIANT_MAPPING
GOURAUD|AMBIANT_MAPPING
PHONG|AMBIANT_MAPPING
(in full RGB modes, PVM_RGB)
FLAT|NOTHING
GOURAUD|NOTHING
PHONG|NOTHING
NOTHING|MAPPING
FLAT|MAPPING
GOURAUD|MAPPING
NOTHING|PERSPECTIVE_MAPPING
FLAT|PERSPECTIVE_MAPPING
GOURAUD|PERSPECTIVE_MAPPING
NOTHING|AMBIANT_MAPPING
FLAT|AMBIANT_MAPPING
GOURAUD|AMBIANT_MAPPING
The flags names are pretty self explanatory, but PHONG is not really
phong shading, but a FakePhong using a kind of environement mapping.
Phong does not take into account lights in the scene, instead the phong
light is positionned at the camera position.
PERSPECTIVE_MAPPING is an affine mapping corrected every 16 pixels.
BUMP mapping rely on FakePhong shading and hence has the same
limitations.
When using the PERSPECTIVE_MAPPING flag, you can add the AUTOMATIC
flag, in this case the engine will try to determine if the perspective
correction is needed for each polygons. Works not very well, but could
be useful.
ie: FLAT|PERSPECTIVE_MAPPING|AUTOMATIC
Camera (PVCam struct)
---------------------
typedef struct _Camera
{
char *Name;
float fieldofview;
unsigned Height,Width;
float roll,pitch,yaw;
float xscreenscale,yscreenscale,fscale;
Point pos;
Point target;
Mat3x3 Matrix; // [0][x]=vright [1][x]=vup [2][x]=***
} PVCam;
nothing special here, see 3dsview.c for ideas. The important thing to remenber is to correctly
setup Height,Width and fieldofview according to suit your eyes :)
A camera has 2 positionning system. One wich is based on the camera position and the
camera's target position (pos and target field) and one wich is based on position and roll,
pitch yaw. Choose one of these methods and use the appropriates API functions PV_SetCamAngles or
PV_SetCamTarget. See 3dsview for side-effects when using them simultaneously.
Lights (PVLight struct)
-----------------------
typedef enum _PVLightType {PVL_DIRECTIONAL,PVL_PARALLEL,PVL_INFINITEPOINT,PVL_POINT,PVL_SPOT,PVL_USER_LIGHT} PVLightType;
#define LIGHT_NORMAL 0
#define LIGHT_FORGET 1 // Switch off the light
typedef struct _TLight
{
char *Name;
PVLightType Type;
PVFLAGS Flags;
RGBF Color;
float Intensity;
float Range;
float Attenuation0,Attenuation1,Attenuation2;
float FallOff,Theta,Phi;
float cosTh,cosPh;
Point Position;
Point Direction;
Point Target;
struct _TLight *Next;
void *UserData;
} PVLight;
Very straight forward here. Color field is ignored when not in PVM_RGB mode.
Flags is used to switch off/on lights.
Meshes (PVMesh struct)
----------------------
typedef struct _PVMesh
{
char *Name;
PVFLAGS Flags;
unsigned int NbrFaces,NbrVertexes,NbrVisibles,NbrBoxes;
Point Pivot;
char *VertexVisible;
unsigned nbrclipf,nbrclipv; // Nombre de faces clipps
PVClippedFace *ClippedOrg; // pt originaux
Point OldPos,OldPosv,Pos;
Mat3x3 OldMatrix,OldMatrixv,Matrix;
float ScaleX,ScaleY,ScaleZ;
PVVertex *Vertex;
PVFace *Face;
PVMapInfo *Mapping;
Point *Rotated;
PVScreenPoint *Projected;
PVFace **Visible;
PVShadeInfo *Shading;
PVBox *Box;
void *UserData;
struct _PVMesh *Next;
} PVMesh;
[QUICK EXPLANATION MODE ON]
Main fields are:
ScaleX,ScaleY,ScaleZ, wich are the scaling factors
to apply to the object regarding the original size (the original mesh
is NOT modified however).
Pivot : which is the pivot point coordinates (center of rotation)
Pos : which indicates the position of the mesh in the world
Matrix : which is the rotation matrix applied to the mesh (the original mesh
is NOT modified however)..
For other infos see 3DStudio readers.
[QUICK EXPLANATION MODE OFF]
World (PVWorld struct)
----------------------
typedef struct _PVWorld
{
unsigned NbrFaces,NbrVertexes,NbrVisibles;
unsigned NbrObjs;
RGBF AmbiantLight;
PVMaterial *Materials;
PVFace **Visible;
PVMesh *Objs;
PVLight *Lights;
UPVD8 ReservedColors;
RGB *Global256Palette;
} PVWorld;
[QUICK EXPLANATION MODE ON]
AmbiantLight: color of the ambiant light
Global256Palette: When in PVM_PALETIZED8 mode, quantized palette used to
render world.
ReservedColors: When in PVM_PALETIZED8 mode, number of color left
to the user at the beginning of Global256Palette.
[QUICK EXPLANATION MODE OFF]
Hierarchy
---------
World
|
|------ Lights
|
|------ Ambiant Light
|
|------ Materials
| |--- Render flags
| |--- Textures
|------ Meshes
|
|--- Bouding Boxes
|--- Faces
|--- Vertexes
|--- Normals
When you create a world you need to create meshes, material, Lights and attach all these object to
the world (see 3dsread.c to see how it is done).
Once everything is created and linked, you need to 'compile' meshes and materials.
Application skeleton:
---------------------
* World, camera creation
* camera assignation
* mesh creation
* materials creation
* Set RGB modes
* Set PV working mode
* mesh compilation
* material compilation
* enjoy!
* Garbage collection and world destruction
Mesh compilation
----------------
This phase creates links beetwen the 'MaterialName' of each face, and the material which have the same
name in the material list of the world. This set up the 'Filler' field of each face to the adress
of the routine which will handle the correct rendering. The selection is done with the flags
affected to the material (FLAT|MAPPING by example).
Material Compilation
--------------------
This phase converts material's texture to a format suitable for fast rendering according to the
value of PVMode (PV_SetMode()), the value fixed by PV_SetRGBIndexingMode() and the ReservedColors
field in the world struct.
It also computes MipMaps on mipmapped materials.
After these two steps you should *NOT* change one of the parameters linked with display (RGB pixel
format, Rendering Mode and so on).
This process could be very long, especially in paletized mode.
World Rendering
---------------
Very simple first call PV_ComputeWorld(MyWorld), and then PV_RenderWorld(MyWorld,MyBuffer) where
MyBuffer must be big enough to handle the image rendered. MyBuffer could be the video memory.
Cleaning house
--------------
When finished with PV, destroy all the objects you created (Worlds and Cameras) and call
PV_GarbageCollector() to free some more memory (rendering buffers allocated 'on fly' during
the rendering stage).
PV_GarbageCollector() could be called wherever you want but be warned that it could decrease
performance if PV have to recreate the freeed buffers.
User defined lights & triangle filler
-------------------------------------
DOC TO BE DONE
just look at pvision.h for the flags & call back functions :)
---------------------------------------------------------
Panard Motion
---------------------------------------------------------
Usage
-----
include pmotion.h and 3dspm.h if you want to read anim from .3ds and link with pvision.lib.
Overview:
--------
PM is a basic hierarchical animation system.
PM is based on quaternions to interpolate angles in 3D-Space.
ease, cont bias and non linear stuffs are not yet implemented.
Details:
-------
See 3dspm.c :)
-----------------------------------------------------------------------
Contact & Infos
------------------
- The code for the 3DStudio driver is heavily stolen from the code of
JARE/IGUANA
- Additional documentation for 3ds files are taken from
'The Unofficial 3DStudio 3DS File Format' by Jeff Lewis
(werewolf@worldgate.com)
- Useful Help and hints from Adept/Esteem for 3ds (adept@aquanet.co.il)
- and my brain.
If you find bugs, or have suggestions or just want to tell me what you
think of this, contact me.
You can contact me at:
bruneto@efrei.fr (Olivier Brunet)
or visit:
http://www.efrei.fr/~bruneto/pvision (Home of Panard Vision)
Olivier Brunet
近期下载者:
相关文件:
收藏者: