Exemple #1
0
void drawSun()
{   
	glUseProgram(sunShader);
	
	setupLighting(sunShader);
	
	//glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
	vec3 Position = getCameraPosition();
	
	v = getViewMatrix();
	
	mat4 a = translate(0.0, 0.0, -400.0); //333.0 Times
	mat4 rotation = rotateY(thetaY);
	mat4 b = multiplymat4(a, rotation);
	m = multiplymat4(b, scale(100.0));
	
	initMVP(sunShader, m, v);
	glUniform3f(glGetUniformLocation(sunShader, "cameraPos"), Position.x, Position.y, Position.z);
	glUniform1f(glGetUniformLocation(sunShader, "systemTime"), glfwGetTime());
    
    glBindVertexArray (planetVAO);
    bindTexture(GL_TEXTURE0, sunTexture);
    bindTexture(GL_TEXTURE1, sunNormal);
    glUniform1i(glGetUniformLocation(sunShader, "tex"), 0);
    glUniform1i(glGetUniformLocation(sunShader, "normalTex"), 1);
    
    glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber );
    glBindVertexArray(0);
    //glBindFramebuffer(GL_FRAMEBUFFER, 0);  
    
    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, colorBuffer);
    glUniform1f(glGetUniformLocation(sunShader, "exposure"), 1.0);
}
Exemple #2
0
void drawPlanet()
{   
	glUseProgram(planetShader);
	setupLighting(planetShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
		
	for(int i = 0; i < 11; i++)
	{	
		mat4 rotation = multiplymat4(rotateY(rotationSpeedArray[i]), rotateX(planetInstanceArray[i].axialTilt+45));
		mat4 translation = multiplymat4(translate(planetInstanceArray[i].radius*1000, 0.0, 0.0), rotation);
		mat4 b = translate(0.0, 0.0, -400.0);
		mat4 roty = rotateY(orbitSpeedArray[i]);
		mat4 rotxy = multiplymat4(b, roty);
		mat4 c = multiplymat4(rotxy, translation);
		m = multiplymat4(c, scale(planetInstanceArray[i].size*100));
		planetInstanceArray[i].planetLocation = m;
    	
		//mv = modelMatrices[i];
		initMVP(planetShader, m, v);
		glUniform3f(glGetUniformLocation(planetShader, "cameraPos"), Position.x, Position.y, Position.z);
    
    	glBindVertexArray (planetVAO);
    	bindTexture(GL_TEXTURE0, planetInstanceArray[i].texture);
    	bindTexture(GL_TEXTURE1, planetInstanceArray[i].normal);
    	glUniform1i(glGetUniformLocation(planetShader, "tex"), 0);
    	glUniform1i(glGetUniformLocation(planetShader, "normalTex"), 1);
    	glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber);
    	glBindVertexArray(0);
    }
}
Exemple #3
0
mat4 lookAt(vec3 eye, vec3 at, vec3 up)
{
    vec3 umv = {eye.x - at.x, eye.y - at.y, eye.z - at.z};
    vec3 n = normalizevec3(umv);
    vec3 u = normalizevec3(crossvec3(up, n));
    vec3 v = normalizevec3(crossvec3(n, u));
    mat4 c = IDENTITY_MATRIX;
    c.m[0][0] = u.x;
    c.m[1][0] = u.y;
    c.m[2][0] = u.z;

    c.m[0][1] = v.x;
    c.m[1][1] = v.y;
    c.m[2][1] = v.z;

    c.m[0][2] = n.x;
    c.m[1][2] = n.y;
    c.m[2][2] = n.z;

    c.m[0][3] = 0.0f;
    c.m[1][3] = 0.0f;
    c.m[2][3] = 0.0f;
    c.m[3][3] = 1.0f;
    vec3 negativeEye = {-eye.x, -eye.y, -eye.x};
    mat4 d = translatevec3(negativeEye);
    mat4 out = multiplymat4(c, d);
    return out;
}
Exemple #4
0
mat4 rotationSpace()
{
	vec2 rotation = getCameraRotation();
    mat4 rx = rotateX(rotation.y);
	mat4 ry = rotateY(rotation.x);
	mat4 rxry = multiplymat4(rx, ry);
	return rxry;
}
void translate(const mat4* m, float x, float y, float z) {
	mat4 translation = IDENTITY_MATRIX;
    mat4 temp;
	translation.m[12] = x;
	translation.m[13] = y;
	translation.m[14] = z;
    temp = multiplymat4(m, &translation);
	memcpy(m->m, temp.m, sizeof(m->m));
}
void scale(const mat4* m, float x, float y, float z) {
	mat4 scale = IDENTITY_MATRIX;
    mat4 temp;
	scale.m[0] = x;
	scale.m[5] = y;
	scale.m[10] = z;
    temp = multiplymat4(m, &scale);
	memcpy(m->m, temp.m, sizeof(m->m));
}
Exemple #7
0
void drawObj()
{
	v = getViewMatrix();
	glUseProgram(planetShader);
	//mat4 rx = multiplymat4(translate(0.0, 0.0, -15.0), rotationSpace());
	m = multiplymat4(translatevec4(light_position), scale(100));//rx;//multiplymat4(rx, rotateY(90));
	
	initMVP(planetShader, m, v);
	
	glBindVertexArray (objectVAO);
	//glDrawArrays( GL_TRIANGLES, 0, object.vertexNumber );
    glBindVertexArray(0);
}
void rotateZ(const mat4* m, float angle) {
	mat4 rotation = IDENTITY_MATRIX;
	mat4 temp;
	float sine = (float)sin(angle);
	float cosine = (float)cos(angle);

	rotation.m[0] = cosine;
	rotation.m[1] = -sine;
	rotation.m[4] = sine;
	rotation.m[5] = cosine;
    temp = multiplymat4(m, &rotation);
	memcpy(m->m, temp.m, sizeof(m->m));
}
Exemple #9
0
void drawAtmosphere()
{
	glUseProgram(atmosphereShader);
	setupLighting(atmosphereShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
	
	for(int i = 0; i < 11; i++)
    {	
    	float scaleFactor = 1.025;
    	m = multiplymat4(planetInstanceArray[i].planetLocation, scale(scaleFactor));
    	
    	float fOuter = planetInstanceArray[i].size*100*scaleFactor;
		float fInner = (planetInstanceArray[i].size*100);
		
		//float fOuter = (fScale);
		//float fInner = fScale/scaleFactor;
		
		//printf("fInner: %f, fOuter: %f\n", fInner, 1/(fOuter-fInner));
		//printf("camera: %f, %f, %f\n", Position.x, Position.y, Position.z);
		//printf("camera: %f, %f, %f\n", 1.0f / pow(0.650f, 4.0f), 1.0f / pow(0.570f, 4.0f), 1.0f / pow(0.475f, 4.0f));
		
		glUniform4f(glGetUniformLocation(atmosphereShader, "LightPosition"), light_position.x, light_position.y, light_position.z, light_position.w);
    	glUniform3f(glGetUniformLocation(atmosphereShader, "camPosition"), Position.x, Position.y, Position.z);
    	glUniform3f(glGetUniformLocation(atmosphereShader, "v3InvWavelength"), 1.0f / pow(0.650f, 4.0f), 1.0f / pow(0.570f, 4.0f), 1.0f / pow(0.475f, 4.0f));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fCameraHeight"), lengthvec3(getCameraPosition()));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fCameraHeight2"), (lengthvec3(getCameraPosition())) * (lengthvec3(getCameraPosition())));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fInnerRadius"), fInner);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fInnerRadius2"), fInner*fInner);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fOuterRadius"), fOuter);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fOuterRadius2"), fOuter*fOuter);
    
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKrESun"), 0.0025f * 20.0f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKmESun"), 0.0015f * 20.0f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKr4PI"), 0.0025f * 4.0f * 3.141592653f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fKm4PI"), 0.0015f * 4.0f * 3.141592653f);
    
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScale"), 1/(fOuter-fInner));
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScaleDepth"), 0.25);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "fScaleOverScaleDepth"), 1.0/(fOuter-fInner)/0.25);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "g"), -0.990f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "g2"), -0.990f*-0.990f);
    	glUniform1f(glGetUniformLocation(atmosphereShader, "time"), glfwGetTime());
    	
    	initMVP(atmosphereShader, m, v);
    	
    	glBindVertexArray (atmosphereVAO);
    	glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber);
    	glBindVertexArray(0);
    }
}
Exemple #10
0
void drawMoon()
{
	glUseProgram(planetShader);
	setupLighting(planetShader);
	vec3 Position = getCameraPosition();
	v = getViewMatrix();
	
	mat4 rt = multiplymat4(rotateY(orbitSpeedArray[3]), translate(planetInstanceArray[3].radius*1000, 0.0, 0.0));
	m = multiplymat4(multiplymat4(rt, translate(10.0, 0.0, 0.0)), scale(100));
	
	//mv = modelMatrices[i];
	initMVP(planetShader, m, v);
	glUniform3f(glGetUniformLocation(planetShader, "cameraPos"), Position.x, Position.y, Position.z);
    
    glBindVertexArray (planetVAO);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, planetInstanceArray[2].texture);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, planetInstanceArray[2].normal);
 	glUniform1i(glGetUniformLocation(planetShader, "tex"), 0);
    glUniform1i(glGetUniformLocation(planetShader, "normalTex"), 1);
    //glDrawArrays( GL_TRIANGLES, 0, planet.vertexNumber );
    glBindVertexArray(0);
}