Jump to content

[SOLVED]Simple general rendering speed question (ModelBase class)


Frag

Recommended Posts

Hi guys,

 

I saw in my model classes that nothing is modified on a clock. It is rather just executed in loop. So, it is not clear to me. By example, how often the setrotationangle is called?

 

I am asking because I want to control the animation speed. Does it means that if it animate correctly on my beast machine ...it will animate at a slower speed on a slower machine? Or its time based?

 

Anyone can clarify the processing speed of the rendering?

Link to comment
Share on other sites

Everything in Minecraft updates every tick. Ticks happen 20 times a second, unless you are lagging.

So, generally, it behaves the same on every machine whether you get 60fps or 240.

 

The problem is with animations: If you just change the rotations of things every tick you have 20fps animations, which is stuttering and not acceptable (and you have other problems, too, because you are running the animation at 20fps but the game runs at lets say 55, which don't divide evenly at all so you get frame drops and repeated frames which makes things even worse looking). But you want it to run the same speed regardless of fps still.

So, what to do? You update every tick, but then you interpolate between frames. This happens by keeping a "last tick" value (how the rotation was last tick) and keeping a delta or partialTick value. You then do something like:

 

actualRotation = rotationLastTick + (rotationNow - rotationLastTick) * partialTicks

 

every frame. The partial ticks are provided by Minecraft. This then allows you to have smooth animations which still run the same speed everywhere regardless of fps (unless of course you have so low fps that things stutter anyways or you are lagging so much that you have less than 20 ticks per second).

 

Does make sense ... where I can get that "Tick" value from the ModelBase class to keep an eye on?

Link to comment
Share on other sites

Ok so as an example ... lets take the very simple Blooper model...

 

Here is the model

 

package fantastic.renders.models;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ModelBlooper extends ModelBase
{
    /** The squid's body */
    ModelRenderer squidBody;

    /** The squid's tentacles */
    ModelRenderer[] squidTentacles = new ModelRenderer[8];

    public ModelBlooper()
    {
        byte b0 = -16;
        this.squidBody = new ModelRenderer(this, 0, 0);
        this.squidBody.addBox(-6.0F, -8.0F, -6.0F, 12, 16, 12);
        this.squidBody.rotationPointY += (float)(24 + b0);

        for (int i = 0; i < this.squidTentacles.length; ++i)
        {
            this.squidTentacles[i] = new ModelRenderer(this, 48, 0);
            double d0 = (double)i * Math.PI * 2.0D / (double)this.squidTentacles.length;
            float f = (float)Math.cos(d0) * 5.0F;
            float f1 = (float)Math.sin(d0) * 5.0F;
            this.squidTentacles[i].addBox(-1.0F, 0.0F, -1.0F, 2, 18, 2);
            this.squidTentacles[i].rotationPointX = f;
            this.squidTentacles[i].rotationPointZ = f1;
            this.squidTentacles[i].rotationPointY = (float)(31 + b0);
            d0 = (double)i * Math.PI * -2.0D / (double)this.squidTentacles.length + (Math.PI / 2D);
            this.squidTentacles[i].rotateAngleY = (float)d0;
        }
    }

    /**
     * Sets the model's various rotation angles. For bipeds, par1 and par2 are used for animating the movement of arms
     * and legs, where par1 represents the time(so that arms and legs swing back and forth) and par2 represents how
     * "far" arms and legs can swing at most.
     */
    public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
    {
        ModelRenderer[] amodelrenderer = this.squidTentacles;
        int i = amodelrenderer.length;

        for (int j = 0; j < i; ++j)
        {
            ModelRenderer modelrenderer = amodelrenderer[j];
            modelrenderer.rotateAngleX = 0.5F + (0.6F)*(float) Math.sin(0.2*par3);
        }
    }

    /**
     * Sets the models various rotation angles then renders the model.
     */
    public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
    {
        this.setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
        this.squidBody.render(par7);

        for (int i = 0; i < this.squidTentacles.length; ++i)
        {
            this.squidTentacles[i].render(par7);
        }
    }
}

 

And here is the render

 

package fantastic.renders.entity;



import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.ResourceLocation;
import fantastic.FantasticInfo;
import fantastic.entities.EntityBlooper;
import fantastic.renders.models.ModelBlooper;

public class RenderBlooper extends RenderLiving
{
private static final ResourceLocation texture1 = new ResourceLocation(FantasticInfo.ID.toLowerCase() + ":textures/models/mobs/blooper.png");
protected ModelBlooper model;

public RenderBlooper(ModelBase par1ModelBase, float par2)
{
	super(par1ModelBase, par2);
	model = ((ModelBlooper) mainModel);
}

public void renderBlooper(EntityBlooper par1, double par2, double par3, double par4, float par5, float par6)
{
	super.doRender(par1, par2, par3, par4, par5, par6);

}

public void doRenderLiving(EntityLiving par1, double par2, double par3, double par4, float par5, float par6)
{
	this.renderBlooper((EntityBlooper) par1, par2, par3, par4, par5, par6);

}

@Override
public void doRender(Entity par1, double par2, double par3, double par4, float par5, float par6)
{
	this.renderBlooper((EntityBlooper) par1, par2, par3, par4, par5, par6);

}

protected ResourceLocation getEntityTexture(Entity entity)
{
			return texture1;
}

}

 

I understand the general idea of what you are talking about here ... but its hard for me to really know how to apply it. So looking at those blooper model and classes ... how would you use that technique?

Link to comment
Share on other sites

Just use setLivingAnimations and the partial tick calculations are already applied for you.

 

My animations are good ... but yes I have missing frames and jumps from time to time. Which looks like EXACLTY like what you are describing. I tried to fix that thing for months ... but for some reason you probably answered my prayer this morning.

 

From what I understood from your explanation is to use SetLivingAnimations instead of SetRotationAngles?

 

Could I ask you help and ask you to take a look at this tiny 8 lines SetRotationAngles method of the blooper and modify it with your technique. From there, I will figure it out really quickly. I am a soft dev, but not much experience with the rendering. With this short example, sun will shine on me. I should be able to go from there and would let you know if it fixed my issue.

 

    public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
    {
        ModelRenderer[] amodelrenderer = this.squidTentacles;
        int i = amodelrenderer.length;

        for (int j = 0; j < i; ++j)
        {
            ModelRenderer modelrenderer = amodelrenderer[j];
            modelrenderer.rotateAngleX = 0.5F + (0.6F)*(float) Math.sin(0.2*par3);
}
      

 

Link to comment
Share on other sites

Actually looking at it now, that should be fine. I don't know why that would cause a choppy animation. par3 includes the partial ticks.

 

HO MY GOD I FIXED MY ISSUE!!!

 

You have no clue how I could be happy right now!!! The model I posted is fine, I wanted a small example ... but mine was not, even with using par3.

 

But after reading your explanation of how the rendering works, it made me understand few things and I was able to pinpoint the issue on the SPOT.

 

Thank you so much diesieben07 ... this forum is a BLESS.

 

Thanks again!!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.