I've been working on a Python script that does some 3D processing on some data I have, without actually rendering anything (I want to take advantage of the rayCast and pointInsideFrustum mechanics, which is hard to find decoupled from a full-fledged graphics library). Basically what I'm doing is moving around cameras, projecting a ray from the camera, raycasting with some model, and testing what other camera poses' frustums contain that point.

Anyway, the issue I'm having is that when I try to move a camera in my script (done using both the bge KX_GameObject and bpy Object, for good measure; I also tried using applyMovement and applyRotation with limited success). While the position seems to be updated, it seems like it doesn't register. Namely, I perform a check to make sure that the camera can see the point that is returned from raycasting via pointInsideFrustum. However, it doesn't detect anything. I delay the script being run until after the first tick, so that the projection matrix can be initialized. Indeed, after checking, the projection matrix is in fact initialized, so that's not the problem.

However, the logic in the code works correctly, since, after restarting the code in game engine mode, it works fine. However, after moving the camera (in the code) to a position far enough away, it fails again. This leads me to believe that the camera isn't actually moving, or that it isn't properly registering. I suspect this might have to do with logic ticks in the Python script. From some other posts elsewhere that I've read, I suspect that Python scripts only are run in a single logic tick, though I'm not certain. If this is the case though, is there a way to make it run over multiple logic ticks?

It's important that this script be constantly running. As bad as it might sound, I have a web server running inside of this script, for the purpose of being able to do some processing via API requests.

  • $\begingroup$ Could you provide a small example file (without webserver of course) of what you are trying to achieve? Could be uploaded here (pasteall) for example if you don´t own a google account. $\endgroup$ – user2859 Apr 7 '14 at 11:17
  • $\begingroup$ pasteall.org/50698/python ; I've selected the main snippet where things aren't working. The very last line is where it fails. process is what the API calls, though adjust_camera is probably the method in question. $\endgroup$ – jtcramer Apr 7 '14 at 18:02
  • $\begingroup$ There are a lot of redundant transformations inside and outside of the bge in your script which will overwrite the ones you applied before. If you just want to set the absolute position of the camera e.g. you can assign the values directly to camera.worldPosition etc. Also there should be no need to touch objects outside of bge. That usually doesnt work well because when the game engine is fired up it doesnt look for changed scene data outside of bge anymore. $\endgroup$ – user2859 Apr 8 '14 at 8:20
  • $\begingroup$ Ohh okay. Before I learned that the camera projection matrix wasn't initialized until after the first tick, I made the transformations super repetitive because it wasn't working when I just used bge. But I guess since I'm delaying it should work now. I wasn't aware that things could go awry if you used both bpy and bge. $\endgroup$ – jtcramer Apr 8 '14 at 18:58
  • $\begingroup$ I've removed all traces of bpy, but the camera now doesn't seem to be moving at all, despite the worldPosition and worldOrientation attributes having changed, i.e. after I exit the Game Engine, the cameras haven't moved. I'm not not sure if this should necessarily be the case, but I'm more suspicious since the code that uses the camera from different positions doesn't seem to be working correctly. Any ideas? $\endgroup$ – jtcramer Apr 14 '14 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.