Jump to content

Is there a Vector * Scalar function?


big_red_frog

Recommended Posts

I continue to have fun modding in minecraft.

 

If I have two Vec3 instances, and I want to find the midpoint between them, then I find myself doing a lot of manual math.

 

In theory, it should be

 

vec2 - vec1 = vecDiff

midVec = vec1 + ( vecDiff * scalar_of_0.5 )

 

I can't see an elegant way to do this scalar multiplication on the Vec3 class, and end up with the following.

 

Vec3 diffVec = ent2Vec.subtract( ent1Vec );
Vec3 halfVec = new Vec3( diffVec.xCoord / 2, diffVec.yCoord / 2, diffVec.zCoord / 2 );
Vec3 midPoint = ent1Vec.add( halfVec );

 

Am I missing the obvious?

 

Is there a cleaner way to say something like this made up function below?

 

halfBetween = betweenVec.scalar( 0.5 )

 

So I could get to

 

Vec3 midPoint = entVec1.add( entVec2.substract( entVec1 ).scalar( 0.5 ))

 

 

Link to comment
Share on other sites

Wow, that was fast.

 

Do I need to do casting into Vec3 at the end, or will forge functions take a Vector3d as a parameter transparently.

 

Happy to stare at examples, if there are any...

 

Minecraft's vector classes aren't compatible with the

javax.vecmath

classes, you'll need to manually convert between them (i.e. create a new instance of the other vector class using the same coordinates as the existing vector).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.