- 1,007
- 36
- 206
Как сделать обычную лазерную винтовку вполне понятно. Но как получить энтити не из под прицела игрока? (То есть, сделать пушке разброс)
private static Vec3 createLookVec(float yaw, float pitch, float spread, float length) {
float cosYaw = MathHelper.cos((float)((- yaw) * 0.017453292f - 3.1415927f));
float sinYaw = MathHelper.sin((float)((- yaw) * 0.017453292f - 3.1415927f));
float cosPitch = - MathHelper.cos((float)((- pitch) * 0.017453292f));
float sinPitch = MathHelper.sin((float)((- pitch) * 0.017453292f));
Vec3 lookVec = Vec3.createVectorHelper((double)(sinYaw * cosPitch * length), (double)(sinPitch * length), (double)(cosYaw * cosPitch * length));
if (spread > 0.0f) {
addSpreadToVec3(lookVec, spread);
}
return lookVec;
}
private static void addSpreadToVec3(Vec3 vec, float...
private static Vec3 createLookVec(float yaw, float pitch, float spread, float length) {
float cosYaw = MathHelper.cos((float)((- yaw) * 0.017453292f - 3.1415927f));
float sinYaw = MathHelper.sin((float)((- yaw) * 0.017453292f - 3.1415927f));
float cosPitch = - MathHelper.cos((float)((- pitch) * 0.017453292f));
float sinPitch = MathHelper.sin((float)((- pitch) * 0.017453292f));
Vec3 lookVec = Vec3.createVectorHelper((double)(sinYaw * cosPitch * length), (double)(sinPitch * length), (double)(cosYaw * cosPitch * length));
if (spread > 0.0f) {
addSpreadToVec3(lookVec, spread);
}
return lookVec;
}
private static void addSpreadToVec3(Vec3 vec, float spread) {
Random rand = new Random();
float randAngle = (rand.nextFloat() - 0.5f) * spread * 2.0f * 0.017453292f;
Vec3 axis = Vec3.createVectorHelper((double)(rand.nextFloat() - 0.5f), (double)(rand.nextFloat() - 0.5f), (double)(rand.nextFloat() - 0.5f));
axis.normalize();
float s = MathHelper.sin((float)randAngle);
float c = MathHelper.cos((float)randAngle);
float oc = 1.0f - c;
double[] m = new double[]{(double)oc * axis.xCoord * axis.xCoord + (double)c, (double)oc * axis.xCoord * axis.yCoord - axis.zCoord * (double)s, (double)oc * axis.zCoord * axis.xCoord + axis.yCoord * (double)s, (double)oc * axis.xCoord * axis.yCoord + axis.zCoord * (double)s, (double)oc * axis.yCoord * axis.yCoord + (double)c, (double)oc * axis.yCoord * axis.zCoord - axis.xCoord * (double)s, (double)oc * axis.zCoord * axis.xCoord - axis.yCoord * (double)s, (double)oc * axis.yCoord * axis.zCoord + axis.xCoord * (double)s, (double)oc * axis.zCoord * axis.zCoord + (double)c};
vec.xCoord = m[0] * vec.xCoord + m[1] * vec.yCoord + m[2] * vec.zCoord;
vec.yCoord = m[3] * vec.xCoord + m[4] * vec.yCoord + m[5] * vec.zCoord;
vec.zCoord = m[6] * vec.xCoord + m[7] * vec.yCoord + m[8] * vec.zCoord;
}