Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi everybody.  I am wondering if there is a easy way or method to get the ForgeDirection that a Vec3 (or any other type of 3D vector) is pointing?  I am trying to make a block that blends in to it's souroundings, if it makes any difference.  Thank you in advance.

Hi

 

I don't know of a  vanilla function for this but it is easy enough to do yourself.

 

Find which of the three components [x, y, z] have the largest absolute magnitude.  The vector is pointing mostly in that direction.

 

eg [0.5, -0.6, 0.9] is pointing mostly in the positive z direction

[0, -0.7, 0.3] is pointing mostly in the negative y direction

 

-TGG

  • Author

Thanks, but I think I can make a exact way.  If you can get the ForgeDirection an Entity is looking, that would also work.

  • Author

This is what I'm going to try to use.  Fell free to use it yourself :)

 

Revised:

public static ForgeDirection getForgeDirection(Vec3 vec) {

	vec.normalize();

	double pitchR = Math.atan(vec.yCoord / Math.sqrt(Math.pow(vec.xCoord, 2) + Math.pow(vec.zCoord, 2)));
	double yawR = Math.atan2(-vec.zCoord, vec.xCoord);
	double pi = Math.PI;

	ForgeDirection dir = ForgeDirection.UNKNOWN;

	System.out.println("Pitch: " + pitchR + ", Yaw: " + yawR);

	if(yawR < -pi || yawR > pi)
		System.err.println("Yaw is too big!!");

	if(pitchR > -pi/4 && pitchR < pi/4){ // if the vector is mostly horizontal

		if(yawR >= -pi/4 && yawR <= pi/4)
			dir = ForgeDirection.EAST;
		else if(yawR < -pi/4 && yawR >= -3*pi/4)
			dir = ForgeDirection.SOUTH;
		else if(yawR > pi/4 && yawR <= 3*pi/4)
			dir = ForgeDirection.NORTH;
		else if(yawR < -3*pi/4 || yawR > 3*pi/4)
			dir = ForgeDirection.WEST;



	} else if(pitchR >= pi/4)
		dir = ForgeDirection.UP;
	else
		dir = ForgeDirection.DOWN;

	return dir;
}

 

Edit:  I have a gitch where it sometimes thinks South is West, and I have no idea why.

Edit 2: I fixed it.

Hi

 

Keen, that will work too.  Both of our methods give the same answer.  Yours is better if you want to know the exact yaw & pitch, although it has a small bug in it - what happens if vec.xCoord and vec.zCoord are both zero?

 

-TGG

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.