Added Preview for Camera's Position and look direction in Path Previews

Added getDestination() method to AdvancedPosition to calculate the destination based on a step size and the position's pitch/yaw
This commit is contained in:
CrushedPixel
2015-07-14 04:25:19 +02:00
parent 0ff40cc0f5
commit eb4f0fcc20
3 changed files with 120 additions and 1 deletions

View File

@@ -6,6 +6,9 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import javax.vecmath.Vector3d;
@Data
@NoArgsConstructor
@@ -48,6 +51,20 @@ public class AdvancedPosition extends Position {
return dx * dx + dy * dy + dz * dz;
}
public AdvancedPosition getDestination(double stepSize) {
float f2 = MathHelper.cos((float) (Math.toRadians(-yaw) - (float)Math.PI));
float f3 = MathHelper.sin((float) (Math.toRadians(-yaw) - (float) Math.PI));
float f4 = -MathHelper.cos((float) (Math.toRadians(-pitch)));
float f5 = MathHelper.sin((float) (Math.toRadians(-pitch)));
Vector3d direction = new Vector3d((double)(f3 * f4), (double)f5, (double)(f2 * f4));
direction.normalize();
direction.scale(stepSize);
Vector3d position = new Vector3d(x, y, z);
position.add(direction);
return new AdvancedPosition(position.getX(), position.getY(), position.getZ(), pitch, yaw, roll, null);
}
@Override
public AdvancedPosition newInstance() {
return new AdvancedPosition();

View File

@@ -12,6 +12,7 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.opengl.GL11;
@@ -30,9 +31,12 @@ public class PathPreviewRenderer {
private KeyframeList<AdvancedPosition> keyframes;
private final ResourceLocation cameraHeadResource = new ResourceLocation("replaymod", "camera_head.png");
@SubscribeEvent
public void renderCameraPath(RenderWorldLastEvent event) {
if(!ReplayHandler.isInReplay() || ReplayHandler.isInPath() || !ReplayMod.replaySettings.showPathPreview() || mc.gameSettings.hideGUI) return;
//if(!ReplayHandler.isInReplay() || ReplayHandler.isInPath() || !ReplayMod.replaySettings.showPathPreview() || mc.gameSettings.hideGUI) return;
if(!ReplayHandler.isInReplay() || !ReplayMod.replaySettings.showPathPreview() || mc.gameSettings.hideGUI) return;
Entity entity = ReplayHandler.getCameraEntity();
if(entity == null) return;
@@ -90,6 +94,15 @@ public class PathPreviewRenderer {
drawPoint(doubleX, doubleY, doubleZ, kf);
}
if(ReplayHandler.getPositionKeyframes().size() > 1) {
AdvancedPosition cameraPosition = ReplayHandler.getPositionKeyframes().getInterpolatedValueForTimestamp(ReplayHandler.getRealTimelineCursor(),
ReplayMod.replaySettings.isLinearMovement());
if(cameraPosition != null) {
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
drawCamera(doubleX, doubleY, doubleZ, cameraPosition);
}
}
GlStateManager.disableAlpha();
GlStateManager.disableTexture2D();
GlStateManager.disableBlend();
@@ -202,4 +215,93 @@ public class PathPreviewRenderer {
GlStateManager.popMatrix();
}
private void drawCamera(double playerX, double playerY, double playerZ, AdvancedPosition pos) {
GlStateManager.pushMatrix();
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer renderer = tessellator.getWorldRenderer();
mc.renderEngine.bindTexture(cameraHeadResource);
double x = pos.getX() - playerX;
double y = pos.getY() - playerY;
double z = pos.getZ() - playerZ;
GlStateManager.translate(x, y + 1.4, z);
GL11.glNormal3f(0, 1, 0);
//draw the position line
AdvancedPosition pos2 = pos.getDestination(2);
GlStateManager.enableDepth();
GlStateManager.disableLighting();
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
renderer.startDrawing(1);
renderer.setColorRGBA_I(Color.GREEN.getRGB(), 170);
renderer.addVertex(pos2.getX() - pos.getX(), pos2.getY() - pos.getY(), pos2.getZ() - pos.getZ());
renderer.addVertex(0, 0, 0);
Tessellator.getInstance().draw();
GlStateManager.enableTexture2D();
GlStateManager.rotate((float) -pos.getYaw(), 0, 1, 0);
GlStateManager.rotate((float) pos.getPitch(), 1, 0, 0);
GlStateManager.rotate((float) pos.getRoll(), 0, 0, 1);
float cubeSize = 0.5f;
x = y = z = -cubeSize/2;
renderer.startDrawingQuads();
renderer.setColorRGBA_I(Color.WHITE.getRGB(), 200);
//back
renderer.addVertexWithUV(x, y + cubeSize, z, 3 * 8 / 64f, 8 / 64f);
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z, 4*8/64f, 8/64f);
renderer.addVertexWithUV(x + cubeSize, y, z, 4*8/64f, 2*8/64f);
renderer.addVertexWithUV(x, y, z, 3*8/64f, 2*8/64f);
//front
renderer.addVertexWithUV(x + cubeSize, y, z + cubeSize, 2 * 8 / 64f, 2*8/64f);
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z + cubeSize, 2 * 8 / 64f, 8/64f);
renderer.addVertexWithUV(x, y + cubeSize, z + cubeSize, 8 / 64f, 8 / 64f);
renderer.addVertexWithUV(x, y, z + cubeSize, 8 / 64f, 2*8/64f);
//left
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z, 0, 8/64f);
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z + cubeSize, 8/64f, 8/64f);
renderer.addVertexWithUV(x + cubeSize, y, z + cubeSize, 8/64f, 2*8/64f);
renderer.addVertexWithUV(x+cubeSize,y,z, 0, 2*8/64f);
//right
renderer.addVertexWithUV(x, y + cubeSize, z + cubeSize, 2*8/64f, 8/64f);
renderer.addVertexWithUV(x, y + cubeSize, z, 3*8/64f, 8/64f);
renderer.addVertexWithUV(x, y, z, 3*8/64f, 2*8/64f);
renderer.addVertexWithUV(x, y, z + cubeSize, 2 * 8 / 64f, 2 * 8 / 64f);
//bottom
renderer.addVertexWithUV(x + cubeSize, y, z, 3*8/64f, 0);
renderer.addVertexWithUV(x + cubeSize, y, z + cubeSize, 3*8/64f, 8/64f);
renderer.addVertexWithUV(x, y, z + cubeSize, 2*8/64f, 8/64f);
renderer.addVertexWithUV(x, y, z, 2 * 8 / 64f, 0);
//top
renderer.addVertexWithUV(x, y + cubeSize, z, 8/64f, 0);
renderer.addVertexWithUV(x, y + cubeSize, z + cubeSize, 8/64f, 8/64f);
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z + cubeSize, 2*8/64f, 8/64f);
renderer.addVertexWithUV(x + cubeSize, y + cubeSize, z, 2 * 8 / 64f, 0);
Tessellator.getInstance().draw();
renderer.setTranslation(0, 0, 0);
GlStateManager.popMatrix();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB