Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cieniowanie_003
- #include <stdlib.h>
- #include <GL/glut.h>
- #include <math.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- struct color
- {
- float a,b,c;
- /*
- color CMYnaRGB(color &CMY){
- color RGB;
- RGB.a=1-CMY.a;
- RGB.b=1-CMY.b;
- RGB.c=1-CMY.c;
- return RGB;
- }
- */
- };
- class punkt{
- public:
- float x,y,wartosc;
- int id;
- color kolor;
- };
- class dane : public punkt{
- public:
- punkt tab[192];
- float max,min,odc,skok,przedzial;
- bool paleta;
- void wczytaj(string nazwa_pliku){
- ifstream plik;
- plik.open(nazwa_pliku.c_str());
- if(!plik.good())
- cout << "Blad wczytywania pliku... plik nie istnieje!" << endl;
- else{
- for(int i = 0; i<192; i++){
- plik>>tab[i].x;
- plik>>tab[i].y;
- plik>>tab[i].wartosc;
- tab[i].id=i;
- }
- plik.close();
- }
- }
- void MaxMin(){
- min=10000,max=0;
- for(int i=0;i<192;i++)
- {
- if(tab[i].wartosc<min)
- min=tab[i].wartosc;
- if(tab[i].wartosc>max)
- max=tab[i].wartosc;
- }
- przedzial=max-min;
- skok=przedzial/100;
- }
- void PrzypiszKolor(){
- float podzial;
- podzial=(max-min)/4;
- float a,b;
- a=min;
- b=min+skok;
- float x=0.0,y=0.0,z=1.0;
- for(int j=0;j<=100;j++)
- {
- for(int i=0;i<192;i++)
- {
- if(tab[i].wartosc>=a && tab[i].wartosc<=b)
- {
- tab[i].kolor.a=x;
- tab[i].kolor.b=y;
- tab[i].kolor.c=z;
- }
- }
- if(j<25)
- {
- y+=0.04;
- }
- if(j>=25&&j<50)
- {
- z-=0.04;
- }
- if(j>=50&&j<75)
- {
- x+=0.04;
- }
- if(j>=75&&j<100)
- {
- y-=0.04;
- }
- a=b;
- b+=skok;
- if(j==99)
- {b+=10;
- x=0;}
- }
- for (int i=0;i<192;i++)
- {
- tab[i].x/=10;
- tab[i].y/=100;
- tab[i].wartosc=-tab[i].wartosc;
- }
- }
- void Rysuj(){
- glBegin(GL_QUAD_STRIP);
- glVertex2f(-1,0.2);
- glVertex2f(-1,0);
- glVertex2f(0,0.2);
- glVertex2f(0,0);
- glEnd();
- glEnable( GL_BLEND );
- glBlendFunc( GL_ONE, GL_ONE );
- glBegin(GL_QUAD_STRIP);
- glColor3f(0.3,0.0,0.7); glVertex2f(-0.7,0.);
- glColor3f(0.3,0.0,0.7); glVertex2f(-0.7,0);
- glColor3f(0.3,0.0,0.7); glVertex2f(0,0.7);
- glColor3f(0.3,0.0,0.7); glVertex2f(0,0);
- glEnd();
- for(int i=0;i<31;i++)
- {
- glBegin(GL_QUAD_STRIP);
- glColor3f(tab[i].kolor.a,tab[i].kolor.b,tab[i].kolor.c); glVertex2f(tab[i].x,tab[i].y);
- glColor3f(tab[i+1].kolor.a,tab[i+1].kolor.b,tab[i+1].kolor.c); glVertex2f(tab[i+1].x,tab[i+1].y);
- glColor3f(tab[i+32].kolor.a,tab[i+32].kolor.b,tab[i+32].kolor.c); glVertex2f(tab[i+32].x,tab[i+32].y);
- glColor3f(tab[i+33].kolor.a,tab[i+33].kolor.b,tab[i+33].kolor.c); glVertex2f(tab[i+33].x,tab[i+33].y);
- glEnd();
- }
- for(int i=32;i<63;i++)
- {
- glBegin(GL_QUAD_STRIP);
- glColor3f(tab[i].kolor.a,tab[i].kolor.b,tab[i].kolor.c); glVertex2f(tab[i].x,tab[i].y);
- glColor3f(tab[i+1].kolor.a,tab[i+1].kolor.b,tab[i+1].kolor.c); glVertex2f(tab[i+1].x,tab[i+1].y);
- glColor3f(tab[i+32].kolor.a,tab[i+32].kolor.b,tab[i+32].kolor.c); glVertex2f(tab[i+32].x,tab[i+32].y);
- glColor3f(tab[i+33].kolor.a,tab[i+33].kolor.b,tab[i+33].kolor.c); glVertex2f(tab[i+33].x,tab[i+33].y);
- glEnd();
- }
- for(int i=64;i<95;i++)
- {
- glBegin(GL_QUAD_STRIP);
- glColor3f(tab[i].kolor.a,tab[i].kolor.b,tab[i].kolor.c); glVertex2f(tab[i].x,tab[i].y);
- glColor3f(tab[i+1].kolor.a,tab[i+1].kolor.b,tab[i+1].kolor.c); glVertex2f(tab[i+1].x,tab[i+1].y);
- glColor3f(tab[i+32].kolor.a,tab[i+32].kolor.b,tab[i+32].kolor.c); glVertex2f(tab[i+32].x,tab[i+32].y);
- glColor3f(tab[i+33].kolor.a,tab[i+33].kolor.b,tab[i+33].kolor.c); glVertex2f(tab[i+33].x,tab[i+33].y);
- glEnd();
- }
- for(int i=96;i<127;i++)
- {
- glBegin(GL_QUAD_STRIP);
- glColor3f(tab[i].kolor.a,tab[i].kolor.b,tab[i].kolor.c); glVertex2f(tab[i].x,tab[i].y);
- glColor3f(tab[i+1].kolor.a,tab[i+1].kolor.b,tab[i+1].kolor.c); glVertex2f(tab[i+1].x,tab[i+1].y);
- glColor3f(tab[i+32].kolor.a,tab[i+32].kolor.b,tab[i+32].kolor.c); glVertex2f(tab[i+32].x,tab[i+32].y);
- glColor3f(tab[i+33].kolor.a,tab[i+33].kolor.b,tab[i+33].kolor.c); glVertex2f(tab[i+33].x,tab[i+33].y);
- glEnd();
- }
- for(int i=128;i<159;i++)
- {
- glBegin(GL_QUAD_STRIP);
- glColor3f(tab[i].kolor.a,tab[i].kolor.b,tab[i].kolor.c); glVertex2f(tab[i].x,tab[i].y);
- glColor3f(tab[i+1].kolor.a,tab[i+1].kolor.b,tab[i+1].kolor.c); glVertex2f(tab[i+1].x,tab[i+1].y);
- glColor3f(tab[i+32].kolor.a,tab[i+32].kolor.b,tab[i+32].kolor.c); glVertex2f(tab[i+32].x,tab[i+32].y);
- glColor3f(tab[i+33].kolor.a,tab[i+33].kolor.b,tab[i+33].kolor.c); glVertex2f(tab[i+33].x,tab[i+33].y);
- glEnd();
- }
- }
- /*
- color RGBnaCMY (){
- this->kolor.a = 1 - this->kolor.a;
- this->kolor.b = 1 - this->kolor.b;
- this->kolor.c = 1 - this->kolor.c;
- return this->kolor;
- }
- void wybierz_palete(){
- cout<< "podaj czy paleta ma byc RGB(1) czy CMY(0)?" << endl;
- cin>>this->paleta;
- if (paleta == 0){
- for (int i = 0; i<192; i++){
- tab[i].kolor =
- }
- }
- }*/
- };
- void Display() // funkcja generuj�ca scen� 3D
- {
- glClearColor( 0.0, 0.0, 0.0, 1.0 ); // kolor t�a - zawarto�� bufora koloru
- glClear( GL_COLOR_BUFFER_BIT ); // czyszczenie bufora koloru
- glColor3f( 0.0, 1.0, 0.0 ); // kolor rysowania
- /* tu wywoluje sie wszystkie funkcje... */
- string test = "dane_testowe.txt";
- dane d1;
- d1.wczytaj(test);
- d1.MaxMin();
- //d1.wybierz_palete();
- d1.PrzypiszKolor();
- d1.Rysuj();
- glFlush();
- glutSwapBuffers(); // zamiana bufor�w koloru
- }
- void Reshape( int width, int height )
- {
- Display(); // generowanie sceny 3D
- }
- int main( int argc, char * argv[] )
- {
- glutInit( & argc, argv ); // inicjalizacja biblioteki GLUT
- glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); // inicjalizacja bufora ramki
- glutInitWindowSize( 400, 400 ); // rozmiary g��wnego okna programu
- glutCreateWindow( "Cieniowanie | Mieszanie | Przezroczystosc" ); // utworzenie g��wnego okna programu
- glutDisplayFunc( Display ); // do��czenie funkcji generuj�cej scen� 3D
- glutReshapeFunc( Reshape ); // do��czenie funkcji wywo�ywanej przy zmianie rozmiaru okna
- glutMainLoop(); // wprowadzenie programu do obs�ugi p�tli komunikat�w
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement