This commit is contained in:
2026-02-12 11:18:51 +00:00
parent 414e52de9e
commit b0511f3830
4 changed files with 350 additions and 47 deletions

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VoxelIsometricRenderer
{
public static class PlayerObject
{
static int PositionX = 0;
static int PositionY = 0;
static int PositionZ = 0;
static float PrecisePositionX = 0.0f;
static float PrecisePositionY = 0.0f;
static float PrecisePositionZ = 0.0f;
public static int[] GetPos()
{
return new int[] { PositionX, PositionY, PositionZ };
}
public static float[] GetPresicePos()
{
return new float[] { PrecisePositionX, PrecisePositionY, PrecisePositionZ };
}
public static void SetPos(int[] pos, bool Reoccure)
{
PositionX = pos[0];
PositionY = pos[1];
PositionZ = pos[2];
if (Reoccure) SetPrecisePos(new float[] { pos[0], pos[1], pos[2] },false);
}
public static void SetPrecisePos(float[] pos, bool Reoccure)
{
PrecisePositionX = pos[0];
PrecisePositionY = pos[1];
PrecisePositionZ = pos[2];
if(Reoccure)SetPos(new int[] {(int)pos[0], (int)pos[1],(int)pos[2] },false);
}
public static void IncrementPos(int Axis, int Increment) { IncrementPos(Axis, Increment, true); }
public static void IncrementPos(int Axis, int Increment,bool Reoccure)
{
switch (Axis)
{
case 0: PositionX += Increment; break;
case 1: PositionY += Increment; break;
case 2: PositionZ += Increment; break;
}
if (Reoccure) SetPrecisePos(new float[] { (float)PositionX, (float)PositionY, (float)PositionZ },false);
}
public static void IncrementPrecisePos(int Axis, float Increment, bool Reoccure)
{
switch (Axis)
{
case 0: PrecisePositionX += Increment; break;
case 1: PrecisePositionY += Increment; break;
case 2: PrecisePositionZ += Increment; break;
}
if (Reoccure) SetPos(new int[] {(int)PrecisePositionX, (int)PrecisePositionY, (int)PrecisePositionZ },false);
}
public static void SetSpecificPos(int Axis, int Pos, bool Reoccure)
{
switch (Axis)
{
case 0:PositionX = Pos; break;
case 1: PositionY = Pos; break;
case 2: PositionZ = Pos; break;
}
if (Reoccure) SetPrecisePos(new float[] { PositionX, PositionY, PositionZ },false);
}
}
}

View File

@@ -26,6 +26,8 @@ namespace VoxelIsometricRenderer
public static int Frames = 0; public static int Frames = 0;
public static double TotalRamUsage = 0; public static double TotalRamUsage = 0;
public static double RamUsage = 0; public static double RamUsage = 0;
public static int width;
public static int height;
public Terrain4() public Terrain4()
{ {
InitializeComponent(); InitializeComponent();
@@ -58,11 +60,13 @@ namespace VoxelIsometricRenderer
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) { for (int j = 0; j < 16; j++) {
for (int k = 0; k < 16; k++) { for (int k = 0; k < 16; k++) {
if (i < 10 && k < 10 && rnd.Next(0, 3) > 0) TestChunk.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k); if (i < 5 && k < 5 && rnd.Next(0, 3) > 0) TestChunk.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
else TestChunk.CreateAir(i, j, k); else TestChunk.CreateAir(i, j, k);
} }
} }
} }
LightingManager.Lights.Add(new LightSource(LightShape.Sphere,12,12,12, 5, 18, 5, new float[] {0.8f,0.0f,0.0f},64));
LightingManager.Lights.Add(new LightSource(LightShape.Sphere,12,12,12, 5, 8, 5, new float[] {0.0f,0.0f,0.6f},64));
TestChunk.GenerateLightMap(); TestChunk.GenerateLightMap();
TestChunk.CalculateCull(); TestChunk.CalculateCull();
MainThread = new Thread(Runtime); MainThread = new Thread(Runtime);
@@ -87,6 +91,22 @@ namespace VoxelIsometricRenderer
//LightingManager.sunAngles[1] += 1f; //LightingManager.sunAngles[1] += 1f;
} }
if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - SecondFrameTime > 1000) { if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - SecondFrameTime > 1000) {
int[] pos = LightingManager.Lights[0].GetPosition();
int[] pos2 = LightingManager.Lights[1].GetPosition();
if (up && pos[0] > 0)
{
pos[0]--;
pos2[1]--;
}
else if (up) up = false;
else if (pos[0] < 10)
{
pos[0]++;
pos2[1]++;
}
else up = true;
//LightingManager.Lights[0].SetPosition(pos);
//LightingManager.Lights[1].SetPosition(pos2);
TotalRamUsage = Math.Round(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1000000.0); TotalRamUsage = Math.Round(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1000000.0);
RamUsage = Math.Round(GC.GetTotalMemory(false) / 1000000.0); RamUsage = Math.Round(GC.GetTotalMemory(false) / 1000000.0);
SecondFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; SecondFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
@@ -112,6 +132,8 @@ namespace VoxelIsometricRenderer
Display.Top = 0; Display.Top = 0;
Display.Width = Width; Display.Width = Width;
Display.Height = Height; Display.Height = Height;
width = Width;
height = Height;
} }
private void ResizeAspectRatio(object sender, EventArgs e) private void ResizeAspectRatio(object sender, EventArgs e)
{ {
@@ -125,24 +147,48 @@ namespace VoxelIsometricRenderer
private void KeyDownEvent(object sender, KeyEventArgs e) private void KeyDownEvent(object sender, KeyEventArgs e)
{ {
if (e.KeyCode == Keys.Up) scale += 0.25f; if (e.KeyCode == Keys.Add) scale += 0.25f;
if (e.KeyCode == Keys.Down) scale -= 0.25f; if (e.KeyCode == Keys.Subtract) scale -= 0.25f;
if (e.KeyCode == Keys.W) if (e.KeyCode == Keys.Up)
{ {
LightingManager.sunAngles[1] += 10f; LightingManager.sunAngles[1] += 10f;
} }
if (e.KeyCode == Keys.S) if (e.KeyCode == Keys.Down)
{ {
LightingManager.sunAngles[1] -= 10f; LightingManager.sunAngles[1] -= 10f;
} }
if (e.KeyCode == Keys.A) if (e.KeyCode == Keys.Left)
{ {
LightingManager.sunAngles[0] += 10f; LightingManager.sunAngles[0] += 10f;
} }
if (e.KeyCode == Keys.D) if (e.KeyCode == Keys.Right)
{ {
LightingManager.sunAngles[0] += 10f; LightingManager.sunAngles[0] += 10f;
} }
if (e.KeyCode == Keys.W)
{
PlayerObject.IncrementPos(2, 1);
}
if (e.KeyCode == Keys.S)
{
PlayerObject.IncrementPos(2, -1);
}
if (e.KeyCode == Keys.A)
{
PlayerObject.IncrementPos(0, 1);
}
if (e.KeyCode == Keys.D)
{
PlayerObject.IncrementPos(0, -1);
}
if (e.KeyCode == Keys.Space)
{
PlayerObject.IncrementPos(1, 1);
}
if (e.KeyCode == Keys.ShiftKey)
{
PlayerObject.IncrementPos(1, -1);
}
} }
private void KeyUpEvent(object sender, KeyEventArgs e) private void KeyUpEvent(object sender, KeyEventArgs e)

View File

@@ -43,8 +43,168 @@ namespace VoxelIsometricRenderer
int ZWorldPos; int ZWorldPos;
LightShape Shape; LightShape Shape;
byte[,,] LightLevels; byte[,,] LightLevels;
float[] LightLevelModifier = new float[] { 1.5f, 1.5f, 1.5f }; float[] LightLevelModifier = new float[] { 1.0f, 1.0f, 1.0f };
int Brightness = 64; int Brightness = 64;
public void SetPosition(int[] pos)
{
XWorldPos = pos[0];
YWorldPos = pos[1];
ZWorldPos = pos[2];
}
public int[] GetPosition()
{
return new int[] { XWorldPos, YWorldPos, ZWorldPos };
}
public int[] GetRadius()
{
return new int[] {RangeX,RangeY, RangeZ };
}
public int GetAverageRadius()
{
return (RangeX + RangeY + RangeZ) / 3;
}
public float[] GetRGBLightLevels(int level)
{
float Multiplier = (float)level / 255.0f;
return new float[] { LightLevelModifier[0] * Multiplier, LightLevelModifier[1] * Multiplier, LightLevelModifier[2] * Multiplier };
}
public int GetLightLevel(int RelativeBlockX, int RelativeBlockY, int RelativeBlockZ, int face, bool BlocksLight)
{
int CentreX = LightLevels.GetLength(0) / 2;
int CentreY = LightLevels.GetLength(1) / 2;
int CentreZ = LightLevels.GetLength(2) / 2;
int LightLevel = 0;
if(RelativeBlockX >= 0 && RelativeBlockX < LightLevels.GetLength(0) &&
RelativeBlockY >= 0 && RelativeBlockY < LightLevels.GetLength(1) &&
RelativeBlockZ >= 0 && RelativeBlockZ < LightLevels.GetLength(2))
{
LightLevel = LightLevels[RelativeBlockX,RelativeBlockY,RelativeBlockZ];
int DirectionX = 0;
if (BlocksLight)
{
switch (face)
{
case 0:
if (CentreZ < RelativeBlockZ)
{
DirectionX = 180;
}
if (CentreZ == RelativeBlockZ)
{
DirectionX = 90;
}
if (CentreZ > RelativeBlockZ)
{
DirectionX = 0;
}
break;
case 1:
if (CentreZ > RelativeBlockZ)
{
DirectionX = 180;
}
if (CentreZ == RelativeBlockZ)
{
DirectionX = 90;
}
if (CentreZ < RelativeBlockZ)
{
DirectionX = 0;
}
break;
case 2:
if (CentreX < RelativeBlockX)
{
DirectionX = 180;
}
if (CentreX == RelativeBlockX)
{
DirectionX = 90;
}
if (CentreX > RelativeBlockX)
{
DirectionX = 0;
}
break;
case 3:
if (CentreX > RelativeBlockX)
{
DirectionX = 180;
}
if (CentreX == RelativeBlockX)
{
DirectionX = 90;
}
if (CentreX < RelativeBlockX)
{
DirectionX = 0;
}
break;
case 4:
if (CentreY < RelativeBlockY)
{
DirectionX = 180;
}
if(CentreY == RelativeBlockY)
{
DirectionX = 90;
}
if(CentreY > RelativeBlockY)
{
DirectionX = 0;
}
break;
case 5:
if (CentreY > RelativeBlockY)
{
DirectionX = 180;
}
if (CentreY == RelativeBlockY)
{
DirectionX = 90;
}
if (CentreY < RelativeBlockY)
{
DirectionX = 0;
}
break;
}
/* if (CentreZ < RelativeBlockZ && RelativeBlockZ > RelativeBlockX)
{
for (int i = RelativeBlockZ; i < LightLevels.GetLength(2); i++)
{
LightLevels[RelativeBlockX, RelativeBlockY, i] = 0;
}
} else if (CentreZ > RelativeBlockZ && RelativeBlockZ < RelativeBlockX)
{
for (int i = RelativeBlockZ; i >= 0; i--)
{
LightLevels[RelativeBlockX, RelativeBlockY, i] = 0;
}
} else
{
if (CentreX < RelativeBlockX && RelativeBlockX > RelativeBlockZ)
{
for (int i = RelativeBlockX; i < LightLevels.GetLength(0); i++)
{
LightLevels[i, RelativeBlockY, RelativeBlockZ] = 0;
}
}
else if (CentreX > RelativeBlockX && RelativeBlockX < RelativeBlockZ)
{
for (int i = RelativeBlockZ; i >= 0; i--)
{
LightLevels[i, RelativeBlockY, RelativeBlockZ] = 0;
}
}
}*/
LightLevel = (int)(LightLevel * ((1 + Math.Cos(Math.PI * DirectionX / 180)) / 2));
// MessageBox.Show(LightLevel + "");
}
}
return LightLevel;
}
public static bool IsWithinCircle(int Radius, int CentreX, int CentreY, int posX, int PosY) public static bool IsWithinCircle(int Radius, int CentreX, int CentreY, int posX, int PosY)
{ {
return LightingManager.Square(posX - CentreX) + LightingManager.Square(PosY - CentreY) < LightingManager.Square(Radius); return LightingManager.Square(posX - CentreX) + LightingManager.Square(PosY - CentreY) < LightingManager.Square(Radius);
@@ -174,10 +334,30 @@ namespace VoxelIsometricRenderer
public static List<LightSource> Lights = new List<LightSource>(); public static List<LightSource> Lights = new List<LightSource>();
public static LightDirection SunAngle = LightDirection.North; public static LightDirection SunAngle = LightDirection.North;
public static float MaxBloom = 1.05f; public static float MaxBloom = 1.05f;
public static float[] GetLightsOnCube(int WorldX, int WorldY, int WorldZ, int face, bool BlocksLight)
public static float[] RenderLightOnCube(int WorldX, int WorldY, int WorldZ, int face)
{ {
return new float[] { 0, 0, 0 }; float[] RGBLevels = new float[] { 0, 0, 0 };
int LightCount = 0;
Lights.ForEach(Light =>
{
int DistX = WorldX - (Light.GetPosition()[0] - Light.GetRadius()[0]);
int DistY = WorldY - (Light.GetPosition()[1] - Light.GetRadius()[1]);
int DistZ = WorldZ - (Light.GetPosition()[2] - Light.GetRadius()[2]);
if (DistX > 0 && DistY > 0 && DistZ > 0 && DistX - Light.GetRadius()[0] < 0 && DistY - Light.GetRadius()[1] < 0 && DistZ - Light.GetRadius()[2] < 0)
{
//MessageBox.Show("X: " + DistX + " Y: " + DistY + " Z: " + DistZ);
float[] LightRGB = new float[3];
LightCount++;
int LightLevel = Light.GetLightLevel(DistX, DistY, DistZ, face, BlocksLight);
LightRGB = Light.GetRGBLightLevels(LightLevel);
RGBLevels[0] += LightRGB[0];
RGBLevels[1] += LightRGB[1];
RGBLevels[2] += LightRGB[2];
}
});
//return RGBLevels;
return new float[] { RGBLevels[0] != 0 ? RGBLevels[0]/LightCount : 0, RGBLevels[1] != 0 ? RGBLevels[1]/LightCount : 0, RGBLevels[2] != 0 ? RGBLevels[2]/LightCount : 0 };
} }
public static void UpdateLighting() public static void UpdateLighting()
{ {
@@ -252,7 +432,7 @@ namespace VoxelIsometricRenderer
if (faces[i] >= 0 && GeneratedFaceTextures[faces[i], i].Height > ImageHeight) ImageHeight = GeneratedFaceTextures[faces[i], i].Height; if (faces[i] >= 0 && GeneratedFaceTextures[faces[i], i].Height > ImageHeight) ImageHeight = GeneratedFaceTextures[faces[i], i].Height;
} }
Bitmap GeneratedModel = new Bitmap(ImageWidth, ImageHeight); Bitmap GeneratedModel = new Bitmap(ImageWidth, ImageHeight);
voxel.Draw(Graphics.FromImage(GeneratedModel),0,0,0,0,0,0); voxel.Draw(Graphics.FromImage(GeneratedModel),0,0,0,0,0,0,false);
voxel.SetPreCompiledModel(PreCompiledModels.Count); voxel.SetPreCompiledModel(PreCompiledModels.Count);
PreCompiledModels.Add(GeneratedModel); PreCompiledModels.Add(GeneratedModel);
GeneratedModel.Save("Model" + voxel.GetModelNum() + ".png"); GeneratedModel.Save("Model" + voxel.GetModelNum() + ".png");
@@ -263,21 +443,26 @@ namespace VoxelIsometricRenderer
} }
public static float GetShadingValue(float LightValue, int RGBIndex, int FaceIndex) public static float GetShadingValue(float LightValue, int RGBIndex, int FaceIndex)
{ {
return (float)Math.Max(LightValue * LightingManager.AmbientColouring[RGBIndex], LightingManager.AmbientMinimums[FaceIndex]); return GetShadingValue(LightValue, RGBIndex, FaceIndex, new float[] { 0, 0, 0 });
} }
public static ImageAttributes GetShadow(int face) { return GetShadow(face, 0, 0,0,0); } public static float GetShadingValue(float LightValue, int RGBIndex, int FaceIndex, float[] Lights)
public static ImageAttributes GetShadow(int face, int WorldX, int WorldY, int WorldZ, int ShadowLevel) {
//if (Lights[RGBIndex] > 0) MessageBox.Show(Lights[RGBIndex] + "");
return ((float)Math.Max(LightValue * LightingManager.AmbientColouring[RGBIndex], LightingManager.AmbientMinimums[FaceIndex])) + Lights[RGBIndex] * 10;
}
public static ImageAttributes GetShadow(int face) { return GetShadow(face, 0, 0,0,0, false); }
public static ImageAttributes GetShadow(int face, int WorldX, int WorldY, int WorldZ, int ShadowLevel, bool BlocksLight)
{ {
ImageAttributes imageAttributes; ImageAttributes imageAttributes;
float[][] colorMatrixElements; float[][] colorMatrixElements;
float[] Lights = LightingManager.RenderLightOnCube(WorldX, WorldY, WorldZ, face); float[] Lights = LightingManager.GetLightsOnCube(WorldX, WorldY, WorldZ, face, BlocksLight);
ColorMatrix colorMatrix; ColorMatrix colorMatrix;
switch (face) { switch (face) {
case 0: case 0:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face,Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
@@ -287,9 +472,9 @@ namespace VoxelIsometricRenderer
return imageAttributes; return imageAttributes;
case 1: case 1:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face, Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
@@ -299,9 +484,9 @@ namespace VoxelIsometricRenderer
return imageAttributes; return imageAttributes;
case 2: case 2:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face, Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
@@ -311,9 +496,9 @@ namespace VoxelIsometricRenderer
return imageAttributes; return imageAttributes;
case 3: case 3:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face, Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
@@ -323,9 +508,9 @@ namespace VoxelIsometricRenderer
return imageAttributes; return imageAttributes;
case 4: case 4:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face, Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
@@ -335,9 +520,9 @@ namespace VoxelIsometricRenderer
return imageAttributes; return imageAttributes;
case 5: case 5:
colorMatrixElements = new float[][]{ colorMatrixElements = new float[][]{
new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face), 0, 0, 0, 0}, // red new float[] { GetShadingValue(GetSunlightValue(face,ShadowLevel), 0,face, Lights), 0, 0, 0, 0}, // red
new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face), 0, 0, 0}, // green new float[] {0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 1, face, Lights), 0, 0, 0}, // green
new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face), 0, 0}, // blue new float[] {0, 0, GetShadingValue(GetSunlightValue(face,ShadowLevel), 2, face, Lights), 0, 0}, // blue
new float[] {0, 0, 0, 1, 0}, // alpha new float[] {0, 0, 0, 1, 0}, // alpha
new float[] {0, 0, -0, 0, 1}}; // three translations of 0.2 new float[] {0, 0, -0, 0, 1}}; // three translations of 0.2
@@ -635,7 +820,7 @@ namespace VoxelIsometricRenderer
VoxelNum = TextureManager.VoxelCount; VoxelNum = TextureManager.VoxelCount;
TextureManager.VoxelCount++; TextureManager.VoxelCount++;
} }
virtual public void Draw(Graphics g, int x, int y, int WorldX, int WorldY, int WorldZ, int ShadowLevel) virtual public void Draw(Graphics g, int x, int y, int WorldX, int WorldY, int WorldZ, int ShadowLevel, bool BlocksLight)
{ {
for (int i = 0; i < DrawOrder.Length; i++) { for (int i = 0; i < DrawOrder.Length; i++) {
if (DrawOrder[i] > 0 && DrawOrder[i] < 6 && faces[DrawOrder[i]] >= 0) if (DrawOrder[i] > 0 && DrawOrder[i] < 6 && faces[DrawOrder[i]] >= 0)
@@ -647,7 +832,7 @@ namespace VoxelIsometricRenderer
{ {
case 0: case 0:
Side = GetRenderedSide(DrawOrder[i]); Side = GetRenderedSide(DrawOrder[i]);
g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i], WorldX, WorldY,WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i], WorldX, WorldY,WorldZ, ShadowLevel, BlocksLight));
break; break;
default: default:
@@ -655,23 +840,23 @@ namespace VoxelIsometricRenderer
{ {
case 0: case 0:
Side = GetRenderedSide(0); Side = GetRenderedSide(0);
g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y, Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(0, WorldX, WorldY, WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y, Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(0, WorldX, WorldY, WorldZ, ShadowLevel, BlocksLight));
break; break;
case 1: case 1:
Side = GetRenderedSide(1); Side = GetRenderedSide(1);
g.DrawImage(Side, new Rectangle(x + (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(1, WorldX, WorldY, WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle(x + (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(1, WorldX, WorldY, WorldZ, ShadowLevel, BlocksLight));
break; break;
case 2: case 2:
Side = GetRenderedSide(2); Side = GetRenderedSide(2);
g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(2, WorldX, WorldY, WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle(x - (Side.Width / 4), y - (Side.Height / 4), Side.Width, Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(2, WorldX, WorldY, WorldZ, ShadowLevel, BlocksLight));
break; break;
case 3: case 3:
Side = GetRenderedSide(3); Side = GetRenderedSide(3);
g.DrawImage(Side, new Rectangle( x + (Side.Width / 4),y,Side.Width,Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(3, WorldX, WorldY, WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle( x + (Side.Width / 4),y,Side.Width,Side.Height),0,0,Side.Width,Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(3, WorldX, WorldY, WorldZ, ShadowLevel, BlocksLight));
break; break;
default: default:
Side = GetRenderedSide(DrawOrder[i]); Side = GetRenderedSide(DrawOrder[i]);
g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i], WorldX, WorldY, WorldZ, ShadowLevel)); g.DrawImage(Side, new Rectangle(x, y, Side.Width, Side.Height), 0, 0, Side.Width, Side.Height, GraphicsUnit.Pixel, TextureManager.GetShadow(DrawOrder[i], WorldX, WorldY, WorldZ, ShadowLevel, BlocksLight));
break; break;
} }
break; break;
@@ -1009,12 +1194,12 @@ namespace VoxelIsometricRenderer
public static int[] GetDrawLocation(int x, int y, int z, int offsetX, int offsetY, int offsetZ) public static int[] GetDrawLocation(int x, int y, int z, int offsetX, int offsetY, int offsetZ)
{ {
return new int[]{(int)((((double)(x + offsetX) * 0.5) + ((double)(z + offsetZ) * -0.5))*(double)BlockSize), return new int[]{(int)((((double)(x + offsetX) * 0.5) + ((double)(z + offsetZ) * -0.5))*(double)BlockSize),
(int)((((double)(x + offsetX) * 0.5) + ((double)(z + offsetZ) * 0.5) - (offsetY + (y)))*((double)BlockSize/2.0)) }; (int)((((double)(x + offsetX) * 0.5) + ((double)(z + offsetZ) * 0.5) - (-offsetY + (y)))*((double)BlockSize/2.0)) };
} }
public static void RenderBlock(Graphics g, int BlockID,int WorldX, int WorldY, int WorldZ, int ShadowLevel) public static void RenderBlock(Graphics g, int BlockID,int WorldX, int WorldY, int WorldZ, int ShadowLevel)
{ {
int[] location = GetDrawLocation(WorldX, WorldY, WorldZ, 0, 0, 0); int[] location = GetDrawLocation(WorldX, WorldY, WorldZ, PlayerObject.GetPos()[0], PlayerObject.GetPos()[1], PlayerObject.GetPos()[2]);
VoxelRegistry.FetchVoxel(blocks[BlockID].FetchVoxelID()).Draw(g, location[0] + 300, location[1] + 300, WorldX, WorldY, WorldZ, ShadowLevel); VoxelRegistry.FetchVoxel(blocks[BlockID].FetchVoxelID()).Draw(g, location[0] + (Terrain4.width/4) , location[1] + (Terrain4.height/2), WorldX, WorldY, WorldZ, ShadowLevel, FetchBlockState(BlockID).hasBlocksLight());
} }
public static int CheckInBlock(Block block,int x, int y, int z) public static int CheckInBlock(Block block,int x, int y, int z)
{ {

View File

@@ -46,6 +46,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="PlayerObject.cs" />
<Compile Include="Terrain4.cs"> <Compile Include="Terrain4.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>