📄 camera.java
字号:
ptIntersect.add(m_Position);
vLightSourceToIntersect.sub(ptIntersect, m_LightSourcePos); // Lets compute the vector that points to the Intersect
// point from the light source
Length = vLightSourceToIntersect.length(); // Save the length we will need it later.
vLightSourceToIntersect.normalize(); // Normalize the vector so its unit length
gl.glEnable(GL.GL_BLEND); // You should already know what this does
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); // You should already know what this does
gl.glDisable(GL.GL_DEPTH_TEST); // You should already know what this does
gl.glEnable(GL.GL_TEXTURE_2D); // You should already know what this does
/////////// Differenet Color Glows & Streaks /////////////////////
//RenderBigGlow(1.0f, 1.0f, 1.0f, 1.0f, m_LightSourcePos, 1.0f);
//RenderStreaks(1.0f, 1.0f, 0.8f, 1.0f, m_LightSourcePos, 0.7f);
//
//RenderBigGlow(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 1.0f);
//RenderStreaks(1.0f, 0.9f, 1.0f, 1.0f, m_LightSourcePos, 0.7f);
//////////////////////////////////////////////////////////////////
// Render the large hazy glow
renderBigGlow(gl, 0.60f, 0.60f, 0.8f, 1.0f, m_LightSourcePos, 16.0f);
// Render the streaks
renderStreaks(gl, 0.60f, 0.60f, 0.8f, 1.0f, m_LightSourcePos, 16.0f);
// Render the small Glow
renderGlow(gl, 0.8f, 0.8f, 1.0f, 0.5f, m_LightSourcePos, 3.5f);
pt.scaleAdd(Length * .1f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 20%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.9f, 0.6f, 0.4f, 0.5f, pt, 0.6f); // Render the small Glow
pt.scaleAdd(Length * .15f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 30%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.8f, 0.5f, 0.6f, 0.5f, pt, 1.7f); // Render the a Halo
pt.scaleAdd(Length * .175f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 35%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.9f, 0.2f, 0.1f, 0.5f, pt, 0.83f); // Render the a Halo
pt.scaleAdd(Length * .285f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 57%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.7f, 0.7f, 0.4f, 0.5f, pt, 1.6f); // Render the a Halo
pt.scaleAdd(Length * .2755f, vLightSourceToIntersect, m_LightSourcePos);// Lets compute a point that is 55.1%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.9f, 0.9f, 0.2f, 0.5f, pt, 0.8f); // Render the small Glow
pt.scaleAdd(Length * .4775f, vLightSourceToIntersect, m_LightSourcePos);// Lets compute a point that is 95.5%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.93f, 0.82f, 0.73f, 0.5f, pt, 1.0f); // Render the small Glow
pt.scaleAdd(Length * .49f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 98%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.7f, 0.6f, 0.5f, 0.5f, pt, 1.4f); // Render the a Halo
pt.scaleAdd(Length * .65f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 130%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.7f, 0.8f, 0.3f, 0.5f, pt, 1.8f); // Render the small Glow
pt.scaleAdd(Length * 0.63f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 126%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.4f, 0.3f, 0.2f, 0.5f, pt, 1.4f); // Render the small Glow
pt.scaleAdd(Length * 0.8f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 160%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.7f, 0.5f, 0.5f, 0.5f, pt, 1.4f); // Render the a Halo
pt.scaleAdd(Length * .7825f, vLightSourceToIntersect, m_LightSourcePos);// Lets compute a point that is 156.5%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.8f, 0.5f, 0.1f, 0.5f, pt, 0.6f); // Render the small Glow
pt.scaleAdd(Length * 1.0f, vLightSourceToIntersect, m_LightSourcePos); // Lets compute a point that is 200%
// away from the light source in the
// direction of the intersection point.
renderHalo(gl, 0.5f, 0.5f, 0.7f, 0.5f, pt, 1.7f); // Render the a Halo
pt.scaleAdd(Length * 0.975f, vLightSourceToIntersect, m_LightSourcePos);// Lets compute a point that is 195%
// away from the light source in the
// direction of the intersection point.
renderGlow(gl, 0.4f, 0.1f, 0.9f, 0.5f, pt, 2.0f); // Render the small Glow
gl.glDisable(GL.GL_BLEND); // You should already know what this does
gl.glEnable(GL.GL_DEPTH_TEST); // You should already know what this does
gl.glDisable(GL.GL_TEXTURE_2D); // You should already know what this does
}
}
private void renderHalo(GL gl, float r, float g, float b, float a, Tuple3f p, float scale) {
Tuple3f[] q = new Tuple3f[4];
for (int i = 3; i >= 0; i--)
q[i] = new Tuple3f();
// Basically we are just going to make a 2D box
// from four points we don't need a z coord because
// we are rotating the camera by the inverse so the
// texture mapped quads will always face us.
q[0].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[0].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[1].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[1].y = (p.y + scale); // Set the y coordinate scale units from the center point.
q[2].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[2].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[3].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[3].y = (p.y + scale); // Set the y coordinate scale units from the center point.
gl.glPushMatrix(); // Save the model view matrix
gl.glTranslatef(p.x, p.y, p.z); // Translate to our point
gl.glRotatef(-m_HeadingDegrees, 0.0f, 1.0f, 0.0f);
gl.glRotatef(-m_PitchDegrees, 1.0f, 0.0f, 0.0f);
gl.glBindTexture(GL.GL_TEXTURE_2D, m_HaloTexture[0]); // Bind to the Big Glow texture
gl.glColor4f(r, g, b, a); // Set the color since the texture is a gray scale
gl.glBegin(GL.GL_TRIANGLE_STRIP); // Draw the Big Glow on a Triangle Strip
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex2f(q[0].x, q[0].y);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex2f(q[1].x, q[1].y);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex2f(q[2].x, q[2].y);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex2f(q[3].x, q[3].y);
gl.glEnd();
gl.glPopMatrix(); // Restore the model view matrix
}
private void renderGlow(GL gl, float r, float g, float b, float a, Tuple3f p, float scale) {
Tuple3f[] q = new Tuple3f[4];
for (int i = 3; i >= 0; i--)
q[i] = new Tuple3f();
// Basically we are just going to make a 2D box
// from four points we don't need a z coord because
// we are rotating the camera by the inverse so the
// texture mapped quads will always face us.
q[0].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[0].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[1].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[1].y = (p.y + scale); // Set the y coordinate scale units from the center point.
q[2].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[2].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[3].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[3].y = (p.y + scale); // Set the y coordinate scale units from the center point.
gl.glPushMatrix(); // Save the model view matrix
gl.glTranslatef(p.x, p.y, p.z); // Translate to our point
gl.glRotatef(-m_HeadingDegrees, 0.0f, 1.0f, 0.0f);
gl.glRotatef(-m_PitchDegrees, 1.0f, 0.0f, 0.0f);
gl.glBindTexture(GL.GL_TEXTURE_2D, m_GlowTexture[0]); // Bind to the Big Glow texture
gl.glColor4f(r, g, b, a); // Set the color since the texture is a gray scale
gl.glBegin(GL.GL_TRIANGLE_STRIP); // Draw the Big Glow on a Triangle Strip
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex2f(q[0].x, q[0].y);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex2f(q[1].x, q[1].y);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex2f(q[2].x, q[2].y);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex2f(q[3].x, q[3].y);
gl.glEnd();
gl.glPopMatrix(); // Restore the model view matrix
}
private void renderBigGlow(GL gl, float r, float g, float b, float a, Tuple3f p, float scale) {
Tuple3f[] q = new Tuple3f[4];
for (int i = 3; i >= 0; i--)
q[i] = new Tuple3f();
// Basically we are just going to make a 2D box
// from four points we don't need a z coord because
// we are rotating the camera by the inverse so the
// texture mapped quads will always face us.
q[0].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[0].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[1].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[1].y = (p.y + scale); // Set the y coordinate scale units from the center point.
q[2].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[2].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[3].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[3].y = (p.y + scale); // Set the y coordinate scale units from the center point.
gl.glPushMatrix(); // Save the model view matrix
gl.glTranslatef(p.x, p.y, p.z); // Translate to our point
gl.glRotatef(-m_HeadingDegrees, 0.0f, 1.0f, 0.0f);
gl.glRotatef(-m_PitchDegrees, 1.0f, 0.0f, 0.0f);
gl.glBindTexture(GL.GL_TEXTURE_2D, m_BigGlowTexture[0]); // Bind to the Big Glow texture
gl.glColor4f(r, g, b, a); // Set the color since the texture is a gray scale
gl.glBegin(GL.GL_TRIANGLE_STRIP); // Draw the Big Glow on a Triangle Strip
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex2f(q[0].x, q[0].y);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex2f(q[1].x, q[1].y);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex2f(q[2].x, q[2].y);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex2f(q[3].x, q[3].y);
gl.glEnd();
gl.glPopMatrix(); // Restore the model view matrix
}
private void renderStreaks(GL gl, float r, float g, float b, float a, Tuple3f p, float scale) {
Tuple3f[] q = new Tuple3f[4];
for (int i = 3; i >= 0; i--)
q[i] = new Tuple3f();
// Basically we are just going to make a 2D box
// from four points we don't need a z coord because
// we are rotating the camera by the inverse so the
// texture mapped quads will always face us.
q[0].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[0].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[1].x = (p.x - scale); // Set the x coordinate -scale units from the center point.
q[1].y = (p.y + scale); // Set the y coordinate scale units from the center point.
q[2].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[2].y = (p.y - scale); // Set the y coordinate -scale units from the center point.
q[3].x = (p.x + scale); // Set the x coordinate scale units from the center point.
q[3].y = (p.y + scale); // Set the y coordinate scale units from the center point.
gl.glPushMatrix(); // Save the model view matrix
gl.glTranslatef(p.x, p.y, p.z); // Translate to our point
gl.glRotatef(-m_HeadingDegrees, 0.0f, 1.0f, 0.0f);
gl.glRotatef(-m_PitchDegrees, 1.0f, 0.0f, 0.0f);
gl.glBindTexture(GL.GL_TEXTURE_2D, m_StreakTexture[0]); // Bind to the Big Glow texture
gl.glColor4f(r, g, b, a); // Set the color since the texture is a gray scale
gl.glBegin(GL.GL_TRIANGLE_STRIP); // Draw the Big Glow on a Triangle Strip
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex2f(q[0].x, q[0].y);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex2f(q[1].x, q[1].y);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex2f(q[2].x, q[2].y);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex2f(q[3].x, q[3].y);
gl.glEnd();
gl.glPopMatrix(); // Restore the model view matrix
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -