Jump to content

How do I make GL11 constantly rotate part of my model? (Helicopter Rotor)


Recommended Posts

Posted

I'm creating a Helicopter Model for my EntityHelicopter (It loads the model properly and renders properly etc)

However I'm trying to have GL11 rotate a specific part of my model. Is that possible?

 

My core sofar?

 

 

//This File was created with the Minecraft-SMP Modelling Toolbox 2.2.1.1

// Copyright © 2015 Minecraft-SMP.de

// This file is for Flan's Flying Mod Version 4.0.x+

 

package net.mcheroesandgenerals.warblocks;

 

import java.util.Random;

 

import org.lwjgl.opengl.GL11;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelRenderer;

import net.minecraft.entity.Entity;

import net.minecraft.util.MathHelper;

import scala.tools.nsc.doc.model.Public;

 

public class ModelHuey

extends ModelBase {

int x = 0;

ModelRenderer body;

ModelRenderer nose;

ModelRenderer tail1;

ModelRenderer tail2;

ModelRenderer tail3;

ModelRenderer tail4;

ModelRenderer tailRotor;

ModelRenderer mainRotorA;

ModelRenderer mainRotorPole;

ModelRenderer mainRotorB;

ModelRenderer skidLeft;

ModelRenderer skidRight;

ModelRenderer skidBack;

ModelRenderer skidFront;

ModelRenderer RightLauncher;

ModelRenderer LeftLauncher;

ModelRenderer tailflapRight;

ModelRenderer tailflapLeft;

 

    public ModelHuey() {

textureWidth = 64;

textureHeight = 32;

 

body = new ModelRenderer(this, 28, 0);

body.addBox(-4.0F, -1.0F, -6.0F, 7, 7, 11);

body.setRotationPoint(0.0F, 16.0F, 0.0F);

body.setTextureSize(128, 128);

body.mirror = false;

setRotation(body, 0.0F, 0.0F, 0.0F);

 

nose = new ModelRenderer(this, 11, 0);

nose.addBox(-4.0F, 3.0F, -8.0F, 7, 3, 2);

nose.setRotationPoint(0.0F, 16.0F, 0.0F);

nose.setTextureSize(128, 128);

nose.mirror = false;

setRotation(nose, 0.0F, 0.0F, 0.0F);

 

tail1 = new ModelRenderer(this, 0, 9);

tail1.addBox(-2.0F, -2.0F, -3.0F, 3, 6, 11);

tail1.setRotationPoint(0.0F, 16.0F, 0.0F);

tail1.setTextureSize(128, 128);

tail1.mirror = false;

setRotation(tail1, 0.0F, 0.0F, 0.0F);

 

tail2 = new ModelRenderer(this, 0, 0);

tail2.addBox(-1.0F, -1.0F, 8.0F, 1, 4, 5);

tail2.setRotationPoint(0.0F, 16.0F, 0.0F);

tail2.setTextureSize(128, 128);

tail2.mirror = false;

setRotation(tail2, 0.0F, 0.0F, 0.0F);

 

tail3 = new ModelRenderer(this, 21, 1);

tail3.addBox(-1.0F, -1.0F, 13.0F, 1, 2, 8);

tail3.setRotationPoint(0.0F, 16.0F, 0.0F);

tail3.setTextureSize(128, 128);

tail3.mirror = false;

setRotation(tail3, 0.0F, 0.0F, 0.0F);

 

tail4 = new ModelRenderer(this, 0, 10);

tail4.addBox(-1.0F, -5.0F, 20.0F, 1, 4, 1);

tail4.setRotationPoint(0.0F, 16.0F, 0.0F);

tail4.setTextureSize(128, 128);

tail4.mirror = false;

setRotation(tail4, 0.0F, 0.0F, 0.0F);

 

tailRotor = new ModelRenderer(this, 17, 14);

tailRotor.addBox(0.0F, -0.5F, -2.5F, 1, 1, 5);

tailRotor.setRotationPoint(0.0F, 12.0F, 20.5F);

tailRotor.setTextureSize(128, 128);

tailRotor.mirror = false;

setRotation(tailRotor, 0.0F, 0.0F, 0.0F);

 

mainRotorA = new ModelRenderer(this, 0, 26);

mainRotorA.addBox(0.0F, -4.0F, -1.0F, 16, 1, 2);

mainRotorA.setRotationPoint(-0.5F, 15.0F, 0.0F);

mainRotorA.setTextureSize(128, 128);

mainRotorA.mirror = false;

setRotation(mainRotorA, 0.0F, 0.0F, 0.0F);

 

mainRotorPole = new ModelRenderer(this, 52, 28);

mainRotorPole.addBox(-1.0F, -3.0F, -0.5F, 2, 2, 1);

mainRotorPole.setRotationPoint(-0.5F, 15.0F, 0.0F);

mainRotorPole.setTextureSize(128, 128);

mainRotorPole.mirror = false;

setRotation(mainRotorPole, 0.0F, 0.0F, 0.0F);

 

mainRotorB = new ModelRenderer(this, 0, 29);

mainRotorB.addBox(-16.0F, -4.0F, -1.0F, 16, 1, 2);

mainRotorB.setRotationPoint(-0.5F, 15.0F, 0.0F);

mainRotorB.setTextureSize(128, 128);

mainRotorB.mirror = false;

setRotation(mainRotorB, 0.0F, 0.0F, 0.0F);

 

skidLeft = new ModelRenderer(this, 38, 19);

skidLeft.addBox(-5.0F, 7.0F, -8.0F, 1, 1, 12);

skidLeft.setRotationPoint(0.0F, 16.0F, 0.0F);

skidLeft.setTextureSize(128, 128);

skidLeft.mirror = false;

setRotation(skidLeft, 0.0F, 0.0F, 0.0F);

 

skidRight = new ModelRenderer(this, 38, 19);

skidRight.addBox(3.0F, 7.0F, -8.0F, 1, 1, 12);

skidRight.setRotationPoint(0.0F, 16.0F, 0.0F);

skidRight.setTextureSize(128, 128);

skidRight.mirror = false;

setRotation(skidRight, 0.0F, 0.0F, 0.0F);

 

skidBack = new ModelRenderer(this, 30, 20);

skidBack.addBox(-5.0F, 6.0F, -6.0F, 9, 1, 1);

skidBack.setRotationPoint(0.0F, 16.0F, 0.0F);

skidBack.setTextureSize(128, 128);

skidBack.mirror = false;

setRotation(skidBack, 0.0F, 0.0F, 0.0F);

 

skidFront = new ModelRenderer(this, 30, 20);

skidFront.addBox(-5.0F, 6.0F, 2.0F, 9, 1, 1);

skidFront.setRotationPoint(0.0F, 16.0F, 0.0F);

skidFront.setTextureSize(128, 128);

skidFront.mirror = false;

setRotation(skidFront, 0.0F, 0.0F, 0.0F);

 

RightLauncher = new ModelRenderer(this, 38, 24);

RightLauncher.addBox(-7.0F, 4.0F, 0.0F, 2, 3, 4);

RightLauncher.setRotationPoint(0.0F, 16.0F, 0.0F);

RightLauncher.setTextureSize(128, 128);

RightLauncher.mirror = false;

setRotation(RightLauncher, 0.0F, 0.0F, 0.0F);

 

LeftLauncher = new ModelRenderer(this, 38, 24);

LeftLauncher.addBox(4.0F, 4.0F, 0.0F, 2, 3, 4);

LeftLauncher.setRotationPoint(0.0F, 16.0F, 0.0F);

LeftLauncher.setTextureSize(128, 128);

LeftLauncher.mirror = false;

setRotation(LeftLauncher, 0.0F, 0.0F, 0.0F);

 

tailflapRight = new ModelRenderer(this, 0, 16);

tailflapRight.addBox(-4.0F, -1.0F, 14.0F, 3, 1, 2);

tailflapRight.setRotationPoint(0.0F, 16.0F, 0.0F);

tailflapRight.setTextureSize(128, 128);

tailflapRight.mirror = false;

setRotation(tailflapRight, 0.0F, 0.0F, 0.0F);

 

tailflapLeft = new ModelRenderer(this, 0, 16);

tailflapLeft.addBox(0.0F, -1.0F, 10.0F, 3, 1, 2);

tailflapLeft.setRotationPoint(0.0F, 16.0F, 4.0F);

tailflapLeft.setTextureSize(128, 128);

tailflapLeft.mirror = false;

setRotation(tailflapLeft, 0.0F, 0.0F, 0.0F);

}

 

public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)

{

int maxAngle = 90;

super.render(entity, f, f1, f2, f3, f4, f5);

        GL11.glPushMatrix();

GL11.glScalef(5F, 5F, 5F);

GL11.glTranslatef((float)0, (float) -1.23, (float) 0.0);

body.render(f5);

nose.render(f5);

tail1.render(f5);

tail2.render(f5);

tail3.render(f5);

tail4.render(f5);

tailRotor.render(f5);

mainRotorA.render(f5);

mainRotorPole.render(f5);

mainRotorB.render(f5);

skidLeft.render(f5);

skidRight.render(f5);

skidBack.render(f5);

skidFront.render(f5);

RightLauncher.render(f5);

LeftLauncher.render(f5);

tailflapRight.render(f5);

tailflapLeft.render(f5);

        GL11.glPopMatrix();

}

 

public void renderModel(float f5){

body.render(f5);

nose.render(f5);

tail1.render(f5);

tail2.render(f5);

tail3.render(f5);

tail4.render(f5);

tailRotor.render(f5);

mainRotorA.render(f5);

mainRotorPole.render(f5);

mainRotorB.render(f5);

skidLeft.render(f5);

skidRight.render(f5);

skidBack.render(f5);

skidFront.render(f5);

RightLauncher.render(f5);

LeftLauncher.render(f5);

tailflapRight.render(f5);

tailflapLeft.render(f5);

}

 

 

private void setRotation(ModelRenderer model, float x, float y, float z)

{

model.rotateAngleX = x;

model.rotateAngleY = y;

model.rotateAngleZ = z;

}

 

public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)

{

super.setRotationAngles(f, f1, f2, f3, f4, f5, null);

}

 

}

 

 

 

I'm trying to get the model to rotate very very very fast! (Like a helicopter rotor would do)

Posted

In #setRotationAngles you have access to the Entity - use #ticksExisted (constantly increasing) to calculate an angle and set the specific part's rotationY to that value. That's one way, anyway.

I'm not entirely sure on how to come around imputing that code.

Do you have an example piece of code that I could use?

Posted

In your model file add something to this effect

 

This is from a model of mine

 

    public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)  {
    	
    	EntityParagon Entity = (EntityParagon)par7Entity;

    	this.LSHOULDERGEAR.rotateAngleX = Entity.ticksExisted * 0.139626F;
    	this.RSHOULDERGEAR.rotateAngleX = Entity.ticksExisted * 0.139626F;
    	this.LLEGGEAR.rotateAngleX = Entity.ticksExisted * 0.139626F;
    	this.RLEGGEAR.rotateAngleX = Entity.ticksExisted * 0.139626F;

    }

 

The effect...

 

The gears turn at a constant rate

 

Still no luck  :-[

 

 

Here's the code I've used:

 

    public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)  {

 

    EntityHuey Entity = (EntityHuey)par7Entity;

    this.mainRotorA.rotateAngleY = Entity.ticksExisted * 0.139626F;

    this.mainRotorB.rotateAngleY = Entity.ticksExisted * 0.139626F;

    this.tailRotor.rotateAngleX = Entity.ticksExisted * 0.0139626F;

 

    }

 

 

It doesn't seem to work either. Nor from restarting the mod or testing it in debugging mode.

Posted

#setRotationAngles is a method from ModelBase and is called automatically from the render class, unless as gummby8 asked the OP's model class does not extend ModelBase.

 

Right, didn't realise that. But yes, if you look at the code he posted it does extend ModelBase (It's just on the next line for some reason) so that's not the problem.

Posted

Right, didn't realise that. But yes, if you look at the code he posted it does extend ModelBase (It's just on the next line for some reason) so that's not the problem.

Indeed. Hm.

 

@OP Please post the entire class again with the most recent code. Also, are you sure you registered your entity renderer to use this particular model class?

 

A couple nitpicks:

1. ALWAYS put @Override above inherited methods; even though your method signature looks fine, better safe than sorry (plus it will help if / when you update to the next Minecraft version)

 

2. Please use standard Java naming conventions; variable names should start with lowercase 'entity' instead of 'Entity' - 'Entity.ticksExisted' looks like a static reference

 

3. You don't need to cast the entity parameter to access the #ticksExisted field, as it belongs to Entity not your class; unless you need to access fields or methods from your specific class, there is no reason to cast

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.

×
×
  • Create New...

Important Information

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