peasycam icon indicating copy to clipboard operation
peasycam copied to clipboard

adding methods to move camera front and back (.move, .forward, .backward)

Open rsepierre opened this issue 3 years ago • 4 comments

rsepierre avatar Jan 24 '22 13:01 rsepierre

The goal for this commit was to provide a public interface to move the PeasyCam camera center position. Because "center" is private, even by extending the PeasyCam Class, we can not add the possibility to move or "pan" backwards or forwards relative to the camera.

For this reason, I created three methods (although they are not all necessary) which are similar to the pan method :

  • .move (x, y, z) -- similar to panning relative to the camera, on three axis.
  • .forward (distance) -- moves the center forward for a certain distance.
  • .backward (distance) -- moves the center backward for a certain distance.

I could not find any way to actually build the library so I could not test the code. I think then maybe forward and backward are inverted, otherwise I think it should behave just like .pan() as code is mostly identical;

Alternative ways I thought about to fixing the issue :

  • make the "center" variable public
  • add z parameters to .pan() (instead of creating .move)

As unfortunately extending the PeasyCam Class does not provide any public interface with "center" I hope that you will consider those changes for the main branch.

rsepierre avatar Jan 24 '22 14:01 rsepierre

I have since successfully compiled peasycam and tested the functions that worked seamlessly. Just as I feared I had to invert .forward and .backard but everything works fine.

I'm not sure how pull requests work. The last two commits added themselves to the PR automatically. If considered for master, should probably filter out changes made to the compiler/builder and .gitignore

rsepierre avatar Jan 26 '22 01:01 rsepierre

Ok it's a lot of commits for this, I'm sure there was better way to git my way out of there but here should be everything that changes with the pull request as of now :

  • Implementation of move() which enables moving on x,y,z axis relative to the camera.
  • implementation of forward() and backward() which uses move()
  • pan() now also uses move()
  • deletion of the unused import processing.core.PShape; in Resizable_Offscreen.java Eclipse was warning about.
  • Every other file should be reverted to current master state, untouched.
	public void move(final double dx, final double dy, final double dz) {
		center = center.add(rotation.applyTo(new Vector3D(dx, dy, dz)));
		feed();
	}

	public void pan(final double dx, final double dy) {
		move(dx, dy, 0);
	}

	public void forward(final double distance) {
		move(0, 0, -distance);
	}

	public void backward(final double distance) {
		move(0, 0, distance);
	}

rsepierre avatar Jan 26 '22 14:01 rsepierre

@jdf Hi there ! I allow myself to tag you as I'm guessing this might have slipped through your priorities :-) I was wondering if you were satisfied with the current state of the pull request ?

rsepierre avatar Feb 21 '22 15:02 rsepierre