|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.minecraft.src.Bone
public class Bone
The Bone class makes it possible to create skeletons, which should help you out in
animating your mobs a little bit more easy. However, since you won't work with a
graphical interface, creating bones will be different from what you are probably
used to.
First, you will need to instantiate every Bone in the constructor of your model
file. The default orientation, when all angles are set to zero, will be in the
vector (0, 0, length), meaning it will always point backwards on a regular model.
You can also set what its parent node is. If a Bone does not have a parent node,
it is assumed it is the root node. Each Bone can only have one parent, but several
children. Also, all children will inherit the offset position of the root node.
The neutral position basically defines in what direction the Bone normally faces
when in rest. This will not affect the rotation of any model currently attached
to it or the rotation of the child nodes, but will affect the position of the
child nodes when recalculating their positions. The length always defines how far
each child Bone will be placed, since child Bones are always placed at the end of
their parent Bone.
Once you're ready to render, you can call the prepareDraw method. You only need
to apply it to one Bone, since it will always search for the root node to execute
the code there. It will then automatically rotate every child Bone and places
them at the right position. Finally, use the setAnglesToModels method to rotate
each model and place them at the correct spot. Note that if you also apply custom
rotation for the individual models that you should apply that after you've run
setAnglesToModels, since this will override the settings the model originally had.
The best way to solve this is to make a separate method to rotate the Bones.
The following would be an example of a biped with a skeleton. It takes ModelBiped
as an example and extends it with a skeleton. First, we have the part that goes
in the constructor.
// First, the origin will be placed. This is where the rest is attached to. skeletonOrigin = new Bone(0, 0, 0, 0); // Next, the entire skeleton is built up. skeletonHead = new Bone(-3.141593F / 2, 0, 0, 0, skeletonOrigin); skeletonBody = new Bone(3.141593F / 2, 0, 0, 12, skeletonOrigin); skeletonShoulderRight = new Bone(0, -3.141593F / 2, 0, 5, skeletonOrigin); skeletonShoulderLeft = new Bone(0, 3.141593F / 2, 0, 5, skeletonOrigin); skeletonArmRight = new Bone(3.141593F / 2, 0, 0, 12, skeletonShoulderRight); skeletonArmLeft = new Bone(3.141593F / 2, 0, 0, 12, skeletonShoulderLeft); skeletonPelvisRight = new Bone(0, -3.141593F / 2, 0, 2, skeletonBody); skeletonPelvisLeft = new Bone(0, 3.141593F / 2, 0, 2, skeletonBody); skeletonLegRight = new Bone(3.141593F / 2, 0, 0, 12, skeletonPelvisRight); skeletonLegLeft = new Bone(3.141593F / 2, 0, 0, 12, skeletonPelvisLeft); // Finally, all models will be attached to the skeletons. skeletonHead.addModel(bipedHead); skeletonHead.addModel(bipedHeadwear); skeletonBody.addModel(bipedBody); skeletonArmRight.addModel(bipedRightArm); skeletonArmLeft.addModel(bipedLeftArm); skeletonLegRight.addModel(bipedRightLeg); skeletonLegLeft.addModel(bipedRightLeg);
skeletonHead.relativeAngles.angleY = f3 / 57.29578F; skeletonHead.relativeAngles.angleX = f4 / 57.29578F; skeletonArmRight.relativeAngles.angleX = MathHelper.cos(f * 0.6662F + 3.141593F) * 2.0F * f1 * 0.5F; skeletonArmRight.relativeAngles.angleZ = 0.0F; skeletonArmLeft.relativeAngles.angleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F; skeletonArmLeft.relativeAngles.angleZ = 0.0F; skeletonLegRight.relativeAngles.angleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1; skeletonLegRight.relativeAngles.angleY = 0.0F; skeletonLegLeft.relativeAngles.angleX = MathHelper.cos(f * 0.6662F + 3.141593F) * 1.4F * f1; skeletonLegLeft.relativeAngles.angleY = 0.0F;
setRotationAngles(f, f1, f2, f3, f4, f5); skeletonOrigin.prepareDraw(); skeletonOrigin.setAnglesToModels();
Field Summary | |
---|---|
Angle3D |
relativeAngles
|
Constructor Summary | |
---|---|
Bone(float x,
float y,
float z,
float l)
Constructor to create a bone. |
|
Bone(float x,
float y,
float z,
float l,
Bone parent)
Constructor to create a bone. |
|
Bone(float xOrig,
float yOrig,
float zOrig,
float xRot,
float yRot,
float zRot,
float l)
Constructor to create a bone. |
Method Summary | |
---|---|
void |
addModel(net.minecraft.src.ModelRenderer model)
Attaches a model to the bone. |
void |
addModel(net.minecraft.src.ModelRenderer model,
boolean inherit)
Attaches a model to the bone. |
void |
addModel(net.minecraft.src.ModelRenderer model,
boolean inherit,
boolean isUpright)
Attaches a model to the bone. |
void |
addModel(net.minecraft.src.ModelRenderer model,
float x,
float y,
float z)
Attaches a model to the bone with a given base rotation. |
void |
addModel(net.minecraft.src.ModelRenderer model,
float x,
float y,
float z,
boolean inherit)
Attaches a model to the bone with a given base rotation. |
void |
addModel(net.minecraft.src.ModelRenderer model,
float x,
float y,
float z,
boolean inherit,
boolean isUpright)
Attaches a model to the bone with a given base rotation. |
void |
attachBone(Bone parent)
Attaches the bone to a parent. |
void |
detachBone()
Detaches the bone from its parent. |
Angle3D |
getAbsoluteAngle()
Gets the current absolute angles. |
net.minecraft.src.Vec3D |
getPosition()
Gets the current position of the bone. |
Bone |
getRootParent()
Gets the root parent bone. |
void |
prepareDraw()
Prepares the bones for rendering. |
void |
removeModel(net.minecraft.src.ModelRenderer model)
Removes the given model from the Bone. |
void |
resetOffset()
Resets the offset. |
void |
resetOffset(boolean doRecursive)
Resets the offset. |
void |
setAnglesToModels()
Sets the current angles of the Bone to the models attached to it. |
void |
setNeutralRotation(float x,
float y,
float z)
Sets the current neutral rotation of the bone. |
net.minecraft.src.Vec3D |
setOffset(float x,
float y,
float z)
Sets the current offset of the parent root Bone. |
void |
setRotations(float x,
float y,
float z)
Sets the current rotation of the Bone, not calculating any parent bones in. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public Angle3D relativeAngles
Constructor Detail |
---|
public Bone(float x, float y, float z, float l)
x
- the x-rotation of the boney
- the y-rotation of the bonez
- the z-rotation of the bonel
- the length of the bonepublic Bone(float xOrig, float yOrig, float zOrig, float xRot, float yRot, float zRot, float l)
xOrig
- the x-offset of the originyOrig
- the y-offset of the originzOrig
- the z-offset of the originxRot
- the x-rotation of the boneyRot
- the y-rotation of the bonezRot
- the z-rotation of the bonel
- the length of the bonepublic Bone(float x, float y, float z, float l, Bone parent)
x
- the x-rotation of the boney
- the y-rotation of the bonez
- the z-rotation of the bonel
- the length of the boneparent
- the parent Bone node this Bone is attached toMethod Detail |
---|
public void detachBone()
public void attachBone(Bone parent)
parent
- the parent Bone node this Bone is attached topublic net.minecraft.src.Vec3D setOffset(float x, float y, float z)
x
- the x-positiony
- the y-positionz
- the z-position
public void resetOffset()
public void resetOffset(boolean doRecursive)
doRecursive
- public void setNeutralRotation(float x, float y, float z)
x
- the x-rotation of the boney
- the y-rotation of the bonez
- the z-rotation of the bonepublic Bone getRootParent()
public void addModel(net.minecraft.src.ModelRenderer model)
model
- the model to attachpublic void addModel(net.minecraft.src.ModelRenderer model, boolean inherit)
model
- the model to attachinherit
- whether the model should inherit the Bone's base rotationspublic void addModel(net.minecraft.src.ModelRenderer model, boolean inherit, boolean isUpright)
model
- the model to attachinherit
- whether the model should inherit the Bone's base rotationsisUpright
- whether the model is modeled in the upright positionpublic void addModel(net.minecraft.src.ModelRenderer model, float x, float y, float z)
model
- the model to attachx
- the base x-rotationy
- the base y-rotationz
- the base z-rotationpublic void addModel(net.minecraft.src.ModelRenderer model, float x, float y, float z, boolean inherit)
model
- the model to attachx
- the base x-rotationy
- the base y-rotationz
- the base z-rotationinherit
- whether the model should inherit the Bone's base rotationspublic void addModel(net.minecraft.src.ModelRenderer model, float x, float y, float z, boolean inherit, boolean isUpright)
model
- the model to attachx
- the base x-rotationy
- the base y-rotationz
- the base z-rotationinherit
- whether the model should inherit the Bone's base rotationsisUpright
- whether the model is modeled in the upright positionpublic void removeModel(net.minecraft.src.ModelRenderer model)
model
- the model to remove from the bonepublic Angle3D getAbsoluteAngle()
public net.minecraft.src.Vec3D getPosition()
public void prepareDraw()
public void setRotations(float x, float y, float z)
x
- y
- z
- public void setAnglesToModels()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |