Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Can you translate/Rotate a item using a LWJGL Matrix4f


Discult
 Share

Recommended Posts

Hello I am currently in the works of making a model loader that loads in boned/jointed models from maya/blender. I have the models loading and rendering sorted I am just wondering i am using 

Minecraft.getMinecraft().getItemRenderer().renderItem(entityIn, new ItemStack(Items.IRON_AXE), ItemCameraTransforms.TransformType.NONE);

to render the item model but i want to rotate it following its bone which has its data stored in a matrix4f. What can i do to apply these translations and rotations onto the item.

 

Thank you for reading.

Link to comment
Share on other sites

If you already know your way around openGL and matrix transformations, the two main ways of interacting with it when MC modding are...

 

1. Through the GlStateManager, which is a layer between MC and LWJGL, and caches some openGL state data, then only updates LWJGL (and therefore openGL) when the data has changed (eg. if you set the color to the same color it has cached, it won't send the LWJGL command)

 

2. Through LWJGL, which sits between GlStateManager and openGL, and has commands very similar to the normal openGL command set

 

If you don't know exactly what to do with the matrix itself...well then I'm not much help because neither do I.  I did some direct matrix stuff a long time ago but don't remember any of it.  In any case, if you haven't already done so, I suggest looking through the GlStateManager class and the openGL documentation.  That's probably about as much as I can say to help, so gl!

Edited by Laike_Endaril
Fixed typo
Link to comment
Share on other sites

9 minutes ago, Laike_Endaril said:

If you already know your way around openGL and matrix transformations, the two main ways of interacting with it when MC modding are...

 

1. Through the GlStateManager, which is a layer between MC and LWJGL, and caches some openGL state data, then only updates LWJGL (and therefore openGL) when the data has changed (eg. if you set the color to the same color it has cached, it won't send the LWJGL command)

 

2. Through LWJGL, which sits between GlStateManager and openGL, and has commands very similar to the normal openGL command set

 

If you don't know exactly what to do with the matrix itself...well then I'm not much help because neither do I.  I did some direct matrix stuff a long time ago but don't remember any of it.  In any case, if you haven't already done so, I suggest looking through the GlStateManager class and the openGL documentation.  That's probably about as much as I can say to help, so gl!

thanks i have been i am just trying to find a way to get the translations and stuffi already have in a matrix4F and eaither return them to their  float values or just use the matrix instead 

Link to comment
Share on other sites

You can almost certainly use the matrix itself...but beyond that I'm not sure exactly which method(s) you'll need to do so correctly.  It might be the multMatrix call, but I can't remember for sure.  Whatever you do, make sure you pushMatrix exactly once before you do any matrix alterations, and popMatrix exactly once after you render.

 

In GlStateManager:

    public static void multMatrix(FloatBuffer matrix)
    {
        GL11.glMultMatrix(matrix);
    }

 

And on the openGL docs page: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMultMatrix.xml

I don't remember what order the matrix data needs to be in when changing from a matrix4f to a float buffer, but I would hope the provided method for doing so would do so correctly, so if you're really lucky...

 

GlStateManager.pushMatrix();
FloatBuffer buf = FloatBuffer.allocate(16);
Matrix4f yourMatrix = ???;
yourMatrix.store(buf);
GlStateManager.multMatrix(buf);

//Render stuff here

GlStateManager.popMatrix();

 

Also keep in mind that there are several Matrix4f classes to choose from when importing.  LWJGL has one, minecraft has one...I'm not sure what the differences between them are, but the minecraft one may do something special with the data ordering...I have no idea.  I don't even have confidence that this will work, but it's something you can try if you feel like.

Link to comment
Share on other sites

2 minutes ago, Laike_Endaril said:

You can almost certainly use the matrix itself...but beyond that I'm not sure exactly which method(s) you'll need to do so correctly.  It might be the multMatrix call, but I can't remember for sure.  Whatever you do, make sure you pushMatrix exactly once before you do any matrix alterations, and popMatrix exactly once after you render.

 

In GlStateManager:


    public static void multMatrix(FloatBuffer matrix)
    {
        GL11.glMultMatrix(matrix);
    }

 

And on the openGL docs page: https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMultMatrix.xml

I don't remember what order the matrix data needs to be in when changing from a matrix4f to a float buffer, but I would hope the provided method for doing so would do so correctly, so if you're really lucky...

 


GlStateManager.pushMatrix();
FloatBuffer buf = FloatBuffer.allocate(16);
Matrix4f yourMatrix = ???;
yourMatrix.store(buf);
GlStateManager.multMatrix(buf);

//Render stuff here

GlStateManager.popMatrix();

 

Also keep in mind that there are several Matrix4f classes to choose from when importing.  LWJGL has one, minecraft has one...I'm not sure what the differences between them are, but the minecraft one may do something special with the data ordering...I have no idea.  I don't even have confidence that this will work, but it's something you can try if you feel like.

Thank you i will look into it

 

Link to comment
Share on other sites

GL11.glMultMatrix(getRenderMatrix().asDoubleBuffer());

 

as Laike_Endaril already noticed.

 

Is your source available somewhere? I did something a while back for Wavefront Object Models, but never finished it. And would be interested in some working solution for rigged Meshs, as my Rig was just based on an hand written XML File for now.


Also im curious about how you solve Collision Detection ? (you might want to switch over to some other Matrix4f class like https://github.com/TheCBProject/CodeChickenLib/blob/master/src/main/java/codechicken/lib/vec/Matrix4.java, as LWJGL code isnt available on serverside)

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.

Guest
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I'm trying to get the item meta of all the items if that helps. like the lore and stuff.
    • Hello. When i tried making another server but for another version i cant seem to find a mods folder. and making one doesn't help.
    • public abstract class NitroglycerinFluid extends ForgeFlowingFluid { // Directly reference a log4j logger. private static final Logger LOGGER = LogManager.getLogger(); protected NitroglycerinFluid(Properties properties) { super(properties); } public static Properties createProperties() { return new Properties(() -> ModFluids.NITROGLYCERIN, () -> ModFluids.FLOWING_NITROGLYCERIN, FluidAttributes.builder(new ResourceLocation("sussybakaplus:block/nitroglycerin_still"), new ResourceLocation("sussybakaplus:block/nitroglycerin_flow")).overlay(new ResourceLocation("sussybakaplus:block/nitroglycerin_overlay")).density(3000).viscosity(1000).luminosity(15).temperature(1300)).tickRate(1).canMultiply().bucket(() -> ModItems.NITROGLYCERIN_BUCKET).block(() -> ModBlocks.NITROGLYCERIN); } @Override public boolean isSource(FluidState state) { return false; } @Override public int getAmount(FluidState state) { return state.getValue(LEVEL); } public void animateTick(Level p_76445_, BlockPos p_76446_, FluidState p_76447_, Random p_76448_) { LOGGER.info("animate"); if (!p_76447_.isSource() && !p_76447_.getValue(FALLING)) { if (p_76448_.nextInt(64) == 0) { p_76445_.playLocalSound((double)p_76446_.getX() + 0.5D, (double)p_76446_.getY() + 0.5D, (double)p_76446_.getZ() + 0.5D, SoundEvents.WATER_AMBIENT, SoundSource.BLOCKS, p_76448_.nextFloat() * 0.25F + 0.75F, p_76448_.nextFloat() + 0.5F, false); } } else if (p_76448_.nextInt(10) == 0) { p_76445_.addParticle(ParticleTypes.UNDERWATER, (double)p_76446_.getX() + p_76448_.nextDouble(), (double)p_76446_.getY() + p_76448_.nextDouble(), (double)p_76446_.getZ() + p_76448_.nextDouble(), 0.0D, 0.0D, 0.0D); } } @Nullable public ParticleOptions getDripParticle() { return ParticleTypes.DRIPPING_WATER; } @Override protected void beforeDestroyingBlock(LevelAccessor accessor, BlockPos pos, BlockState state) { BlockEntity blockentity = state.hasBlockEntity() ? accessor.getBlockEntity(pos) : null; LOGGER.info("spread to " + state.getBlock().getRegistryName().toString()); if (state.getBlock().getRegistryName().getPath().equals("fire")) { float f = 4.0F; Minecraft.getInstance().level.explode(null, pos.getX(), pos.getY(), pos.getZ(), f, Explosion.BlockInteraction.BREAK); } //Block.dropResources(state, accessor, pos, blockentity); } @Override public void tick(Level level, BlockPos pos, FluidState state) { //super.tick(level, pos, state); LOGGER.info("tick"); if (this.hasBurningNeighbors(level, pos)) { LOGGER.info("EXPLODING!!!"); float f = 4.0F; level.explode(null, pos.getX(), pos.getY(), pos.getZ(), f, Explosion.BlockInteraction.BREAK); } else { LOGGER.info(pos.toShortString() + " doesn't have any buring neighbors"); } } private boolean hasBurningNeighbors(LevelReader levelReader, BlockPos pos) { for(Direction direction : Direction.values()) { if (this.isBurning(levelReader, pos.relative(direction))) { return true; } } return false; } private boolean isBurning(LevelReader levelReader, BlockPos pos) { return (pos.getY() < levelReader.getMinBuildHeight() || pos.getY() >= levelReader.getMaxBuildHeight() || levelReader.hasChunkAt(pos)) && levelReader.getBlockState(pos).isBurning(levelReader, pos); } protected float getExplosionResistance() { return 0.0F; } public int getTickDelay(LevelReader p_76226_) { return p_76226_.dimensionType().ultraWarm() ? 1 : 1; } protected boolean isRandomlyTicking() { return true; } public Optional<SoundEvent> getPickupSound() { return Optional.of(SoundEvents.BUCKET_FILL); } } My Fluid Class
    • So how do I get the container? It doesn't need to be a event btw.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.