home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 February
/
Chip_2001-02_cd1.bin
/
bonus
/
demos
/
CS
/
exp
/
SOURCES
/
DEMO
/
EFEKT_13.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
2000-08-19
|
4KB
|
176 lines
/*
RAY TORUS KNOT 3ds viewer
return:
0 - doslo k chybe
1 - este nezacal
2 - prebehol v poriadku
3 - uz skoncil
*/
#include <iostream>
#include "api3ds.h"
#include "efekt.h"
#include "efekt_13.h"
extern int sync_num;
int efekt_13::init()
{
start=TRUE;
counter=ZACIATOK13*refresh;
glClearColor (cl_r, cl_g, cl_b, 1.0);
x_pos=0.0;
inten=0.0;
l1=dynamic_cast<OmniLight3DS*>(sce->GetLight("Omni01"));
l2=dynamic_cast<OmniLight3DS*>(sce->GetLight("Omni02"));
return 1;
}
int efekt_13::load()
{
cout << "Loading efekt13 ... ";
FILE *stream=fopen(CFGNAME13,"r");
if (stream==NULL) return 0;
fscanf(stream,"file name %s\n",scene_name);
fscanf(stream,"camera name %s\n",camera_name);
fscanf(stream,"begin %f\n",&begin3d);
fscanf(stream,"end %f\n",&end3d);
fscanf(stream,"background color %f,%f,%f\n",&cl_r,&cl_g,&cl_b);
fscanf(stream,"lightning %i\n",&lgt);
fscanf(stream,"fog %i\n",&fog);
fscanf(stream,"fog color %f,%f,%f\n",&fg_r,&fg_g,&fg_b);
fscanf(stream,"fog density %f\n",&fgd);
fscanf(stream,"visibility %f\n",&vis);
fscanf(stream,"minvisibility %f\n",&minvis);
fscanf(stream,"hfov,vfov (PI/x) %f,%f\n",&hfov,&vfov);
fscanf(stream,"render %i\n",&render);
fscanf(stream,"rays %i\n",&rays);
fscanf(stream,"outline %i\n",&obrysy);
fscanf(stream,"outline color %f,%f,%f\n",&ob_r,&ob_g,&ob_b);
fscanf(stream,"outline width %i\n",&ob_wdt);
fscanf(stream,"object name %s\n",object_name);
fclose(stream);
Loader3DS loader;
sce = loader.Load(scene_name,texture_library);
if (sce==NULL) return 0;
cout << "ok!"<<endl;
return 1;
}
int efekt_13::free()
{
return 1;
}
int efekt_13::update()
{
if ((counter/refresh)>153.5)
{
x_pos-=0.00002;
}
else
{
if (x_pos<1.0) x_pos+=0.005;
}
if ((counter/refresh)>157.5)
{
x_pos-=0.01;
Vector3f l1d=l1->Diffuse();
Vector3f l2d=l2->Diffuse();
l1->Diffuse(l1d*0.95F);
l2->Diffuse(l2d*0.95F);
if (inten>0.0) inten-=2;
else inten=0.0;
}
else
{
if (inten<550) inten+=2.6;
}
return 1;
}
int efekt_13::go(double t)
{
if (t<ZACIATOK13) return 1;
if (t<begin3d) return 1;
if (end) return 3;
if (counter>=KONIEC13*refresh) return free();
if (!start) if (!init()) return 0;
int cur_frm=(int)(t*refresh);
if (cur_frm>KONIEC13*refresh) cur_frm=int(KONIEC13*refresh);
if (cur_frm>counter)
while (counter<cur_frm)
{
counter++;
if (counter<KONIEC13*refresh) update();
}
if (counter>=KONIEC13*refresh) return free();
//tu sa kresli->
if (lgt)
{
glEnable(GL_LIGHTING);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
}
else
glDisable(GL_LIGHTING);
if (fog)
{
GLfloat fc[4] = {fg_r,fg_g,fg_b, 1.0};
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogfv(GL_FOG_COLOR, fc);
glFogf(GL_FOG_DENSITY, fgd);
}
else glDisable(GL_FOG);
float frejm=(t-begin3d)/(end3d-begin3d);
kam = sce->GetCamera(camera_name);
kam->FarClipplane(vis);
kam->NearClipplane(minvis);
kam->HorizontalFOV(PI/hfov);
kam->VerticalFOV(PI/vfov);
kam->GL(frejm);
if (render)
{
GLfloat len=kam->Origin(frejm).Len();
GLmatrix m, p;
glMatrixMode(GL_MODELVIEW);
glGetFloatv(GL_MODELVIEW_MATRIX, m());
p.Identity();
p.Translate( (90*sin(x_pos*PI/2) - 150)*len/300, 0, 0);
m = p*m;
glLoadMatrixf(m());
sce->Render(frejm);
}
if (obrysy||rays)
{
Object3DS* object = dynamic_cast<Object3DS*>(sce->GetObject(object_name));
if(object)
{
Vector3f S( 0.0, 200.0, 0.0);
Vector3f C=kam->Origin(frejm);
if (rays) object->Rays(C, S, inten, GL_ONE, GL_ONE);
if (obrysy) object->Outline (C, 8, 1.0,1.0,1.0);
}
}
//<-
return 2;
}