Jump to content

1.19.3 How To Get View Matrix?


sFXprt

Recommended Posts

Hi, I am trying to get the View Matrix so I can draw stuff in the game such as ESP or block/item/entity glow. Issue is I cant find the correct View Matrix. I am able to find the Projection Matrix from 

Minecraft.getInstance().gameRenderer.getProjectionMatrix(Minecraft.getInstance().options.fov().get());

and it works but I cant find the View Matrix at all. I've looked through all the classes and methods and the closest thing I found was 

RenderSystem.getModelViewMatrix();
RenderSystem.getShader().MODEL_VIEW_MATRIX.getFloatBuffer()
Minecraft.getInstance().gameRenderer.blitShader.MODEL_VIEW_MATRIX.getFloatBuffer();
Minecraft.getInstance().gameRenderer.getShader("").MODEL_VIEW_MATRIX.getFloatBuffer(); // Anyone know what goes in the string argument??

which both causes the game to print the usual unexpected errors message when running the code. 

This is all my code does so far

Vector3f screen_pos = WorldToScreen(new Vector3f((float) entity.position().x(), (float) entity.position().y(), (float) entity.position().z()), view_matrix, height, width);

Utils.MessageEx(p, "Screen X: " + screen_pos.x() + " Screen Y: " + screen_pos.y(), false);

All it does is return "An unexpected error has occurred" in the chat and I can't trace the exception error since its not stored in the logs unless a crash occurs(please let me know how to trace exceptions without crash)

So I'm just assuming I'm getting uninitialized matrix data which results in some null exception or something. 

 

EDIT:

I think I may have found it, calling 

Matrix4f m = new PoseStack().last().pose();

returns valid numbers in after World To Screen is called. Before I start rendering can anyone confirm this is indeed the most up to date View Matrix? And is there an interface forge uses to render objects. I know it dabbles in OpenGL but I am very unfamiliar with it and I was hoping it had built in rendering to combat open use of GL

Edited by sFXprt
Link to comment
Share on other sites

When you draw things in minecraft you do it in "world co-ordinates" not screen co-ordinates.

Minecraft will later translate the finish image into screen co-ordinates.

 

In a lot of cases you use "relative world co-ordinates"

i.e. minecraft calls your rendering code with the PoseStack already translated to the block/entity co-ordinates.

So you can just draw as though the block or entity was at 0, 0, 0

 

There are some specialist cases where you need to draw relative to the camera position (drawing custom block outlines is one IIRC?). But these are the exceptions.

In those cases forge passes you the data you need: https://github.com/MinecraftForge/MinecraftForge/blob/b5655b0ddc93ee0c02c9ad1b3a9a4dbd9bd3c572/src/main/java/net/minecraftforge/client/event/RenderHighlightEvent.java#L60

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

@warjort Thanks for helping me understand things better, so where do I go from now say for instance I want to draw an Rectangular Box around an Entity. Would I go about this using the RenderSystem class? If so could I get a simple example? I tried following Wurst Client source code which led me to seeing RenderSystem, VertexBuffer, and something called a MatrixStack being used? Which was called to get the View Matrix 

Matrix4f viewMatrix = matrixStack.peek().getPositionMatrix();

https://github.com/Wurst-Imperium/Wurst7/blob/master/src/main/java/net/wurstclient/hacks/chestesp/ChestEspRenderer.java#:~:text=Matrix4f viewMatrix %3D matrixStack.peek().getPositionMatrix()%3B

Edited by sFXprt
Link to comment
Share on other sites

You use EntityRenderers/Layers.

Registration: https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/src/main/java/net/minecraftforge/client/event/EntityRenderersEvent.java#L52

For examples, look at vanilla code or other mods. Most use entity models rather than direct rendering.

 

Things like Wurst (hacks) are not supported in this forum.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

@warjort thank you for your response, I can now access any given entitys renderer instance so how would I go about drawing it? Only example that comes to my mind is the glowing effect. Which I've tried to find its functionality through vanilla code to no avail. Best I found was it referring to a glowing.png file which upon opening the picture it displayed a skeleton head with white squares surrounding it.

EDIT: I've found this other forge topic which is exactly what I'm trying to achieve - 

However it runs on different code, specifically I cant find setTranslation() and RenderGlobal doesn't exist(maybe its RenderSystem now?) 

Edited by sFXprt
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.