Hi
Problem solved thanks to all:
1) save the actual SbViewportRegion from the actual viewer
2) save from the actual camera: location, type, neardistance
fardistance, orientation matrix
2b) for convenience calculate the inverse of the orientation matrix too
3) get from the actualcamera its actual SbViewVolume.
4) extract via the ViewVolume the witdh and hight of the nearplane
window and the viiewing direction of the camera
5) if necessary use the size in pixels from the saved Viewport to
claculate the relative screen coordinates of the desired screen point,
when given in pixels ...
6) scale the relative coordinates to the ones inside the nearplane using
the extracted width and hight
7) make the nearplanepoint relative to the viewingpoint which is usually
centered on the nearplane of the viewing volume (simply assume that
facht and subtract haf of width and hight)
8) transform the relative point from viewiongvolume to wolrdspace
applying the orientation matrx to the point
9) add the saved cameralocation to it and a vector having the length of
the neardistance and
which points in the viewing direction.
10) if the camera is PERSPECTIVE subtract the cameralocation from the
newly generated worldspacepoint in order to get the final ray direction
if the camera is orthographic set the final raydirection to the saved
viewing direction of the camera
11) call your ray with the worldspacepouint from 9 and the direction from 10
12) apply your ray to your scene and check if there is an intersection
at all :)
13) on redo of the projection or if you have more than one point to
project onto the same surface using the same camera settings, simply
repeat the steps 5 to 12 or even better save
the relative cooridinates calculated in 5 too for reuse and only do
steps 6 to 12
The camera independent way back is a bit easier but requires that at
least steps 1 to 4
have been performed once
a) subtract the surfacepoint in worldcoordinates from the camera
location to get the vector between themn
b) calcualte the angle(bettre the cosine) between the vector from a) and
the viewing direction
c) if the cosine from b) is bigger than 0 the surfacepoint lies behind
the camera an usually can be ignored
d) calculate the absolutevalue of the cosine from b) and check wether
the length of the vector from a) times the absolute cosine is longer
than the fardistance or shorter than the
neardistance than the point can usually be ignored too as it does
definitlynot ly inside the viewing volume of the recorded camera
e) subtract the neardistance form the length calculated in d and devide
by the absolutevalue of the cosine from d)
f) if the camera is perspective set the length of the vector from a to
the length calculated in e
if the camera is orthographic set the length of the viewingdirection
vector to the length calculated in e but do not devide this length by
the absolute value of th cosine from d)
g) add the vector form f to the original suface point in order to get
the corresponding point on the nerplane of the recorde viewing wolume in
worldspace coordinates;
h) subtract from the point in g) the location of the camera and the
vector having the length of the neardistance to make it relative to the
viewvolume
i) use tthe inverse of the camera orientation matric (might ba
calculated in 2b) to transfomr the point from h) back into the cameraspace
j) make the point from i absolute in respect to the nearpalnewindow and
deviede it by its margins to reoptain the its former relative screen
coorinates
cu
Christop Hintermüller
--
THESIS: God is alive
PROOVE: Who else would have scheduled the mankind and world first
recommendation of resrearch????
CONCLUSION: Scientists do what he wants, willing or not:)
|