Jump to content

The most exact rayTrace of the player


Kloonder

Recommended Posts

Hello, my qustion is, if there is a poibility of getting the probably best rayTrace of the player, bacause the normal rayTrace method is not enought, I need to check 4 times more exact for a pixel, that means every pixel in game are 4 pixels. Is that possible?

A example: If you had a 64x64 texture pack, I wanna check what pixel theplayer is aiming for

 

float distance = 10;
MovingObjectPosition mop;
        Vec3 vec3 = Vec3.createVectorHelper(player.posX, player.posY, player.posZ);
        Vec3 vec31 = player.getLook(0);
        Vec3 vec32 = vec3.addVector(vec31.xCoord * distance, vec31.yCoord * distance, vec31.zCoord * distance);
        mop = player.worldObj.rayTraceBlocks(vec3, vec32, false, false, true);

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Link to comment
Share on other sites

First off, that sounds amazing. Secondly when your run the rayTrace method you get a MovingObjectPosition right? In there is a Vector called hitVec. If you wanted to get the exact hit on a 64x64 grid, then you could just do something like this

double hitX = MOP.hitVec.xCoord%1 (Using modulus 1 here because you only want the position hit in the block's local space)

 

double hitY = MOP.hitVec.yCoord%1

double hitZ = MOP.hitVec.zCoord%1

 

if(hitX<0){

    hitX++;

}

if(hitY<0){

    hitY++;

}

if(hitZ<0){

    hitZ++;

}

 

 

int pixelX = (int)Math.floor(hitX *64)

int pixelY = (int)Math.floor(hitY *64)

int pixelZ = (int)Math.floor(hitZ *64)

 

The math here doesn't work out perfectly, but you get the idea.

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

I think it is possible, but how difficult it is depends on the model of your entity and whether it moves much. In this case you're considering the player entity which is reasonably complicated and also can rotate and move some parts. Do you only want to check pixels on the main part of the body? Or also on head, arms, and legs.

 

Because the way raytracing works is mostly just trigonometry. You know where the eyes are, then know the look vector but it is up to you to figure out which pixel is hit. For example, if the player was facing you, then based on the model you would know the position of the body and using trigonometry you could figure out the intersection of the look vector with the plane. However, as soon as the body turns it gets much more complicated to get the math right.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Well, I am aiming for a EntityHanging, so it won't move

 

But it might be rotated compared to your viewing angle. That is part of why the math is hard -- you need to find the intersection of a line going from your eyes to a plane that is angled away from you. It is certainly possible to calculate accurately, but the math will probably drive you crazy before you get it right.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.