Srekel
21-07-2006 19:16:31
We're making a game in the veins of the old Populous games which means that we will allow the player to raise and lower ground as he pleases (among other things). Now, the problem is that the scenequeries always returns the point directly below the camera, not where the camera is looking.
We're using PyOgre, so there could theoretically be some kind of binding issue, but I doubt that.
This is the code for shooting the ray and editing the terrain (which works, only it does it below the camera):
The result output looks like this:
There are a few problems I see. First, when it hits a worldfragment, the distance is 0.0, which can't be correct, right?
Second, one result of each query is that it hits nothing, neither a movable or a worldfragment - but! When this happens, the distance appears to be correct (it grows as you look further away in the distance).
Any explanation for this weird behaviour? Are we doing something the wrong way?
EDIT: Oh, and another thing. A worldfragment is always in the result list, even if you aren't over the terraing and/or are looking away from it.
We're using PyOgre, so there could theoretically be some kind of binding issue, but I doubt that.
This is the code for shooting the ray and editing the terrain (which works, only it does it below the camera):
print "***shooting ray***"
self.raySceneQuery = self.dataManager.sceneManager.createRayQuery(
ogre.Ray(self.dataManager.camera.position,
self.dataManager.camera.direction))
mouseRay = self.dataManager.camera.getCameraToViewportRay(0.5, 0.5)
self.raySceneQuery.ray = mouseRay
for queryResult in self.raySceneQuery.execute():
if queryResult.worldFragment is not None:
print "wf dist", queryResult.distance
print "wf deforming at:", queryResult.worldFragment.singleIntersection
v = queryResult.worldFragment.singleIntersection
self.dataManager.plsm2SceneManager.setDeformationCenter( v )
elif queryResult.movable is not None:
print "mov", queryResult.movable
print "mov dist", queryResult.distance
else:
#print "none!"
print "non dist", queryResult.distance
The result output looks like this:
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19250.5429688
non dist 19058.1464844
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19205.6796875
non dist 19157.9316406
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19205.6796875
non dist 19157.9316406
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19361.375
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19570.1464844
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19570.1464844
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19676.5957031
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19676.5957031
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 19893.7363281
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 20462.6132813
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 21071.5976563
***shooting ray***
wf dist 0.0
wf deforming at: Vector3(-28892.339844, 236.209656, -7840.181152)
non dist 21457.9023438
There are a few problems I see. First, when it hits a worldfragment, the distance is 0.0, which can't be correct, right?
Second, one result of each query is that it hits nothing, neither a movable or a worldfragment - but! When this happens, the distance appears to be correct (it grows as you look further away in the distance).
Any explanation for this weird behaviour? Are we doing something the wrong way?
EDIT: Oh, and another thing. A worldfragment is always in the result list, even if you aren't over the terraing and/or are looking away from it.