void display(void)
{
	lPosition();

	///////////////////////////////////////////////////////////////////////////////////////////////////////
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glColor3f (1.0, 1.0, 1.0);
	glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);			//Texturing Contour Anchored To The Object
	glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);			//Texturing Contour Anchored To The Object

	//glEnable(GL_TEXTURE_GEN_S);										//Auto Texture Generation
	//glEnable(GL_TEXTURE_GEN_T);										//Auto Texture Generation
	glEnable(GL_TEXTURE_2D);
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	stars();
	//glBindTexture(GL_TEXTURE_2D, g_cactus[1]);
	//gluSphere(g_text,0.4,48,48);
	stars();
	sun();
	adam();
	hesper();
	earth();
	mars();
	jupiter();
	saturn();
	uranus();
	neptune();
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	glDisable(GL_TEXTURE_2D);		
	//glDisable(GL_TEXTURE_GEN_S);										//Auto Texture Generation
	//glDisable(GL_TEXTURE_GEN_T);
	glutSwapBuffers();
}
Exemplo n.º 2
0
// Draw method
void displayFcn()
{
  int xc = winWidth / 2, yc = winHeight / 2;
  float green[3] = {0.0, 0.75, 0.0};
  float orange[3] = {1.0, 0.6, 0};
  float red[3] = {1.0, 0.0, 0.0};
  float blue[3] = {0.0, 0.0, 1.0};

  // Clear display window.
  glClear(GL_COLOR_BUFFER_BIT);  

  glColor3f(1.0, 0.0, 0.0);

  Sun sun("Sun", xc, yc, 3.0);

  glColor3fv(green);
  Planet earth("Earth", xc, yc, 1.0, 1.0);

  glColor3fv(orange);
  Planet mercury("Mercury", xc, yc, 0.382, 0.39);

  glColor3fv(blue);
  Planet venus("Venus", xc, yc, 0.949, 0.72);

  glColor3fv(red);
  Planet mars("Mars", xc, yc, 0.532, 1.52);


  glFlush( );
}
Exemplo n.º 3
0
void TimeSource::addSolarPositionData(const QDateTime &dt)
{
    Sun* s = sun();
    s->calcForDateTime(dt, m_offset);
    setData(QStringLiteral("Azimuth"), s->azimuth());
    setData(QStringLiteral("Zenith"), 90.0 - s->altitude());
    setData(QStringLiteral("Corrected Elevation"), s->calcElevation());
}
Exemplo n.º 4
0
Moon* TimeSource::moon()
{
    if (!m_moon) {
        m_moon = new Moon(sun());
    }
    m_moon->setPosition(m_latitude, m_longitude);
    return m_moon;
}
Exemplo n.º 5
0
void selectType(char *type, Particle **p) {
	if (!strcmp(type, "bouble"))		bouble(&(*p));
	if (!strcmp(type, "smoke"))		smoke(&(*p));
	if (!strcmp(type, "water"))		water(&(*p));
	if (!strcmp(type, "ball"))			ball(&(*p));
	if (!strcmp(type, "wind"))			wind(&(*p));
	if (!strcmp(type, "siva"))			siva(&(*p));
	if (!strcmp(type, "sun"))			sun(&(*p));
}
Exemplo n.º 6
0
	void configure() {
		SphericalCoordinates sun(m_sun);
		sun.elevation *= m_stretch;
		m_sunDir = toSphere(sun);

		/* Solid angle covered by the sun */
		m_theta = degToRad(SUN_APP_RADIUS * 0.5f);
		m_solidAngle = 2 * M_PI * (1 - std::cos(m_theta));
		m_radiance = computeSunRadiance(m_sun.elevation, m_turbidity) * m_scale;
	}
Exemplo n.º 7
0
int main()
{
	int gdriver = DETECT, gmode = VGAMAX;
	initgraph(&gdriver, &gmode, "NONE");
	field();
	sun();
	hut();
	delay(1000);
	return 0;
}
Exemplo n.º 8
0
/* OpenGL calls this routine to display the scene
*/ 
void display(){

	//Eye position
	double Ex = -2*dim*Sin(th)*Cos(ph);
	double Ey = +2*dim        *Sin(ph);
	double Ez = +2*dim*Cos(th)*Cos(ph);
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	
	//Set perspective
	glLoadIdentity();
	gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
	
	//Let there be light
	if(light)
		sun();
	 else{
		glDisable(GL_LIGHTING);
	}
	//Texture stuff
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

	shininess = 10;
	float green[]   = {0.0, 0.01*diffuse, 0.0,1.0};
	glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white2);
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black2);
	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green);
	tree(16.5, 0, 0,    5, 4, 1, texture[3]);
	tree(19, 0, 2,    6, 5, 25, texture[3]);
	tree(19, 0, 0.5,    3, 3, 35, texture[3]);
	tree(-20, 0, -10,   8, 3, 50, texture[3]);
	tree(-3, 0, 5,   6, 5, 1, texture[3]);
	tree(-6, 0, 6,  8 , 3.5, 30, texture[3]);
	
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
	glBindTexture(GL_TEXTURE_2D,texture[2]);
    //Draw flat plane
    drawflat(0,0,0, 100, 100, 0, .95, 0);   
	
	drawToolBar();
    //  Display parameters
    glWindowPos2i(5,5);
   // Print("Angle=%d,%d  Dim=%.1f Light=%.1f",th,ph,dim);
    //Print("Angle=%d,%d  Dim=%.1f Light=%s",th,ph,dim,light?"On":"Off");
	
	drawHouse(GL_RENDER, -7,0, 0,    0,     3, 5, 3.4,   2,   .85,.8,0,  .9,.9,0, .7,.7,0,   0.9,.8,0, texture[1], texture[5]);
	
	//Render the scene and make it visible
    //ErrCheck("display");
    glFlush();
    glutSwapBuffers();
}
Exemplo n.º 9
0
void lightSourceAndSun(){

	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = { 50.0 };
	GLfloat light1_diffuse[] = { 1, 1, 1, 10 };
	GLfloat position[] = { 0.0, 2.0, -0.3, 1.0 };

	glLightfv(GL_LIGHT0, GL_DIFFUSE, light1_diffuse);
	glLightfv(GL_LIGHT0, GL_POSITION, position);
	glDisable(GL_LIGHTING);
	sun(0.0, 2.0, -0.3, 0.0, 1.0, 0.0, 1.0);
	glEnable(GL_LIGHTING);
}
Exemplo n.º 10
0
void TimeSource::addDailySolarPositionData(const QDateTime &dt)
{
    Sun* s = sun();
    QList< QPair<QDateTime, QDateTime> > times = s->timesForAngles(
            QList<double>() << -0.833 << -6.0 << -12.0 << -18.0, dt, m_offset);

    setData(QStringLiteral("Sunrise"), times[0].first);
    setData(QStringLiteral("Sunset"), times[0].second);
    setData(QStringLiteral("Civil Dawn"), times[1].first);
    setData(QStringLiteral("Civil Dusk"), times[1].second);
    setData(QStringLiteral("Nautical Dawn"), times[2].first);
    setData(QStringLiteral("Nautical Dusk"), times[2].second);
    setData(QStringLiteral("Astronomical Dawn"), times[3].first);
    setData(QStringLiteral("Astronomical Dusk"), times[3].second);
}
Exemplo n.º 11
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	glPushMatrix();	
	gluLookAt(eye.x, eye.y, eye.z, at.x, at.y, at.z, up.x, up.y, up.z);

	sun();
	alpha_proxima();

	//glFlush();
	glPopMatrix();
	glutSwapBuffers();
}
Exemplo n.º 12
0
    void
    init_SunEarth( memory::Domain<floatType>& myDomain )
    {
      const memory::vector3D<double> rE( 0.0, simParams::distance_Sun_Earth, 0.0 );
      const memory::vector3D<double> vE( simParams::EarthSpeed, 0.0, 0.0 );
      //memory::vector3D<double> vE( 0.0, simParams::EarthSpeed, 0.0 );
      memory::Particle<double> earth( rE, vE, simParams::mass * simParams::partialEarthSun );

      const memory::vector3D<double> rS( 0.0, 0.0, 0.0 );
      const memory::vector3D<double> vS( 0.0, 0.0, 0.0 );
      memory::Particle<double> sun( rS, vS, simParams::mass );

      // initialize particles
      myDomain.addParticle( earth );
      myDomain.addParticle( sun );
    }
Exemplo n.º 13
0
void Assignment1::Init()
{
	// Init VBO here
	glClearColor(0.0f, 0.7f, 1.0f, 0.0f);
	//enable depth test 
	glEnable(GL_DEPTH_TEST);

	rotateAngle = 1;
	translateX = 1;
	scaleAll = 1;
	flyBack = 1;
	cloudMovement = 1;
	explosionRotation = 1;
	explosionSize = 1;
	sizeValue;
	//Generate a default VAO for now 
	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	//generate buffers
	glGenBuffers(NUM_GEOMETRY, &m_vertexBuffer[0]);
	glGenBuffers(NUM_GEOMETRY, &m_colorBuffer[0]);

	landScape();
	clouds();
	sun();
	explosion();
	cactus();

	//Load vertex and fragment shaders
	m_programID = LoadShaders(
		"Shader//TransformVertexShader.vertexshader",
		//"Shader//SimpleVertexShader.vertexshader",
		"Shader//SimpleFragmentShader.fragmentshader"
		);

	//Get a handle for our "MVP" uniform
	m_parameters[U_MVP] = glGetUniformLocation(m_programID, "MVP");
	// Use our shader
	glUseProgram(m_programID);

}
Exemplo n.º 14
0
void CSatNote::SunPosShow(CommonTime m_realTime)
{
	cJulian m_real(m_realTime.year,m_realTime.month,m_realTime.day,
		           m_realTime.hour,m_realTime.minute,m_realTime.second);
	m_real.addHour(-8);
	cSun sun(m_real);
	m_sunLon=sun.GetSunPos().getPoint3D().x;
	m_sunLat=sun.GetSunPos().getPoint3D().y;
	
	CString m_lon,m_lat;
	m_lon.Format("%.3lf",m_sunLon);
	m_lat.Format("%.3lf",m_sunLat);
	CString str1,str2;
	str1="经度:";
	str2="纬度:";
	m_lon=str1+m_lon+"度";
	m_lat=str2+m_lat+"度";
	GetDlgItem(IDC_NOTE_LONG)->SetWindowText(m_lon);
	GetDlgItem(IDC_NOTE_LAT)->SetWindowText(m_lat);


}
Exemplo n.º 15
0
std::vector<NS_CORE KpdZac> CalcKinCharacteristics::calcKpdZacStepen( const NS_CORE InternalGearRatios& intRatios, const std::vector<NS_CORE W>& w, const std::vector<NS_CORE N>& n )
{
	std::vector<NS_CORE KpdZac> ret;

	NS_CORE Log::warning( w.size() != n.size(), "Wrong size", NS_CORE Log::eWarningImportance::CRITICAL, HERE );

	const int size = w.size();
	const int planetaryGearsCount = NS_CORE Singletons::getInstance()->getInitialData()._numberOfPlanetaryGears;
	ret.resize( size );

	for ( int i = 0; i < size; i++ )
	{
		for ( NS_CORE GearSetNumber gearSet( 1 ); gearSet.getValue() <= planetaryGearsCount; ++gearSet )
		{
			NS_CORE Element sun( NS_CORE eMainElement::SUN_GEAR, gearSet );
			NS_CORE Element epy( NS_CORE eMainElement::EPICYCLIC_GEAR, gearSet );
			NS_CORE Element car( NS_CORE eMainElement::CARRIER, gearSet );

			double kpdA = 1;
			double kpdB = 1;
			const double ksi_a_c = 0.02;
			const double ksi_b_c = 0.01;
			const auto k = intRatios[gearSet.getValue() - 1];

			if ( n[i].at( sun ) == '0' && n[i].at( epy ) == '0' && n[i].at( car ) == '0' )
			{
				kpdA = 1;
				kpdB = 1;
			}
			else if ( w[i].at( sun ) && w[i].at( epy ) && w[i].at( car ) )
			{
				NS_CORE Element sun( NS_CORE eMainElement::SUN_GEAR, gearSet );
				NS_CORE Element epy( NS_CORE eMainElement::EPICYCLIC_GEAR, gearSet );

				IFunction_p func = Function::create( k, w[i], n[i], gearSet );
				kpdB = SolveFunctionDiv::create()->calc( func, 0.8f, 1.0f );
				kpdA = 2 * kpdB - 1;
				kpdA = pow( kpdA, -Function::sign( n[i].at( sun ) ) );
				kpdB = pow( kpdB, -Function::sign( n[i].at( epy ) ) );
			}
			else if ( !w[i].at( sun ) && w[i].at( epy ) && w[i].at( car ) )
			{
				double kpdSum = 1 - 1.0f / ( 1 + k.getValue() ) * ( ksi_a_c + ksi_b_c );
				kpdA = 1 / kpdSum;
				kpdB = pow( kpdSum, -Function::sign( n[i].at( epy ) ) );
			}
			else if ( w[i].at( sun ) && !w[i].at( epy ) && w[i].at( car ) )
			{
				double kpdSum = 1 - k.getValue() / ( 1.0f + k.getValue() ) * ( ksi_a_c + ksi_b_c );
				kpdA = pow( kpdSum, -Function::sign( n[i].at( sun ) ) );
				kpdB = 1 / kpdSum;
			}
			else if ( w[i].at( sun ) && w[i].at( epy ) && !w[i].at( car ) )
			{
				kpdA = 1 - ksi_a_c;
				kpdB = 1 - ksi_b_c;
				kpdA = pow( kpdA, -Function::sign( n[i].at( sun ) ) );
				kpdB = pow( kpdB, -Function::sign( n[i].at( epy ) ) );
			}
			else if (!w[i].at(sun) && !w[i].at(epy) && !w[i].at(car))
			{
				//empty gear
				kpdA = 1;
				kpdB = 1;
			}
			else
			{
				NS_CORE Log::warning( true, "Can't calculate KPD", NS_CORE Log::CRITICAL, HERE );
			}

			ret[i][gearSet]._kpdA = kpdA;
			ret[i][gearSet]._kpdB = kpdB;
		}
	}

	return ret;
}
Exemplo n.º 16
0
void draw(void)
{
    glDisable(GL_TEXTURE_2D);
    up_sider = up_sider + .05;
    sx = carx + (x_sl*cos(-temp) - 0.5*sin(-temp));
    sy = cary + (x_sl*sin(-temp) + 0.5*cos(-temp));

    tx = carx + (0.6*cos(temp) - 0.5*sin(-temp));
    ty = cary + (0.6*sin(temp) + 0.5*cos(-temp));

    r_tx = carx + (0.8*cos(temp) - 0.5*sin(-temp));
    r_ty = cary + (0.8*sin(temp) + 0.5*cos(-temp));

    keydown();
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    if(FLAG==1)
        gluLookAt(R*cos(alpha)*sin(theta),R*sin(alpha)*sin(theta),-4 +R*cos(theta),0,0,-4,0,0,-1);
    if(FLAG==2)
        gluLookAt(carx - 3*sin(temp),cary - 3*cos(temp) ,-5.5,carx + 5*sin(temp) ,cary + 5*cos(temp) ,-4,0,0,-1);
    if(FLAG==3) {
        gluLookAt(carx + 0.14*sin(temp) ,cary + 0.14*cos(temp) ,-5.02,carx + 2*sin(temp) ,cary + 2*cos(temp) ,-4.9,0,0,-1);
    }
    if(FLAG==4) {
        gluLookAt(sx ,sy ,-5.51,sx + 3*sin(temp) ,sy + 3*cos(temp) ,-4.6,0,0,-1);
    }
    if(FLAG==5) {

        gluLookAt(sx ,sy,-6.00,sx + 2*sin(up_sider),sy + 2*cos(up_sider) ,-5.3,0,0,-1);
    }
    if(FLAG==6) {
        gluLookAt(tx,ty,-4.5,r_tx ,r_ty,-4.5,0,0,-1);
    }
    if(FLAG==7) {
        gluLookAt(car1x - 3*cos(temp1),car1y - 3*sin(temp1) ,-5.5,car1x + 5*cos(temp1) ,car1y + 5*sin(temp1) ,-4,0,0,-1);
    }

    glPushMatrix();
    glColor3f(1.0,1.0,1.0);
    glTranslatef(0,0,-4);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texture_id[1]);
//            glTexCoord2i(0,0);
//	glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
//	 glEnable(GL_TEXTURE_2D);
//	 glBindTexture(GL_TEXTURE_2D,texture_id[1]);
    for(i=-200; i<200; i++) {
        for(p=-200; p<200; p++) {
            glTexCoord2i(0,0);

            glVertex3f(i,p,0.0);
            glTexCoord2i(1,0);

            glVertex3f(i+1,p,0.0);
            glTexCoord2i(1,1);

            glVertex3f(i+1,p+1,0.0);
            glTexCoord2i(0,1);

            glVertex3f(i,p+1,0.0);
        }
    }
//	 glDisable(GL_TEXTURE_2D);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    car();
    car1();
    glPushMatrix();
    sun();

//    ******new track formation***********
    glColor3f(1.0,1.0,1.0);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texture_id[2]);
//	glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
//		glBindTexture(GL_TEXTURE_2D,texture_id[2]);

    glTexCoord2i(0,0);
    glVertex3f(-17.0,-27.0,-0.1);
    glTexCoord2i(0,1);
    glVertex3f(-11.0,-27.0,-0.1);
    glTexCoord2i(1,1);
    glVertex3f(-11.0,20.0,-0.1);
    glTexCoord2i(1,0);
    glVertex3f(-17.0,20.0,-0.1);


    glTexCoord2i(0,0);
    glVertex3f(-14.0,-13.0,-0.05);
    glTexCoord2i(0,1);
    glVertex3f(-14.0,-7.0,-0.05);
    glTexCoord2i(1,1);
    glVertex3f(10.0,-7.0,-0.05);
    glTexCoord2i(1,0);
    glVertex3f(10.0,-13.0,-0.05);


    /// elvated roof

    //****upper surface*****
    glColor3f(0.0,0.0,0.0);
    glVertex3f(-8.0,-12.5,-3.1);

    glVertex3f(-8.0,-7.5,-3.1);
    glVertex3f(7.0,-7.5,-3.1);
    glVertex3f(7.0,-12.5,-3.1);

    //*****side surfaces*****
    glVertex3f(-8.0,-7,-0.1);
    glVertex3f(-8.0,-7.5,-3.1);
    glVertex3f(7.0,-7.5,-3.1);
    glVertex3f(7.0,-7,-0.1);


    glVertex3f(-8.0,-13,-0.1);
    glVertex3f(-8.0,-12.5,-3.1);
    glVertex3f(7.0,-12.5,-3.1);
    glVertex3f(7.0,-13,-0.1);

///done
    glColor3f(1.0,1.0,1.0);
    glTexCoord2i(0,0);
    glVertex3f(16.0,-7.3,-0.1);
    glTexCoord2i(0,1);
    glVertex3f(10.0,-7.3,-0.1);
    glTexCoord2i(1,1);
    glVertex3f(10.0,20.4,-0.1);
    glTexCoord2i(1,0);
    glVertex3f(16.0,20.4,-0.1);

    glTexCoord2i(0,0);
    glVertex3f(16.0,20,-0.1);
    glTexCoord2i(0,1);
    glVertex3f(16.0,26.0,-0.1);
    glTexCoord2i(1,1);
    glVertex3f(26.0,26.0,-0.1);
    glTexCoord2i(1,0);
    glVertex3f(26.0,20.0,-0.1);

    glTexCoord2i(0,0);
    glVertex3f(29.0,20,-0.1);
    glTexCoord2i(0,1);
    glVertex3f(23.0,20.0,-0.1);
    glTexCoord2i(1,1);
    glVertex3f(23.0,-30.0,-0.1);
    glTexCoord2i(1,0);
    glVertex3f(29.0,-30.0,-0.1);

    glTexCoord2i(0,0);
    glVertex3f(23.0,-30,-0.1);
    glTexCoord2i(0,1);
    glVertex3f(23.0,-24,-0.1);
    glTexCoord2i(1,1);
    glVertex3f(-12.0,-24.0,-0.1);
    glTexCoord2i(1,0);
    glVertex3f(-12.0,-30.0,-0.1);


    glEnd();
    glColor3f(0.0,0.0,0.0);
    glDisable(GL_TEXTURE_2D);
    glPushMatrix(); //turn
    glTranslatef(-14.0,-10.0,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<360; i++) {
        glVertex3f(6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();

    glPushMatrix(); //turn
    glTranslatef(10.0,-7.0,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<180; i++) {
        glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();


    glPushMatrix(); //turn
    glTranslatef(16.0,20.0,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<180; i++) {
        glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();


    glPushMatrix(); //turn
    glTranslatef(26.0,20.3,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<180; i++) {
        glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();

    glPushMatrix(); //turn
    glTranslatef(26.0,25.7,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<180; i++) {
        glVertex3f(-6*cos(i*3.14/180),6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();


    glPushMatrix(); //turn
    glTranslatef(-11.0,-26,-0.01);
    glBegin(GL_TRIANGLE_FAN);
    for(i=0; i<180; i++) {
        glVertex3f(6*cos(i*3.14/180),-6*sin(i*3.14/180),-0.0);
    }
    glEnd();
    glPopMatrix();


    glLineWidth(5.0);
    glPushMatrix();
    glTranslatef(10.0,-30.0,-0.01);
    while(M<6.0) {
        glBegin(GL_LINE_LOOP);
        for(i=0; i<180; i++) {
            glVertex3f((13+M)*cos(i*3.14/180),-(13+M)*sin(i*3.14/180),0.0);
        }

        glEnd();
        M = M + .005;
    }
    glPopMatrix();
    M=0;
    glLineWidth(1.0);

//	glTranslatef(0,0,-4);
    glPopMatrix();

    //glRotatef(-60,1,0,0);
    //glRotatef(t,0,0,1);
    glPopMatrix();
//	pc();
    //t+=0.01;
    glutSwapBuffers();
}
Exemplo n.º 17
0
void ProceduralSky::_update_sky() {

	update_queued = false;

	PoolVector<uint8_t> imgdata;

	static const int size[TEXTURE_SIZE_MAX] = {
		1024, 2048, 4096
	};

	int w = size[texture_size];
	int h = w / 2;

	imgdata.resize(w * h * 4); //RGBE

	{
		PoolVector<uint8_t>::Write dataw = imgdata.write();

		uint32_t *ptr = (uint32_t *)dataw.ptr();

		Color sky_top_linear = sky_top_color.to_linear();
		Color sky_horizon_linear = sky_horizon_color.to_linear();

		Color ground_bottom_linear = ground_bottom_color.to_linear();
		Color ground_horizon_linear = ground_horizon_color.to_linear();

		//Color sun_linear = sun_color.to_linear();

		Vector3 sun(0, 0, -1);

		sun = Basis(Vector3(1, 0, 0), Math::deg2rad(sun_latitude)).xform(sun);
		sun = Basis(Vector3(0, 1, 0), Math::deg2rad(sun_longitude)).xform(sun);

		sun.normalize();

		for (int i = 0; i < w; i++) {

			float u = float(i) / (w - 1);
			float phi = u * 2.0 * Math_PI;

			for (int j = 0; j < h; j++) {

				float v = float(j) / (h - 1);
				float theta = v * Math_PI;

				Vector3 normal(
						Math::sin(phi) * Math::sin(theta) * -1.0,
						Math::cos(theta),
						Math::cos(phi) * Math::sin(theta) * -1.0);

				normal.normalize();

				float v_angle = Math::acos(normal.y);

				Color color;

				if (normal.y < 0) {
					//ground

					float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5);
					color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve));
				} else {
					float c = v_angle / (Math_PI * 0.5);
					color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve));

					float sun_angle = Math::rad2deg(Math::acos(sun.dot(normal)));

					if (sun_angle < sun_angle_min) {
						color = color.blend(sun_color);
					} else if (sun_angle < sun_angle_max) {

						float c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);
						c2 = Math::ease(c2, sun_curve);

						color = color.blend(sun_color).linear_interpolate(color, c2);
					}
				}

				ptr[j * w + i] = color.to_rgbe9995();
			}
		}
	}

	Ref<Image> image;
	image.instance();
	image->create(w, h, false, Image::FORMAT_RGBE9995, imgdata);

	VS::get_singleton()->texture_allocate(texture, w, h, Image::FORMAT_RGBE9995, VS::TEXTURE_FLAG_FILTER | VS::TEXTURE_FLAG_REPEAT);
	VS::get_singleton()->texture_set_data(texture, image);
	_radiance_changed();
}
Exemplo n.º 18
0
int main() {
  // msaa
  glfwWindowHint(GLFW_SAMPLES, 4);
  GLFWwindow * window = initWindow(windowWidth, windowHeight);
  if (!window) {
    glfwTerminate();
    return -1;
  }
  glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
  glfwSetKeyCallback(window, key_callback);
  glfwSetCursorPosCallback(window, cursor_callback);
  glfwSetScrollCallback(window, scroll_callback);

  glEnable(GL_DEPTH_TEST);

  // prepare texture loading library(devil)
  init_texture_loading();

  //plane
  Shader simpleDepthShader("data/shaders/shadow_mapping_depth.vs", "data/shaders/shadow_mapping_depth.frag");

  Model ourModel("data/models/nanosuit/nanosuit.obj");

  GLfloat planeVertices[] = {
    // Positions          // Normals         // Texture Coords
    2.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f,
    -2.0f, 0.0f, -2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 2.0f,
    -2.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,

    2.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f,
    2.0f, 0.0f, -2.0f, 0.0f, 1.0f, 0.0f, 2.0f, 2.0f,
    -2.0f, 0.0f, -2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 2.0f
  };

  // Setup plane VAO xzhs
  GLuint planeVBO;
  GLuint woodTexture;
  GLuint rockTexture;
  glGenVertexArrays(1, &planeVAO);
  glGenBuffers(1, &planeVBO);
  glBindVertexArray(planeVAO);
  glBindBuffer(GL_ARRAY_BUFFER, planeVBO);
  glBufferData(GL_ARRAY_BUFFER, sizeof(planeVertices), &planeVertices, GL_STATIC_DRAW);
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0);
  glEnableVertexAttribArray(1);
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
  glEnableVertexAttribArray(2);
  glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
  glBindVertexArray(0);

  // Load textures
  woodTexture = load_texture("data/textures/wood.png");
  rockTexture = load_texture("data/textures/rock.jpg");

  // Configure depth map FBO
  const GLuint SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
  GLuint depthMapFBO;
  glGenFramebuffers(1, &depthMapFBO);
  // - Create depth texture
  GLuint depthMap;
  glGenTextures(1, &depthMap);
  glBindTexture(GL_TEXTURE_2D, depthMap);

  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
  GLfloat borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);

  glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
  glDrawBuffer(GL_NONE);
  glReadBuffer(GL_NONE);
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  glClearColor(0.1f, 0.1f, 0.1f, 1.0f);

  //xzhe

  Shader shaders("data/shaders/shader.vert", "data/shaders/shader.frag");
  Shader colorShaders("data/shaders/shaderColorUniform.vert",
                      "data/shaders/shaderColorUniform.frag");
  Shader domeShaders("data/shaders/dome.vert", "data/shaders/dome.frag");
  Shader lightShaders("data/shaders/lightShader.vert", "data/shaders/lightShader.frag");
  Shader spriteShaders("data/shaders/spriteShader.vert", "data/shaders/spriteShader.frag");
  Shader starShaders("data/shaders/spriteShader.vert", "data/shaders/stars.frag");

  std::cout << "Loading models..." << std::endl;
  Model dome("data/models/geodesic_dome.obj");
  Model landscape("data/models/landscape.obj");
  std::cout << "Models loaded!" << std::endl;

  std::cout << "Loading extra textures..." << std::endl;
  GLuint domeColor = load_texture("data/textures/sky.png", true, GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
  GLuint domeGlow = load_texture("data/textures/glow.png", true, GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);

  Sprite sun("data/textures/sun.png");
  Sprite moon("data/textures/moon.png");
  Sprite star("data/textures/star.png");

  // enable blending!
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // enable msaa(multisample anti-aliasing)
  glEnable(GL_MULTISAMPLE);

  std::vector<glm::mat4> starModels(256);
  for (auto& m : starModels) {
    m = glm::rotate(m, glm::radians(rand_rotate()), glm::vec3(1.0f, 0.0f, 0.0f));
    m = glm::rotate(m, glm::radians(rand_rotate()), glm::vec3(0.0f, 1.0f, 0.0f));
    m = glm::rotate(m, glm::radians(rand_rotate()), glm::vec3(0.0f, 0.0f, 1.0f));
    m = glm::translate(m, glm::vec3(5.0f, 0.0f, 0.0f));
    m = glm::rotate(m, glm::radians(rand_rotate()), glm::vec3(1.0f, 0.0f, 0.0f));
    m = glm::rotate(m, glm::radians(rand_rotate()), glm::vec3(0.0f, 1.0f, 0.0f));
  }

  double last_frame = glfwGetTime();
  while (!glfwWindowShouldClose(window)) {
    double current_frame = glfwGetTime();
    double delta_time = current_frame - last_frame;
    last_frame = current_frame;

    glfwPollEvents();

    do_movement(delta_time);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glViewport(0, 0, windowWidth, windowHeight);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)windowWidth / (float)windowHeight, 0.1f, 100.0f);
    glm::mat4 view = camera.GetViewMatrix();

    // sun
    float sunAngle = current_frame * 30.0f;
    glm::mat4 sunModel;
    sunModel = glm::rotate(sunModel, glm::radians(sunAngle), glm::vec3(0.0f, 0.0f, 1.0f));
    sunModel = glm::translate(sunModel, glm::vec3(3.5f, 0.0f, 0.0f));
    glm::vec3 sunPos = glm::vec3(sunModel * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));

    // moon
    float moonAngle = sunAngle + 180.0f;
    glm::mat4 moonModel;
    moonModel = glm::rotate(moonModel, glm::radians(moonAngle), glm::vec3(0.0f, 0.0f, 1.0f));
    moonModel = glm::translate(moonModel, glm::vec3(3.5f, 0.0f, 0.0f));

    // directional light
    DirLight dirLight(-sunPos, glm::vec3(0.8f, 0.8f, 0.8f));

    // point light
    GLfloat light_pos_angle = glm::radians(60.0f * current_frame);
    glm::vec3 light_pos(1.2f + sin(light_pos_angle), 0.0f, 2.0f + cos(light_pos_angle));
    glm::vec3 lightColor(1.0f, 1.0f, 1.0f);
    lightColor.r = sin(current_frame * 2.0f);
    lightColor.g = sin(current_frame * 0.7f);
    lightColor.b = sin(current_frame * 1.3f);
    PointLight pointLight(light_pos, lightColor * 0.5f);

    // spot light
    SpotLight spotLight(camera.Position, camera.Front,
                        glm::vec3((GLfloat)flash_light_on));

    shaders.Use();
    shaders.SetUniform("view", view);
    shaders.SetUniform("projection", projection);
    shaders.SetUniform("ViewPos", camera.Position);
    dirLight.SetUniforms(shaders, "dirLight");
    pointLight.SetUniforms(shaders, "pointLights[0]");
    shaders.SetUniform("pointLightCount", 0);
    spotLight.SetUniforms(shaders, "spotLight");
    shaders.SetUniform("material.shininess", 16.0f);

    colorShaders.Use();
    colorShaders.SetUniform("view", view);
    colorShaders.SetUniform("projection", projection);
    colorShaders.SetUniform("ViewPos", camera.Position);
    dirLight.SetUniforms(colorShaders, "dirLight");
    //pointLight.SetUniforms(colorShaders, "pointLights[0]");
    colorShaders.SetUniform("pointLightCount", 0);
    spotLight.SetUniforms(colorShaders, "spotLight");
    colorShaders.SetUniform("material.shininess", 1.8f);

    // make the dome and landscape pinned
    glm::mat4 pinnedView = glm::lookAt(glm::vec3(0.0f, 1.0f, 0.0f),
                                       glm::vec3(0.0f, 1.0f, 0.0f) + camera.Front,
                                       glm::vec3(0.0f, 1.0f, 0.0f));

    if (enable_stars) {
      // stars
      starShaders.Use();
      starShaders.SetUniform("view", view);
      starShaders.SetUniform("projection", projection);
      starShaders.SetUniform("groundBases[0]", 1.0f, 0.0f, 0.0f);
      starShaders.SetUniform("groundBases[1]", 0.0f, 0.0f, 1.0f);
      starShaders.SetUniform("groundUp", 0.0f, 1.0f, 0.0f);
      starShaders.SetUniform("sunPos", sunPos);
      for (const auto& m : starModels) {
        glm::mat4 model = glm::rotate(glm::mat4(), glm::radians(sunAngle), glm::vec3(0.0f, 0.0f, 1.0f)) * m;
        starShaders.SetUniform("model", model);
        star.Draw(starShaders);
      }
    }

    colorShaders.Use();
    glm::mat4 lmodel;
    lmodel = glm::scale(lmodel, glm::vec3(3.0f, 3.0f, 3.0f));
    lmodel = glm::translate(lmodel, glm::vec3(0.0f, 0.1f, 0.0f));
    lmodel = glm::rotate(lmodel, glm::radians(30.0f), glm::vec3(0.0f, 1.0f, 0.0f));
    glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(lmodel)));
    colorShaders.SetUniform("view", view);
    colorShaders.SetUniform("model", lmodel);
    colorShaders.SetUniform("normalMatrix", normalMatrix);
    colorShaders.SetUniform("Color", glm::vec4(0.93f, 0.79f, 0.69f, 1.0f));
    landscape.Draw(colorShaders, false);

    domeShaders.Use();
    domeShaders.SetUniform("view", view);
    domeShaders.SetUniform("projection", projection);
    glActiveTexture(GL_TEXTURE7);
    glBindTexture(GL_TEXTURE_2D, domeColor);
    glActiveTexture(GL_TEXTURE8);
    glBindTexture(GL_TEXTURE_2D, domeGlow);
    domeShaders.SetUniform("domeColor", 7);
    domeShaders.SetUniform("glow", 8);
    glm::mat4 dmodel;
    dmodel = glm::scale(dmodel, glm::vec3(4.0f, 4.0f, 4.0f));
    domeShaders.SetUniform("model", dmodel);
    domeShaders.SetUniform("sunPos", sunPos);
    dome.Draw(domeShaders, false);

    // cheating billboarding to make the sun and moon always face the camera
    glm::mat4 sunModelView = view * sunModel;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        sunModelView[i][j] = (GLfloat)(i == j);
    sunModelView = glm::scale(sunModelView, glm::vec3(0.5f, 0.5f, 0.5f));
    glm::mat4 moonModelView = view * moonModel;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        moonModelView[i][j] = (GLfloat)(i == j);
    moonModelView = glm::scale(moonModelView, glm::vec3(0.5f, 0.5f, 0.5f));

    spriteShaders.Use();
    spriteShaders.SetUniform("view", glm::mat4());
    spriteShaders.SetUniform("projection", projection);
    spriteShaders.SetUniform("model", sunModelView);
    sun.Draw(spriteShaders);
    spriteShaders.SetUniform("model", moonModelView);
    moon.Draw(spriteShaders);

    //xzhs
    // Set texture samples
    shaders.Use();
    glActiveTexture(GL_TEXTURE13);
    glBindTexture(GL_TEXTURE_2D, woodTexture);
    glActiveTexture(GL_TEXTURE14);
    glBindTexture(GL_TEXTURE_2D, rockTexture);
    glActiveTexture(GL_TEXTURE15);
    glBindTexture(GL_TEXTURE_2D, depthMap);
    shaders.SetUniform("material.texture_diffuse1", 14);
    shaders.SetUniform("material.texture_specular1", 14);
    shaders.SetUniform("shadowMap", 15);

    // 1. Render depth of scene to texture (from light's perspective)
    // - Get light projection/view matrix.
    glm::mat4 lightProjection, lightView;
    glm::mat4 lightSpaceMatrix;
    GLfloat near_plane = 1.0f, far_plane = 7.5f;

    lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
    lightView = glm::lookAt(sunPos, glm::vec3(0.0f), glm::vec3(1.0));
    lightSpaceMatrix = lightProjection * lightView;
    // - now render scene from light's point of view
    simpleDepthShader.Use();
    simpleDepthShader.SetUniform("lightSpaceMatrix", lightSpaceMatrix);

    glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
    glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
    glClear(GL_DEPTH_BUFFER_BIT);
    RenderFloor(simpleDepthShader);
    RenderCubes(simpleDepthShader);

    glm::mat4 nmodel;
    nmodel = glm::translate(nmodel, glm::vec3(0.1f, 0.3f, -0.5f));
    nmodel = glm::rotate(nmodel, glm::radians(70.0f), glm::vec3(0.0f, 1.0f, 0.0f));
    nmodel = glm::scale(nmodel, glm::vec3(0.05f, 0.05f, 0.05f));
    simpleDepthShader.SetUniform("model", nmodel);
    ourModel.Draw(simpleDepthShader);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // 2. Render scene as normal
    glViewport(0, 0, windowWidth, windowHeight);
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaders.Use();
    shaders.SetUniform("projection", projection);
    shaders.SetUniform("view", view);
    shaders.SetUniform("ViewPos", camera.Position);
    // Set light uniforms
    // PointLight sunPointLight(sunPos, glm::vec3(0.02f, 0.02f, 0.02f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.5f, 0.5f, 0.5f));
    // sunPointLight.SetUniforms(shaders, "pointLights[0]");
    // shaders.SetUniform("pointLightCount", 0);
    dirLight.SetUniforms(shaders, "dirLight");
    shaders.SetUniform("pointLightCount", 0);

    shaders.SetUniform("lightSpaceMatrix", lightSpaceMatrix);

    shaders.SetUniform("material.texture_diffuse1", 14);
    shaders.SetUniform("material.texture_specular1", 14);
    shaders.SetUniform("shadowMap", 15);
    RenderFloor(shaders);
    shaders.SetUniform("material.texture_diffuse1", 13);
    shaders.SetUniform("material.texture_specular1", 13);
    RenderCubes(shaders);
    shaders.SetUniform("model", nmodel);
    ourModel.Draw(shaders);
    //xzhe

    glfwSwapBuffers(window);
  }

  glfwTerminate();
  return 0;
}
Exemplo n.º 19
0
// Create Objects
void TestScene::SetupObjects()
{    
    spObject sun(new Object);
    sun->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    sun->GetTransform().SetScale(Vector3(2.f, 2.f, 2.f));
    Texture sunTexture;
    LoadTexture(sunTexture, "textures/texture_sun.png");
    sun->GetVO()->GetTexture() = sunTexture;
    sun->SetGLMode(GL_TRIANGLES);
    sun->EnableTexture();
    sun->SetName(L"Sun");
    objects.push_back(sun);
    objectMap.insert(std::make_pair(sun->GetName(), sun));

    spObject world(new Object);
    world->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    world->GetTransform().SetPosition(Vector3(5.f, 0.f, 0.f));
    Texture worldTexture;
    LoadTexture(worldTexture, "textures/4kworld.png");
    world->GetVO()->GetTexture() = worldTexture;
    world->SetGLMode(GL_TRIANGLES);
    world->EnableTexture();
    world->SetName(L"Earth");
    world->SetParent(sun.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(world);
    objectMap.insert(std::make_pair(world->GetName(), world));


    spObject clouds(new Object);
    clouds->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    clouds->GetTransform().SetScale(Vector3(1.01f, 1.01f, 1.01f));
    Texture cloudTexture;
    LoadTexture(cloudTexture, "textures/clouds.png");
    clouds->GetVO()->GetTexture() = cloudTexture;
    clouds->SetGLMode(GL_TRIANGLES);
    clouds->EnableTexture();
    clouds->EnableTransparency();
    clouds->SetName(L"Clouds");
    clouds->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(clouds);
    objectMap.insert(std::make_pair(clouds->GetName(), clouds));

    //spObject disc(new Object);
    //disc->SetVO(new PrimitiveDisc(64));
    //Texture discTexture;
    //LoadTexture(discTexture, "crate.png");
    //disc->GetVO()->GetTexture() = discTexture;
    //disc->SetGLMode(GL_TRIANGLE_FAN);
    //disc->GetTransform().SetPosition(Vector3(2.5f, 0.0f, 0.0f));
    //disc->EnableTexture();
    //disc->SetName(L"Disc");
    //objects.push_back(disc);

    spObject moon(new Object);
    moon->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    moon->GetTransform().SetScale(Vector3(0.27f, 0.27f, 0.27f));
    moon->GetTransform().SetPosition(Vector3(0.f, 0.f, -2.2f));
    Texture moonTexture;
    LoadTexture(moonTexture, "textures/moonmap1k.png");
    moon->GetVO()->GetTexture() = moonTexture;
    moon->SetGLMode(GL_TRIANGLES);
    moon->EnableTexture();
    moon->SetName(L"Moon");
    moon->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(moon);
    objectMap.insert(std::make_pair(moon->GetName(), moon));

    spObject hst(new Object);
    hst->SetVO(MakeShareable(new Model));
    static_cast<Model*>(hst->GetVO().Get())->Load("models/hst.obj", "textures/hst.png");
    hst->GetTransform().SetScale(Vector3(0.0001f, 0.0001f, 0.0001f)); // This thing is yuge!
    hst->GetTransform().SetPosition(Vector3(-1.1f, 0.f, 0.f));
    hst->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.25f, 0.25f, -0.25f)));
    hst->GetTransform().SetRotation(Rotation(0.f, Vector3(-0.2f, 0.8f, -0.2f)));
    hst->SetGLMode(GL_TRIANGLES);
    hst->SetName(L"HST");
    hst->EnableTexture();
    hst->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(hst);
    objectMap.insert(std::make_pair(hst->GetName(), hst));

    spObject iss(new Object);
    iss->SetVO(MakeShareable(new Model));
    static_cast<Model*>(iss->GetVO().Get())->Load("models/iss.obj", "textures/iss.png");
    iss->GetTransform().SetScale(Vector3(0.01f, 0.01f, 0.01f));
    iss->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.f, 0.5f, 0.f)));
    iss->GetTransform().SetRotation(Rotation(0.f, Vector3(0.25f, 0.5f, 0.25f)));
    iss->GetTransform().SetPosition(Vector3(0.f, 0.f, 1.2f));
    iss->SetGLMode(GL_TRIANGLES);
    iss->SetName(L"ISS");
    iss->EnableTexture();
    iss->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(iss);
    objectMap.insert(std::make_pair(iss->GetName(), iss));

    spObject teapot(new Object);
    teapot->SetVO(MakeShareable(new Model));
    static_cast<Model*>(teapot->GetVO().Get())->Load("Models/teapot.obj", "textures/teapot.png");
    teapot->GetTransform().SetPosition(Vector3(5.f, 5.f, -3.f));
    teapot->GetTransform().SetPreRotation(Rotation(0.f, Vector3(1.f, 0.f, 0.f)));
    teapot->GetTransform().SetRotation(Rotation(0.f, Vector3(0.f, 0.f, 1.f)));
    teapot->GetTransform().SetScale(Vector3(0.05f, 0.05f, 0.05f));
    teapot->SetGLMode(GL_TRIANGLES);
    teapot->SetName(L"Teapot");
    teapot->EnableTexture();
    teapot->SetParent(iss.Get(), TransformInheritance(true, true, true, false));
    objects.push_back(teapot);
    objectMap.insert(std::make_pair(teapot->GetName(), teapot));
}
Exemplo n.º 20
0
int main(int argc, char* argv[])
{
	LibVolume::Window::Window window;
	window.setTitle("Nilts");

	LibVolume::Engine::Realm realm;
	realm.linkTo(window);

	realm.background_colour = glm::vec3(4.0, 3.0, 8.0) * 0.2f;

	//Move a kilometre out
	realm.camera.state.position = glm::vec3(1000.0, 1000.0, 64.0);

	LibVolume::Render::Structures::Light sun(LibVolume::Render::Structures::LightType::Directional, glm::vec3(0.8, 0.25, -1.0), glm::vec3(3.0, 3.0, 3.9) * 0.4f, 0.2);
	realm.addLight(sun);

	LibVolume::Engine::VoxelTerrain terrain(glm::ivec3(32, 32, 32), LibVolume::Engine::MeshingAlgorithm::MarchingCubes, false, true);

	realm.addObject(terrain);

	while (window.tick() == false)
	{
		glm::f64vec3 new_camera_position = realm.camera.state.position;

		if (window.event_manager.keyboard_state.key_down)
			new_camera_position += (glm::f64vec3(0.0, 0.0, 3.0) * 0.02) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_right)
			new_camera_position += (glm::f64vec3(3.0, 0.0, 0.0) * 0.02) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_left)
			new_camera_position += (glm::f64vec3(-3.0, 0.0, 0.0) * 0.02) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_up)
			new_camera_position += (glm::f64vec3(0.0, 0.0, -3.0) * 0.02) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_space)
			new_camera_position += (glm::f64vec3(0.0, 3.0, 0.0) * 0.02) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_shift)
			new_camera_position += (glm::f64vec3(0.0, -3.0, 0.0) * 0.02) * realm.camera.state.orientation;

		//Stop the camera moving if it's going to go inside the terrain
		/*if (terrain.existsAt((glm::vec3)(new_camera_position / 32.0)))
		{
			if (terrain.getAt((glm::vec3)new_camera_position / 32.0f)->getDensityAt(glm::mod((glm::vec3)new_camera_position, 32.0f)) < 0.5)
				realm.camera.state.position = new_camera_position;
		}
		else*/
			realm.camera.state.position = new_camera_position;

		if (terrain.existsAt((glm::vec3)(realm.camera.state.position / 32.0)))
		{
			while (terrain.getAt((glm::vec3)realm.camera.state.position / 32.0f)->getDensityAt(glm::mod((glm::vec3)realm.camera.state.position, 32.0f)) > 0.5)
			{
				realm.camera.state.position += terrain.getAt((glm::vec3)new_camera_position / 32.0f)->getNormalAt(glm::mod((glm::vec3)new_camera_position, 32.0f)) * 0.01f;
			}
		}

		if (window.event_manager.keyboard_state.key_a)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(0.0, -0.03, 0.0)) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_d)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(0.0, 0.03, 0.0)) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_w)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(0.03, 0.0, 0.0)) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_s)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(-0.03, 0.0, 0.0)) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_q)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(0.0, 0.0, -0.03)) * realm.camera.state.orientation;
		if (window.event_manager.keyboard_state.key_e)
			realm.camera.state.orientation = glm::f64quat(glm::vec3(0.0, 0.0, 0.03)) * realm.camera.state.orientation;

		for (int x = -2; x < 3; x ++)
		{
			for (int y = -2; y < 3; y ++)
			{
				for (int z = 0; z < 2; z ++)
				{
					loadAt(glm::ivec3(x, y, z) + glm::ivec3(realm.camera.state.position.x, realm.camera.state.position.y, 0) / 32, terrain);
					//terrain.getAt(glm::ivec3(x, y, z))->extract(LibVolume::Engine::MeshingAlgorithm::MarchingCubes);
				}
			}
		}

		realm.tick();
		realm.render();
	}

	return 0;
}
Exemplo n.º 21
0
int main()
{
   double PI = 4*std::atan(1.0);
   clock_t start, finish;
   std::string dimension = "AU"; //can be 'AU' or 'ly'

//-------------------------------------------------------------
   /* problem a)
    * additional functionality as parallelisation
    * and adaptive timesteps in other classes was commented out
    * while generating plots and time for this part*/
//-------------------------------------------------------------
   //initialize sun
   std::string nameSun = "sun";
   arma::Col<double> positionSun(3), velocitySun(3);
   double massSun = 1.0; //SolarMass
   positionSun.zeros();
   velocitySun.zeros();

   //initialize earth
   std::string nameEarth = "earth";
   arma::Col<double> positionEarth(3), velocityEarth(3);
   double massEarth = 3e-6; //solarmass
   positionEarth.zeros();
   velocityEarth.zeros();

   //declare solar system
   System solarsystem;

   positionEarth(0) = 1.0;
   velocityEarth(1) = -2*PI;


   //Declaration of objects
   Object earth(positionEarth,velocityEarth, massEarth, nameEarth);
   Object sun(positionSun, velocitySun, massSun, nameSun);

   //add objects to system
   solarsystem.addObject(sun);
   solarsystem.addObject(earth);

   std::string nameAdd = "rk4";
   earth.newFile(nameAdd);
   sun.newFile(nameAdd);
   SolveStep solver(solarsystem);

   solver.solve(0.01,0.05,"rk4_","rk4", dimension);

   earth.closeFile(nameAdd);
   sun.closeFile(nameAdd);

//-------------------------------------------------------------
   /* problem b)
    * additional functionality in other classes was commented out
    * while generating plots for this part*/
//-------------------------------------------------------------

   //reset sun
   positionSun.zeros();
   velocitySun.zeros();
   earth.setPosition(positionSun);
   earth.setVelocity(velocitySun);

   //reset earth
   positionEarth.zeros();
   velocityEarth.zeros();
   positionEarth(0) = 1.0;
   velocityEarth(1) = -2*PI;
   earth.setPosition(positionEarth);
   earth.setVelocity(velocityEarth);

   //initialize moon
   std::string nameMoon = "moon";
   arma::Col<double> positionMoon(3), velocityMoon(3);
   double massMoon = 3e-6*0.0123; //solarmass
   positionMoon.zeros();
   velocityMoon.zeros();

//   positionMoon(0) = 1.0;
//   positionMoon(1) = -0.00257;
//   velocityMoon(1) = -2*PI;
//   velocityMoon(0) = 0.1668*PI;
   positionMoon(0) = 1.0;
   positionMoon(1) = -2e-3;
   velocityMoon(1) = -2*PI;
   velocityMoon(2) = 0.21544;
   Object moon(positionMoon, velocityMoon, massMoon, nameMoon);

   //declare solar system
   System solarsystemAdapt;

   //add objects to system
   solarsystemAdapt.addObject(sun);
   solarsystemAdapt.addObject(earth);
   solarsystemAdapt.addObject(moon);

   std::string nameAdd = "verletAdapt_";
   earth.newFile(nameAdd);
   sun.newFile(nameAdd);
   moon.newFile(nameAdd);
   SolveStep solverAdapt(solarsystemAdapt);

   double timestep = 1.0;

   start = clock(); //start timer
   solverAdapt.solve(timestep,4.0,nameAdd,"verlet", dimension);
   finish = clock(); //stop timer
   std::cout << "Simulation time: " <<
                static_cast<double>(finish - start)/
                static_cast<double>(CLOCKS_PER_SEC ) << " s" << std::endl;

   earth.closeFile(nameAdd);
   sun.closeFile(nameAdd);
   moon.closeFile(nameAdd);

   //-------------------------------------------------------------
      /* problem c)-->
       * creation of a simple model of an open cluster. The lines
       * in Solvestep that saves every position for every particle
       * is commented out during these calculations. */
   //-------------------------------------------------------------
   dimension = "ly";
   RandomGenerator generate;
   double R0 = 20;
   double epsilon = 1.5*7.3e-11;//7.3e-8;
   int N = 500;
   System mysystem = generate.randomSystem(N, R0);
   mysystem.setEpsilon(epsilon);
   SolveStep solver(mysystem);
   double timestep = 0.1;
   double simulationTime = 10.0;
   std::string fileName = "solve_";
   std::string method = "rk4";


   solver.solve(timestep, simulationTime, fileName, method, dimension);

   std::ofstream fout("start.m");
   fout << "A = [";
   double mass = 0.0;
   for (int i = 0 ; i < mysystem.numberOfObject ; ++i)
   {
      Object &mainbody = mysystem.objectlist[i];

      fout << mainbody.getPosition()(0) << "\t\t" << mainbody.getPosition()(1)
           << "\t\t" << mainbody.getPosition()(2) << "\n";
      mass += mainbody.getMass();
   }
   fout << "] \n";
   fout << "plot3(A(:,1), A(:,2),A(:,3), 'o')";
   fout.close();
   std::cout <<"average mass:"<< mass/static_cast<double>(N) << std::endl;
}
Exemplo n.º 22
0
int main(int , char**)
{
	int width = 1280, height = 760;
	Display mainWindow(width, height, "DEngine");
	//mainWindow.ShowCursor(false);
	mainWindow.WrapMouse(false);

	glm::vec3 lightPosition(-4.0f, 8.0f, -6.0f);
	Light sun(lightPosition, glm::vec3(1.0f, 1.0f, 1.0f), DIRECTIONAL_LIGHT);

	Camera camera(glm::vec3(0.0f, 2.0f, 1.0f));
	camera.SetCameraMode(FLY);
	

	Shader simpleProgram;
	simpleProgram.LoadShaders("./SHADERS/SOURCE/NoNormal_vs.glsl",
		"./SHADERS/SOURCE/NoNormal_fs.glsl");

	Shader skyBoxShaders;
	skyBoxShaders.LoadShaders("./SHADERS/SOURCE/skyBox_vs.glsl",
		"./SHADERS/SOURCE/skyBox_fs.glsl");
	Shader shadowShaders;
	shadowShaders.LoadShaders("./SHADERS/SOURCE/ShadowDepth_vs.glsl",
		"./SHADERS/SOURCE/ShadowDepth_fs.glsl");

	EventListener eventListener(&mainWindow, &camera, &simpleProgram);

	SkyBox sky;
	sky.LoadCubeMap("./Models/skybox");
	
	Model box;
	box.LoadModelFromFile(".\\Models\\Box.obj");
	box.TranslateModel(glm::vec3(0.0f, 2.0f, 0.0f));
	box.meshes[0].AddTexture("./Models/textures/154.png", textureType::DIFFUSE_MAP);
	box.meshes[0].AddTexture("./Models/textures/154_norm.png", textureType::NORMAL_MAP);
	box.meshes[0].AddTexture("./Models/textures/154s.png", textureType::SPECULAR_MAP);
	box.TranslateModel(glm::vec3(0.0f, -0.5f, -2.0f));

	Model floor;
	floor.LoadModelFromFile("./Models/Plane/plane.obj");
	floor.meshes[0].AddTexture("./Models/textures/196.png", textureType::DIFFUSE_MAP);
	floor.meshes[0].AddTexture("./Models/textures/196_norm.png", textureType::NORMAL_MAP);
	floor.meshes[0].AddTexture("./Models/textures/196s.png", textureType::SPECULAR_MAP);
	floor.TranslateModel(glm::vec3(0.0f, -2.0f, 0.0f));
	Clock clock;
	
	while (!mainWindow.isClosed)
	{
		eventListener.Listen();
		clock.NewFrame();

//DRAWING SCENE TO SHADOWMAP		
		//sun.StartDrawingShadows(shadowShaders.programID);
		//
		//glCullFace(GL_FRONT);
		////nanosuit.Draw(&mainWindow, camera, &sun, shadowShaders);
		//box.Draw(&mainWindow, camera, &sun, shadowShaders);
		//floor.Draw(&mainWindow, camera, &sun, shadowShaders);
		//
		//sun.StopDrawingShadows();
		//
		//glCullFace(GL_BACK);
		//glViewport(0, 0, width, height);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//NORMAL DRAWING SCENE		
		simpleProgram.UseProgram();
		glUniformMatrix4fv(glGetUniformLocation(simpleProgram.programID, "lightSpaceMatrix"), 1, GL_FALSE, glm::value_ptr(sun.shadowMatrix));
		glUniform1f(glGetUniformLocation(simpleProgram.programID, "time"), clock.time);
		
		//glActiveTexture(GL_TEXTURE15);
		//glBindTexture(GL_TEXTURE_2D, sun.shadowTexture.textureID);
		//glUniform1i(glGetUniformLocation(simpleProgram.programID, "depth_map"), 15);
		
		
		floor.Draw(&mainWindow, camera, &sun, simpleProgram);
		box.Draw(&mainWindow, camera, &sun, simpleProgram);
		//sky.Draw(&mainWindow, camera, skyBoxShaders);

		camera.Update(clock.deltaTime);
		mainWindow.Update();
	}

	return 0;
}
// main func is temporary ugly
int main(int argc, char ** argv)
{
	srand(time(NULL));

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_ACCUM);
	glutInitWindowPosition(glutGet(GLUT_SCREEN_WIDTH) / 14, glutGet(GLUT_SCREEN_HEIGHT) / 21);
	glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH) * 6 / 7, glutGet(GLUT_SCREEN_HEIGHT) * 6/7);
	int window = glutCreateWindow("Star System");
	//glutFullScreen();

	glEnable(GL_ACCUM);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_LINE_SMOOTH);
	//glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);

	//glCullFace(GL_BACK);
	
	//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	TwInit(TW_OPENGL, NULL);

	glutDisplayFunc(GlutCB::Display);
	glutReshapeFunc(GlutCB::Reshape);
	
	glutMouseFunc(GlutCB::Mouse);
	glutMotionFunc(GlutCB::Motion);
	glutPassiveMotionFunc(GlutCB::PassiveMotion);
	glutKeyboardFunc(GlutCB::Keyboard);
	glutKeyboardUpFunc(GlutCB::KeyboardUp);
	glutSpecialFunc(GlutCB::Special);
	glutSpecialUpFunc(GlutCB::SpecialUp);

	TwGLUTModifiersFunc(glutGetModifiers);

	glutTimerFunc(Constants::deltaTime, GlutCB::Timer, 1);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	Star sun("Sun", 2.0e30, 1.4e9, Vector3f(1.0f, 1.0f, 0.0f), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0));

	Planet mercury("Mercury", 3.3e23, 5.0e6, Vector3f(0.8f, 0.0f, 0.0f), Vector3d(4.6e10, 0.0, 0.0), Vector3d(0.0, 4.7e4, 0.0));

	Planet venus("Venus", 4.8e24, 1.2e7, Vector3f(0.8f, 0.6f, 0.7f), Vector3d(1.0e11, 0.0, 0.0), Vector3d(0.0, 3.5e4, 0.0));

	Planet earth("Earth", 6.0e24, 1.2e7, Vector3f(0.0f, 0.0f, 1.0f), Vector3d(1.5e11, 0.0, 0.0), Vector3d(0.0, 3.0e4, 0.0));
	Sputnik moon("Moon", 7.35e22, 3.4e6, Vector3f(0.7f, 0.7f, 0.7f), &earth, Vector3d(4.0e8, 0.0, 0.0), Vector3d(0.0, 1.0e3, 0.0));

	Planet mars("Mars", 6.4e23, 6.7e6, Vector3f(1.0f, 0.0f, 0.0f), Vector3d(2.0e11, 0.0, 0.0), Vector3d(0.0, 2.4e4, 0.0));

	Teapot rasselsTeapot("RasselsTeapot", 0.0, 0.3, Vector3f(1.0f, 1.0f, 1.0f), Vector3d(3.0e11, 0.0, 0.0), Vector3d(0.0, 2.0e4, 0.0));

	Planet jupiter("Jupiter", 1.9e27, 1.3e8, Vector3f(1.0f, 0.8f, 0.0f), Vector3d(7.4e11, 0.0, 0.0), Vector3d(0.0, 1.3e4, 0.0));

	RenderManager * renderManager = RenderManager::getInstance();
	renderManager->initAll();

	Camera * camera = new Camera();
	
	ControlPane * ctrlPane = ControlPane::getInstance(camera, renderManager);
	ctrlPane->show();

	TwCopyStdStringToClientFunc(CopyStdStringToClient);

	ctrlPane->addSpaceObject(&sun);
	renderManager->renderSpaceObject(&sun);

	ctrlPane->addSpaceObject(&mercury);
	renderManager->renderSpaceObject(&mercury);

	ctrlPane->addSpaceObject(&venus);
	renderManager->renderSpaceObject(&venus);

	ctrlPane->addSpaceObject(&earth);
	renderManager->renderSpaceObject(&earth);

	ctrlPane->addSpaceObject(&moon);
	renderManager->renderSpaceObject(&moon);

	ctrlPane->addSpaceObject(&mars);
	renderManager->renderSpaceObject(&mars);

	ctrlPane->addSpaceObject(&rasselsTeapot);
	renderManager->renderSpaceObject(&rasselsTeapot);

	ctrlPane->addSpaceObject(&jupiter);
	renderManager->renderSpaceObject(&jupiter);

	GlutCBInitializer::init(camera, renderManager);

	glutMainLoop();
	
	delete ctrlPane;
	glutDestroyWindow(window);
	return EXIT_SUCCESS;
}