hi, im new here, i have experience using python in 2D and I wanted to go 3D and I find panda3D
My idea is to make a simple flight simulator
I have a problem with rotations of a model (my plane)
when I roll the plane and I try to Pitch Up the plane pitches up but it moves like the starting axisâŚ
so thats the question⌠how can I rotate the axis to move with the plane?
This creates a node called planeParent, which is a child of render; and your plane is a child of planeParent. Now, if you think pitch should be applied before roll, you can do:
planeParent.setP(pitch)
plane.setR(roll)
On the other hand, if you think roll should be applied before pitch, you can do:
The H value is 0. This is âheadingâ, sometimes called âyawâ, which is the angle about the vertical axis. Itâs independent of both P and R, so if you never set it, itâs going to be 0. Did you expect it to have a different value?
I mean,
if the plane its going to the south⌠then I want to go to west⌠the plane rolls, pithces, and rolls again and now its going west⌠but now wen I roll, the plane pitchesâŚ
how can I fix that?
Oh, you want to move the plane relative to its current rotation.
Instead of messing around with planeParent, just do:
plane.setR(plane, deltaR)
or:
plane.setP(plane, deltaP)
where deltaR and deltaP are the amount by which you want to change P or R (not the new values of P and R). This will rotate the plane by the indicated number of degrees, relative to its current rotation. These rotations will accumulate in the way I think you want them to.
Actually, I think you are getting confused with the heading, pitch, and roll of a plane, and what these mean in Panda.
In a plane if you roll, then âpitchâ (pull up), and then roll back, you will have changed heading. In Panda if you do the same thing you will just have changed pitch.
Youâre probably better off using quaternions for your sim.
Right, unless you do all of these operations relative to yourself, as I described above. In this case, the operations will accumulate, and you will have changed heading at the end of it.
Here ares some snippets of code from the flight sim I am working on right now.
As a fair warning: We spent a good month bashing around in Euler angles, and got it working fairly easily. The magic is understanding HPR changes relative to yourself as opposed to relative to the scene. We abandoned Euler due to our poor math and satans gimbal problem.
For instance, if you just setP(x) your ship will now be pitched x deg up relative to its parent node (im guessing render). But usually the desired effect is to pitch up relative to yourself, ie if you are rolled 180 deg then pitching up relative to yourself is actually pitching down relative to scene.
Quaternions are scary even for math people; but i think you can use them even if you dont quite understand. You can grab a TON of useful info off of the quaternion itself getForward etc.
self.changeQuat = Quat() #in constructor
###
#task call
SQUARERADIUS = .7
x = base.mouseWatcherNode.getMouseX()
y = base.mouseWatcherNode.getMouseY()
percentX = x / SQUARERADIUS
percentY = y / SQUARERADIUS
if percentX > 1:
percentX = 1
if percentY > 1:
percentY = 1
if percentX < -1:
percentX = -1
if percentY < -1:
percentY = -1
self.newP = percentY
self.newH = -percentX
self.newR = 0
self.speed = self.ship.getSpeed()
self.changeQuat.setHpr(VBase3(self.newH, self.newP, self.newR))
#Model here is the thing thats moving around
#Note that camera is parented to it
self.model.setQuat(self.changeQuat * self.model.getQuat())
self.velocityVector = self.model.getQuat().getForward() * self.speed
self.model.setPos( self.velocityVector[0] + self.model.getX(),
self.velocityVector[1] + self.model.getY(),
self.velocityVector[2] + self.model.getZ())
Basically a bounding square inside of aspect2d that takes percentages of where the mouse cursor is relative to that box and applies it to pitch heading.
I just use the changeQuat as just that and add it into the models quat, seems to work ok.