jdf / peasycam

Dead-simple mouse-driven camera for Processing
http://MrFeinberg.com/peasycam/
Apache License 2.0
116 stars 35 forks source link

lookThrough and modified setRotations #3

Closed eljeffeg closed 14 years ago

eljeffeg commented 14 years ago

It works, but I wouldn't say it's complete. It's at a point which I think is beyond my ability to improve. I sent you an e-mail, but here is the situation. I can't figure out how to restrict the orientation so that it only rotates side to side or up and down. My plan was to give options not only to lockX, lockY, lockZ, but to allow the specification for a degree. So that you could setLockZ and then setLockY +/- 60 degrees, such that it would prevent roll and only allow certain degree of up/down pitch. When I do a setRotation however, it doesn't seem to care - spinning the camera to focus on the x,y,z without any orientation. The rotations of pitch, yaw, roll don't seem translate into X,Y,Z rotations. It's a bit beyond me. Anyway... here is part of the code. Maybe it's enough to for some people, or perhaps you can complete it. Unfortunately for me, it doesn't do yet what I need it to do, which is rotate the camera around the Earth focusing on particular points. Can't stop it from flipping the Earth upside down or twisting it to some odd angle.

jdf commented 14 years ago

Many of the deltas are formatting changes. Please revert changes that are only formatting changes, so i can see what really changed!

eljeffeg commented 14 years ago

Ok.. give that a look

jdf commented 14 years ago

The code you've written seems always to look at 0,0,0, unless I misunderstand.

I still believe that this doesn't fit in PeasyCam.

eljeffeg commented 14 years ago

I thought that PeasyCam always sets the focus to 0,0,0.

I guess my thought was that rotations around a point are a very common request and are very difficult for most to implement. My method for rotating around a point is PeasyCam. So it made sense to me that PeasyCam would be an excellent way for people to get this functionality, since it already does most of it. So that all complex math was hidden, and they could just tell it to rotate to x,y,z point. It turned out to be far more difficult that I thought and I've all but given up. Even just programming it in my sketch without PeasyCam has been beyond my skill - I just don't understand the trig math involved when working with these vectors. It's a common support thread on the forum and I've yet to "get it".

eljeffeg commented 14 years ago

It could even be something simpler, like cam.rotateXto(x); So some x vector, instead of an angle. Have PeasyCam calculate the rotation required based on the lookAt to rotate the camera from the current position along the axis to the defined X vector. Allow for animation. It would seem that if rotating the camera by an angle or to an angle fits PeasyCam, it would also fit that PeasyCam could rotate to a vector, since that's how we define most things in 3d space.

jdf commented 14 years ago

There is no such thing as "rotateTo(x)", since it doesn't specify the up vector.

I'm going to close this, but I'll think about how to demonstrate a "look through" method. It may be that there is no well-defined way to do what you're trying to do, but I haven't thought about it very deeply yet.

eljeffeg commented 14 years ago

Sounds good, hope you figure it out. I would love it. I was saying rotateXto(x), which I thought would be different than rotateTo(x). So very similar to cam.rotateX(angle), but instead cam.rotateX(vector). Instead of me trying to figure out the X angle, have peasycam figure out the angle along that axis. Since it should know where it's at and where it would need to go along that axis, I thought it might work out well. But again, I obviously don't have enough knowledge to do it, or it would be done. haha