/[cvs]/api/Classes/Engine3d/Engine3d.cpp
ViewVC logotype

Contents of /api/Classes/Engine3d/Engine3d.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (22 years, 10 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 #include "Engine3d.h"
2 #include "../System/SystemDefine.h"
3 #include "../System/System.h"
4 #include "../String/String.h"
5 #include "../Graphic2d/DrawSprite.h"
6
7 Engine3d::Engine3d(int* ichunkybuffer, int iscreenwidth, int iscreenheight)
8 {
9 chunkybuffer=ichunkybuffer;
10 screenwidth=iscreenwidth;
11 screenheight=iscreenheight;
12
13 String fileName="data/texturer/1.rgb";
14 sgi=new SGI(fileName);
15 // System::println(sgi->getWidth());
16 // System::println(sgi->getHeight());
17 textureList=null;
18 }
19
20 Engine3d::~Engine3d()
21 {
22 if (sgi!=null)
23 {
24 delete sgi;
25 }
26
27 if (textureList!=null)
28 {
29 delete textureList;
30 }
31 }
32
33 void Engine3d::init()
34 {
35
36 zc=0;
37 zc2=20;
38
39 char filedirectory[7]={'d','a','t','a','/',0};
40
41 tmapare_= new TMapare(chunkybuffer, screenwidth, screenheight);
42 TPolytri_= new TPolytri();
43 textureList = new ObjectLinkedList<SGI>();
44 objekt3dlist_[0] = new Object3dList();
45 clipping3d_[0] = new Clipping3d(screenwidth,screenheight,zc, zc2);
46 lwoLoader[0] = new LwoLoader(objekt3dlist_, textureList);
47
48 // char filename[20]={'d','a','t','a','/','o','b','j','e','c','t','/','k','u','b','.','l','w','o',0};
49 // char filename2[22]={'d','a','t','a','/','o','b','j','e','c','t','/','b','o','l','l','.','l','w','o',0};
50
51 String fileName="data/object/kub.lwo";
52 String fileName2="data/object/boll.lwo";
53
54 lwoLoader[0]->scanLwoFile(fileName2);
55 lwoLoader[0]->scanLwoFile(fileName);
56
57 objekt3d_[0]=objekt3dlist_[0]->get(0);
58
59 }
60
61 void Engine3d::draw_polygons(Object3d *objekt3d_, TPolytri *TPolytri_, TMapare *tmapare_, Clipping3d *clipping3d_)
62 {
63 int step2=0;
64
65 for ( int oo=0 ; oo<objekt3d_->getnumberofpolys() ; oo++ )
66 {
67 if ( objekt3d_->getvisiblypolys(oo) != 0 )
68 {
69 if ( objekt3d_->getz(objekt3d_->getpoints(step2+0)) > zc || objekt3d_->getz(objekt3d_->getpoints(step2+1)) > zc || objekt3d_->getz(objekt3d_->getpoints(step2+2)) > zc )
70 {
71 if ( zc2 > objekt3d_->getz(objekt3d_->getpoints(step2+0)) || zc2 > objekt3d_->getz(objekt3d_->getpoints(step2+1)) || zc2 > objekt3d_->getz(objekt3d_->getpoints(step2+2)) )
72 {
73
74 int whichTexture=objekt3d_->gettpoints(oo);
75 SGI *texture=(SGI*)objekt3d_->gettexturep(whichTexture);
76
77 if (texture->getBuffer()>null)
78 {
79 TPolytri_->texture=texture->getBuffer();
80
81 clipping3d_->clipPolygonAgainst6Planes(objekt3d_, oo);
82
83 int step=0;
84
85 while (clipping3d_->getClippedData(TPolytri_, step))
86 {
87 clipping3d_->getClippedData(TPolytri_, step);
88 tmapare_->drawtpolyperspsubtri(TPolytri_);
89 step++;
90 }
91 }
92 }
93 }
94 }
95
96 step2+=3;
97 }
98
99 }
100
101 void Engine3d::clearchunkybuffer(int *chunkybuffer, int screenwidth, int screenheight)
102 {
103 for ( int y=0; y<screenheight ; y++ )
104 {
105 for ( int x=0; x<screenwidth ; x++ )
106 {
107 chunkybuffer[x+y*screenwidth]=0;
108 }
109 }
110
111 }
112
113 void Engine3d::run(float speed, float mousex, float mousey, float mousez )
114 {
115 clearchunkybuffer(chunkybuffer, screenwidth, screenheight);
116
117 DrawSprite::sprite(sgi,20,0);
118 objekt3d_[0]->objectspline(mousex,mousey,mousez);
119 objekt3d_[0]->objectsmulmatrix();
120 objekt3d_[0]->initbackfacecull();
121 objekt3d_[0]->backfacecull();
122 objekt3d_[0]->calculaterotation();
123
124 draw_polygons(objekt3d_[0], TPolytri_,tmapare_, clipping3d_[0]);
125
126 }

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26