2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2014-03-15 20:53:00 +01:00
|
|
|
package appeng.client.render;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-15 20:53:00 +01:00
|
|
|
import java.util.Random;
|
|
|
|
|
2015-12-24 02:07:03 +01:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-03-15 20:53:00 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.multiplayer.WorldClient;
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
2016-10-03 00:23:45 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2014-03-15 20:53:00 +01:00
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.client.renderer.RenderHelper;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2016-06-19 14:43:27 +02:00
|
|
|
import net.minecraft.client.renderer.VertexBuffer;
|
2016-01-01 00:19:44 +01:00
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
2014-03-15 20:53:00 +01:00
|
|
|
import net.minecraftforge.client.IRenderHandler;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-03-15 20:53:00 +01:00
|
|
|
public class SpatialSkyRender extends IRenderHandler
|
|
|
|
{
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
private static final SpatialSkyRender INSTANCE = new SpatialSkyRender();
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
private final Random random = new Random();
|
|
|
|
private final int dspList;
|
2015-04-03 08:54:31 +02:00
|
|
|
private long cycle = 0;
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public SpatialSkyRender()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.dspList = GLAllocation.generateDisplayLists( 1 );
|
2014-03-15 20:53:00 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static IRenderHandler getInstance()
|
|
|
|
{
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
2014-03-15 20:53:00 +01:00
|
|
|
@Override
|
2015-09-30 14:24:40 +02:00
|
|
|
public void render( final float partialTicks, final WorldClient world, final Minecraft mc )
|
2014-03-15 20:53:00 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final long now = System.currentTimeMillis();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( now - this.cycle > 2000 )
|
2014-03-15 20:53:00 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.cycle = now;
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.glNewList( this.dspList, GL11.GL_COMPILE );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderTwinkles();
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.glEndList();
|
2014-03-15 20:53:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
float fade = now - this.cycle;
|
2014-03-15 20:53:00 +01:00
|
|
|
fade /= 1000;
|
2015-04-03 08:54:31 +02:00
|
|
|
fade = 0.15f * ( 1.0f - Math.abs( ( fade - 1.0f ) * ( fade - 1.0f ) ) );
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.pushAttrib();
|
2014-09-18 20:14:32 +02:00
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.disableFog();
|
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.disableBlend();
|
|
|
|
GlStateManager.depthMask( false );
|
|
|
|
GlStateManager.color( 0.0f, 0.0f, 0.0f, 1.0f );
|
2015-09-30 14:24:40 +02:00
|
|
|
final Tessellator tessellator = Tessellator.getInstance();
|
2016-06-19 14:43:27 +02:00
|
|
|
final VertexBuffer VertexBuffer = tessellator.getBuffer();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
for( int i = 0; i < 6; ++i )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.pushMatrix();
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( i == 1 )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.rotate( 90.0F, 1.0F, 0.0F, 0.0F );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 2 )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.rotate( -90.0F, 1.0F, 0.0F, 0.0F );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 3 )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.rotate( 180.0F, 1.0F, 0.0F, 0.0F );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 4 )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.rotate( 90.0F, 0.0F, 0.0F, 1.0F );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( i == 5 )
|
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.rotate( -90.0F, 0.0F, 0.0F, 1.0F );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
VertexBuffer.begin( GL11.GL_QUADS, DefaultVertexFormats.ITEM );
|
|
|
|
VertexBuffer.color( 0f, 0f, 0f, 1f ).pos( -100.0D, -100.0D, -100.0D ).tex( 0.0D, 0.0D ).endVertex();
|
|
|
|
VertexBuffer.color( 0f, 0f, 0f, 1f ).pos( -100.0D, -100.0D, 100.0D ).tex( 0.0D, 16.0D ).endVertex();
|
|
|
|
VertexBuffer.color( 0f, 0f, 0f, 1f ).pos( 100.0D, -100.0D, 100.0D ).tex( 16.0D, 16.0D ).endVertex();
|
|
|
|
VertexBuffer.color( 0f, 0f, 0f, 1f ).pos( 100.0D, -100.0D, -100.0D ).tex( 16.0D, 0.0D ).endVertex();
|
2015-04-03 08:54:31 +02:00
|
|
|
tessellator.draw();
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.popMatrix();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.depthMask( true );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( fade > 0.0f )
|
2015-02-03 12:04:13 +01:00
|
|
|
{
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.disableFog();
|
|
|
|
GlStateManager.disableAlpha();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.depthMask( false );
|
2014-03-15 20:53:00 +01:00
|
|
|
OpenGlHelper.glBlendFunc( 770, 771, 1, 0 );
|
|
|
|
RenderHelper.disableStandardItemLighting();
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.depthMask( false );
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.color( fade, fade, fade, 1.0f );
|
|
|
|
GlStateManager.callList( this.dspList );
|
2014-03-15 20:53:00 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.popAttrib();
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2016-10-03 00:23:45 +02:00
|
|
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
2014-03-15 20:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void renderTwinkles()
|
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final Tessellator tessellator = Tessellator.getInstance();
|
2016-06-19 14:43:27 +02:00
|
|
|
final VertexBuffer VertexBuffer = tessellator.getBuffer();
|
|
|
|
VertexBuffer.begin( GL11.GL_QUADS, DefaultVertexFormats.ITEM );
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int i = 0; i < 50; ++i )
|
2014-03-15 20:53:00 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
double iX = this.random.nextFloat() * 2.0F - 1.0F;
|
|
|
|
double iY = this.random.nextFloat() * 2.0F - 1.0F;
|
|
|
|
double iZ = this.random.nextFloat() * 2.0F - 1.0F;
|
2015-09-30 14:24:40 +02:00
|
|
|
final double d3 = 0.05F + this.random.nextFloat() * 0.1F;
|
2014-03-15 20:53:00 +01:00
|
|
|
double dist = iX * iX + iY * iY + iZ * iZ;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( dist < 1.0D && dist > 0.01D )
|
2014-03-15 20:53:00 +01:00
|
|
|
{
|
|
|
|
dist = 1.0D / Math.sqrt( dist );
|
|
|
|
iX *= dist;
|
|
|
|
iY *= dist;
|
|
|
|
iZ *= dist;
|
2015-09-30 14:24:40 +02:00
|
|
|
final double x = iX * 100.0D;
|
|
|
|
final double y = iY * 100.0D;
|
|
|
|
final double z = iZ * 100.0D;
|
|
|
|
final double d8 = Math.atan2( iX, iZ );
|
|
|
|
final double d9 = Math.sin( d8 );
|
|
|
|
final double d10 = Math.cos( d8 );
|
|
|
|
final double d11 = Math.atan2( Math.sqrt( iX * iX + iZ * iZ ), iY );
|
|
|
|
final double d12 = Math.sin( d11 );
|
|
|
|
final double d13 = Math.cos( d11 );
|
|
|
|
final double d14 = this.random.nextDouble() * Math.PI * 2.0D;
|
|
|
|
final double d15 = Math.sin( d14 );
|
|
|
|
final double d16 = Math.cos( d14 );
|
2014-03-15 20:53:00 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int j = 0; j < 4; ++j )
|
2014-03-15 20:53:00 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final double d17 = 0.0D;
|
|
|
|
final double d18 = ( ( j & 2 ) - 1 ) * d3;
|
|
|
|
final double d19 = ( ( j + 1 & 2 ) - 1 ) * d3;
|
|
|
|
final double d20 = d18 * d16 - d19 * d15;
|
|
|
|
final double d21 = d19 * d16 + d18 * d15;
|
|
|
|
final double d22 = d20 * d12 + d17 * d13;
|
|
|
|
final double d23 = d17 * d12 - d20 * d13;
|
|
|
|
final double d24 = d23 * d9 - d21 * d10;
|
|
|
|
final double d25 = d21 * d9 + d23 * d10;
|
2016-06-19 14:43:27 +02:00
|
|
|
VertexBuffer.pos( x + d24, y + d22, z + d25 ).endVertex();
|
2014-03-15 20:53:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tessellator.draw();
|
|
|
|
}
|
|
|
|
}
|