SetHpr issues, pulling hair out

This will sound stupid but I am having trouble with something very basic. I have been using setHpr to aim my camera and until now had no need to do any more than setting the direction in a plane. Now, I made what is perhaps a stupid assumption, based on aeronautical experience. Hpr as I understand is essential yaw, pitch, roll. Okay, simple. Here is the problem.

I can set the first angle without a hitch. When I try to set any other angle, I get absolutely nothing. No other angle will ever change no matter what. I looked at the example code, copied some lines directly out of the ball maze and from roaming ralph. Zip. For some reason, I cannot set ANY angle other than the first. To wit:, 0, 0) works great., 30, 0) only yields the 48 degrees around the vertical axis., 0, 45) again yields only the 48 degree rotation around the vertical axis.

Variations do likewise. I have tried many different things, and the only angle that will ever, ever change is the first one. I cannot aim the camera in any non-horizontal direction. GRR! What am I missing? Is there something I have to import? Am I missing a function or a module? I looked at the manual, nothing. I looked at the example programs, nothing sticks out. Maybe I have been up far too many hours. I just don’t get it. Is there some documentation somewhere that I can refer to? Where do I find it?

Do I have to use camera.lookAt?



That’s… really weird. In and of itself, what you’re describing should work. And no, neither “lookAt” nor any additional imports should be required, as far as I’m aware.

Would you perhaps post more of your code (in “code” tags for readability’s sake)? My best guess is that you’re doing something elsewhere in your code that is producing that effect.

(I’m tempted to suggest that it’s something to do with objects being made children of the camera, but that should cause the “heading” value to appear ineffectual as well…)

I burned hours on this. I ran the examples, they worked. I went through my code carefully, checked things in sandboxes. No dice. I put breakpoints in, I looked at the sources. I walked around the block for a couple of miles, fuming. This is not logical. Software does not break. Code works. Keep telling yourself that.

I went back and followed through the examples again, saw nothing untoward. I located the prototypes in the Python sources. They looked squeaky clean. Growling louder. Getting ready to pull the legs off some animals here.

I did test cases for a range of values in an array. It got worse. Now I only got one single view that never changed, regardless of what values I entered. Fuming radioactive waste now.

I re-installed the distribution, rebooted. Problem evaporated. GAHHHH!!!

I have wasted precious and irreplaceable hours trying to do a simple task. Not acceptable, nobody to eviscerate. Code is now working perfectly with those innocent doe eyes. I am internalizing a language of guttural sibilant noises that involves rupturing tissues and roasting things.

At this point, I am so deep into doing this that I cannot back out and start over in another language.

Aah, it seems that something likely went wrong with your previous installation. Odd, but not implausible–but do keep an eye out for similar issues, just in case the issue is something more insidious.

However, I’m glad that you got your code working. :slight_smile:

Just curious about something. I created a routine for on-screen editing of parameters for something I am simulating, Turing machine stuff. Due to the view being perspective but needing to get absolute coordinates, I wrote a simple formula that takes the “screen” coordinates (you know, +/- 1 in each axis) into (x,y) pairs that are geometrically corrected.

Everything is well except then when you go to full-screen, the aspect ratio is off and none of the numbers work out. SO, I need to get the screen size. I tried a number of things, can’t locate anything in the manual except general hints, fell down the rabbit hole with WindowProperties, and cannot figure out how to read the screen size. Knowing that I can easily apply a single correction factor and be in business.

How would I read the screen size?

Thanks. I’ll post some screen shots now that I feel better about my progress here.



This can be done, I believe, but if I may, there may be an easier method of doing what you’re attempting. I take it that you’re attempting to convert 2D screen coordinates to 3D world coordinates.

First, if your target objects are arranged on a single plane, then you can use this method to pick points on that plane based on mouse coordinates.

If the objects are not arranged on a plane, then the “extrude” method used in the above suggestion may still be of use (but don’t use “extrudeVec”–that’s apparently intended for curved lenses).

Given a 2D point in the range (-1, 1) on both axes (such as mouse coordinates), “extrude” fills in the supplied point parameters with the resulting 3D near- and far- points corresponding to the vector passing through that 2D point on the lens. Given that, you can subtract one from the other (and normalise the result) to produce a direction vector; if you know how far it is to the target, then multiplying the direction vector by that distance should give you the location of the target point.

(You may also find “getRelativePoint”–again, as used in the first-mentioned suggestion–called for in order to get the points into the correct space.)

However, to answer your actual question, I believe that you can get the screen size as follows:

    winWidth =
    winHeight =

Perfect, thanks.



What I was up to is pretty simple. I have a number of objects on a plane marked with a grid. The mouse can select those objects but in order to get to their array data I need to know their position in “real” x-y-z. So knowing that the screen is a perspective view, I wrote a simple transformation that takes the mouse click, converts it into the actual coordinates of the objects, then scans their array to locate the specific thing that you wish to operate on.

It’s invisible to the user of course. They just point and click. The issue arose that when the aspect ratio of the screen changes, the ratios are all wonky. By reading the actual screen size I wrote a single correction factor that is updated at each frame and it automatically makes the numbers right again.