Posted December 23, 20159 yr 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 ))
December 23, 20159 yr Author 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...
December 23, 20159 yr Author While I am scratching around in here, am I going mad, or does Entity.getVectorForRotation(float pitch, float yaw) take parameters in degrees but Vec3.rotateYaw(float yaw) take parameters in radians Ouch...
December 23, 20159 yr 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.
December 23, 20159 yr Vec3 does have a lot of math methods though. Are you sure none of them work for your case? Looking at the type hierarchy there are subtractions, additions, dot products, multiply, get intermediate, normalize, etc. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
December 24, 20159 yr Author I believe dotproduct and crossproduct are vector applied to vector, not scalar to vector I don't see a "multiply" is it present in your version? if so, what version are you in.
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.