1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
package bloodasp.galacticgreg.generators;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import bloodasp.galacticgreg.GalacticGreg;
import bloodasp.galacticgreg.api.Enums.SpaceObjectType;
import bloodasp.galacticgreg.api.Enums.TargetBlockPosition;
import bloodasp.galacticgreg.api.ISpaceObjectGenerator;
import bloodasp.galacticgreg.api.StructureInformation;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
/**
* Simple ellipsoid-generator. Based on the formular created by Chrysator.
* Thanks for the help!
*
* Generates a simple ellipsoid with dynamic rotation, random size-values, random noise for the surface, etc.
* Can probably be tweaked even more, but works for now...
*/
public class GenEllipsoid implements ISpaceObjectGenerator {
private Vec3 _mEllipsoidCenter;
private Random _mRandom;
private List<StructureInformation> _mStructure;
private double _mCoreDensity = 0.7D;
private double _mSineFactor = 0.05D;
private float _mRandomInfluence;
private float _mRandomAngleX;
private float _mRandomAngleY;
private float _mRandomAngleZ;
private int _mSizeA;
private int _mSizeB;
private int _mSizeC;
public GenEllipsoid()
{
reset();
}
@Override
public SpaceObjectType getType() {
return SpaceObjectType.OreAsteroid;
}
@Override
public void randomize(int pSizeMin, int pSizeMax)
{
_mRandom = new Random(System.currentTimeMillis());
_mRandomAngleX = (float) (_mRandom.nextFloat() * Math.PI);
_mRandomAngleY = (float) (_mRandom.nextFloat() * Math.PI);
_mRandomAngleZ = (float) (_mRandom.nextFloat() * Math.PI);
_mRandomInfluence = _mRandom.nextFloat();
_mSizeA = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10;
_mSizeB = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10;
_mSizeC = pSizeMin + _mRandom.nextInt(pSizeMax - pSizeMin) + 10;
}
@Override
public void setCenterPoint(int pX, int pY, int pZ) {
_mEllipsoidCenter = Vec3.createVectorHelper(pX, pY, pZ);
}
@Override
public void setCenterPoint(Vec3 pCenter)
{
_mEllipsoidCenter = pCenter;
}
@Override
public Vec3 getCenterPoint()
{
return _mEllipsoidCenter;
}
@Override
public List<StructureInformation> getStructure() {
return _mStructure;
}
@Override
public void calculate()
{
int Xmin = (int) (_mEllipsoidCenter.xCoord - _mSizeA);
int Xmax = (int) (_mEllipsoidCenter.xCoord + _mSizeA);
int Ymin = (int) (_mEllipsoidCenter.yCoord - _mSizeB);
int Ymax = (int) (_mEllipsoidCenter.yCoord + _mSizeB);
int Zmin = (int) (_mEllipsoidCenter.zCoord - _mSizeC);
int Zmax = (int) (_mEllipsoidCenter.zCoord + _mSizeC);
for (int iX = Xmin; iX <= Xmax; iX++) {
for (int iY = Ymin; iY <= Ymax; iY++) {
for (int iZ = Zmin; iZ <= Zmax; iZ++)
{
double tmpX = Math.pow(_mEllipsoidCenter.xCoord - iX, 2) / Math.pow(_mSizeA, 2);
double tmpY = Math.pow(_mEllipsoidCenter.yCoord - iY, 2) / Math.pow(_mSizeB, 2);
double tmpZ = Math.pow(_mEllipsoidCenter.zCoord - iZ, 2) / Math.pow(_mSizeC, 2);
double val = (tmpX + tmpY + tmpZ);
Vec3 tPoint = Vec3.createVectorHelper(iX, iY, iZ);
tPoint.rotateAroundX(_mRandomAngleX);
tPoint.rotateAroundY(_mRandomAngleY);
tPoint.rotateAroundZ(_mRandomAngleZ);
TargetBlockPosition tbp = TargetBlockPosition.Invalid;
if (val <= 0.01D)
tbp = TargetBlockPosition.AsteroidInnerCore;
else if (val > 0.01D && val < _mCoreDensity)
tbp = TargetBlockPosition.AsteroidCore;
else if (val >= _mCoreDensity && val <= (1.0D - (_mSineFactor * MathHelper.sin((iZ + iX + iY - _mRandom.nextFloat() * _mRandomInfluence)))))
tbp = TargetBlockPosition.AsteroidShell;
if (tbp != TargetBlockPosition.Invalid)
_mStructure.add(new StructureInformation(Vec3.createVectorHelper(iX, iY, iZ), tbp));
}
}
}
}
@Override
public void reset() {
_mStructure = new ArrayList<StructureInformation>();
_mEllipsoidCenter = Vec3.createVectorHelper(0, 0, 0);
}
}
|