# Is there a Vector * Scalar function?

## 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 ))`

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

##### Share on other sites

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)

Ouch...

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

##### Share on other sites

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/

##### Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• I couldn't find much usage, I found this and attempted to implement it. It doesn't seem to do anything though. I have this linked to a server to client packet... I have been at this since September seventh and have not made any progress. Blockpos and Blockstate are all pre-assigned variables, as is pLevel. I took the vertex consumer directly from LevelRenderer where I got this code from anyways. I didn't know what number to put into the ModelBakery.DESTROY_TYPES.get() so I just put the breakTime I used in the above code. Am I missing something?
• Mods: https://pastebin.com/6rXZLU8i
• Problematic part: [net.minecraft.server.network.ServerGamePacketListenerImpl/]: Gu57 lost connection: Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException: Cannot invoke "net.minecraft.resources.ResourceLocation.toString()" because "p_130086_" is null There is no crash, single player works, sadly it's not Hexerei Debug log: (can't use pastebin, cause 10 mb) https://drive.google.com/file/d/16ikQIx7nYjJtF4aJLy5KqFQHh6-jBNrd/view?usp=sharing
• Something in the Alex's Caves mod is preventing Distant Horizons from rendering. However, I don't want to get rid of Alex's Caves, as it is a part of my personal modded experience. Can someone please find the issue for me?
• So there's a mod I found earlier, and it's called Hyperworld, which is a mod that allows you to explore the 4th dimension. It seemed really cool to add into my modpack, until I realized, it's only available for 1.20.2 on Fabric, and my modpack with ~200 mods is on 1.20.1 on Forge. So I was wondering if anyone can port it from 1.20.2 Fabric to 1.20.1 Forge.

• ### Who's Online (See full list)

• There are no registered users currently online
×

• #### Activity

×
• Create New...