Last active
August 29, 2015 14:26
-
-
Save StillManic/178215e4ac4df46f0816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[12:02:55] [Client thread/INFO] [FML]: X: -825, Y: 60, Z: 505 | |
[12:02:55] [Client thread/INFO] [FML]: player: X: -824.594887, Y: 59.228482, Z: 506.300000 | |
[12:02:55] [Client thread/INFO] [FML]: passed: X: -0.405113, Y: 0.771518, Z: -1.300000 | |
[12:02:55] [Client thread/INFO] [FML]: yaw angle: 0.001362 | |
[12:02:55] [Client thread/INFO] [FML]: pitch angle: 0.001417 | |
[12:02:55] [Client thread/INFO] [FML]: rendered: true | |
[12:02:55] [Client thread/INFO] [FML]: mat lib size: 4 | |
[12:02:55] [Client thread/INFO] [FML]: generalQuads: 400 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void renderTileEntityAt(TileEntity tile, double posX, double posY, double posZ, float partialTicks, int destroyStage) | |
{ | |
if (tile instanceof CustomTileEntity8) | |
{ | |
this.bindTexture(new ResourceLocation(MODID.toLowerCase() + ":" + "textures/eye128.png")); | |
try | |
{ | |
IModel model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase() + ":" + "block/eye.obj")); | |
Function<ResourceLocation, TextureAtlasSprite> textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() | |
{ | |
public TextureAtlasSprite apply(ResourceLocation location) | |
{ | |
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); | |
} | |
}; | |
// look vector = target-self; yaw = atan2(look.z,look.x), pitch = atan2(y, sqrt(x*x+z*z)) | |
// FMLLog.info("X: %f, Y: %f, Z: %f", posX, posY, posZ); | |
FMLLog.info("X: %d, Y: %d, Z: %d", tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ()); | |
// Vector3d teLoc = new Vector3d(posX, posY, posZ); | |
Vector3d teLoc = new Vector3d(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ()); | |
Vector3d playerLoc = new Vector3d(); | |
playerLoc.setX(Minecraft.getMinecraft().thePlayer.getPositionVector().xCoord); | |
playerLoc.setY(Minecraft.getMinecraft().thePlayer.getPositionVector().yCoord); | |
playerLoc.setZ(Minecraft.getMinecraft().thePlayer.getPositionVector().zCoord); | |
FMLLog.info("player: X: %f, Y: %f, Z: %f", playerLoc.x, playerLoc.y, playerLoc.z); | |
FMLLog.info("passed: X: %f, Y: %f, Z: %f", posX, posY, posZ); | |
double angleYaw = teLoc.angle(new Vector3d(playerLoc.getX(), teLoc.getY(), playerLoc.getZ())); | |
// double angleYaw = teLoc.angle(new Vector3d(playerLoc.getX(), posY, playerLoc.getZ())); | |
FMLLog.info("yaw angle: %f", angleYaw); | |
double anglePitch = teLoc.angle(new Vector3d(teLoc.getX(), playerLoc.getY(), playerLoc.getZ())); | |
// double anglePitch = teLoc.angle(new Vector3d(posX, playerLoc.getY(), playerLoc.getZ())); | |
FMLLog.info("pitch angle: %f", anglePitch); | |
// AxisAngle4d yaw = new AxisAngle4d(teLoc, angleYaw); | |
// AxisAngle4d pitch = new AxisAngle4d(teLoc, anglePitch); | |
AxisAngle4d yaw = new AxisAngle4d(0, 1, 0, angleYaw); | |
AxisAngle4d pitch = new AxisAngle4d(1, 0, 0, anglePitch); | |
Quat4f leftRot = new Quat4f(0, 0, 0, 1); | |
Quat4f yawQuat = new Quat4f(); | |
Quat4f pitchQuat = new Quat4f(); | |
yawQuat.set(yaw); | |
leftRot.mul(yawQuat); | |
pitchQuat.set(pitch); | |
leftRot.mul(pitchQuat); | |
Matrix4f matrix = new Matrix4f(); | |
matrix.setIdentity(); | |
matrix.setRotation(leftRot); | |
TRSRTransformation transform = new TRSRTransformation(matrix); | |
OBJModel.OBJState state = new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true, transform, (OBJModel) model); | |
IFlexibleBakedModel modelBaked = model.bake(state, Attributes.DEFAULT_BAKED_FORMAT, textureGetter); | |
// OBJBakedModel modelBaked = (OBJBakedModel) model.bake(state, Attributes.DEFAULT_BAKED_FORMAT, textureGetter); | |
// modelBaked.scheduleRebake(); | |
boolean success = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(tile.getWorld(), modelBaked, tile.getBlockType().getDefaultState(), tile.getPos(), Tessellator.getInstance().getWorldRenderer()); | |
FMLLog.info("rendered: %b", success); | |
FMLLog.info("mat lib size: %d", ((OBJModel) model).getMatLib().getMaterialNames().size()); | |
FMLLog.info("generalQuads: %d", modelBaked.getGeneralQuads().size()); | |
} | |
catch (IOException e) | |
{ | |
FMLLog.info("failed to find the model"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment