PDA

View Full Version : Hit test viewport grid?


PEN
03-14-2006, 02:25 PM
Is there a method for hit testing the viewport grid? Not a grid object but the grid plane that you would build an object on? I don't want to use mouse tools, I'm thinking more along the lines of intersectRay or rayMeshGridIntersect. I just can't sort you how to get either to just get the viewport grid. Any one have a solution to this? I know that I could put a temporary grid object in there but I would rather not.

JHaywood
03-14-2006, 08:21 PM
I could be way off, but since you always know where the viewport grid is, do you even need to test for it? What exactly are you trying to do?

PEN
03-14-2006, 08:53 PM
Based on your mouse position on screen I want the position on the grid. Without using the built in tools.

JHaywood
03-15-2006, 12:47 AM
Ah, I see. Well, it's going to take a smarter man than I to help you with that one. :)

magicm
03-15-2006, 01:24 AM
This script will place a point helper on the home grid (or a user grid when it's activated) at the current mouse position. Not entirely without built-in tools but it works ;)

point pos:((gw.getPointOnCP mouse.pos) * (getCPTM()))

Cheers,
Martijn

PEN
03-15-2006, 12:08 PM
That is what I'm looking for:) I only just started digging into what pointOnCp does. Perfect, I think that I might be back on track.

PEN
03-15-2006, 06:37 PM
And here is a hit test for an object if any one is interested. It returns the ray of the face that it hits.


fn hitTest =
(
theRay=mapScreenToWorldRay mouse.pos
hitRay=intersectRay $ theRay
)

PEN
03-15-2006, 06:44 PM
Or a more complete one.


fn hitTest =
(
theRay=mapScreenToWorldRay mouse.pos
for x in objects do
(
hitRay=intersectRay x theRay
if hitRay!=undefined then
(
return hitRay
)
)
undefined
)

stuh505
03-15-2006, 08:16 PM
Thanks PEN, added this to my little collection of script notes

PEN
03-15-2006, 08:47 PM
Here is the latest, this one will get the closest face to you, the last would only return the first object that it hit. Returns undefined if it does hit anything and if it does it returns a ray.


fn hitTest =
(
theRay=mapScreenToWorldRay mouse.pos
dist=undefined
theHit=undefined
for x in objects do
(
hitRay=intersectRay x theRay
if hitRay!=undefined then
(
tempDist=distance hitRay.pos theRay.pos
if dist==undefined or tempDist<dist then
(
dist=tempDist
theHit=hitRay
)
)
)
theHit
)

magicm
03-15-2006, 11:53 PM
I haven't tested this, but these changes might make it a liiitle bit quicker:

for x in geometry dodist = 1e+008 --> if tempDist < dist thenThis way the dist variable doesn't need to be tested for undefined for each iteration.


Don't think it'll make much difference but it might be worth trying.

Cheers,
Martijn

PEN
03-16-2006, 12:02 PM
Thanks Martijn, for dist I had that originaly but changed if for some reason. Maybe I will do a speed test on that and see what it does for me. As for just looping through geo well I didn't catch that at all, thanks that will make it much faster if used in a big scene.

Rivendale
03-16-2006, 02:08 PM
Hey, here is the way I do it to get a position on the grid:

pixelpos = mouse.pos
gw.mapCPToWorld (mapScreenToCP pixelpos)


CML

PEN
03-16-2006, 03:19 PM
Good to know that there is another way. I think that I might go with thePainterInterface now anyway as it looks like it solves one of the main problems. If I use any of the built in mouseTools functions then I don't have accress so everying thing else as I'm painting. If I write it all using mouse, gw and viewport tools then I run into the problem that the I'm always in selection mode and that just isn't clean. So thePainterInterface deals with every thing as far as I can tell so far.

CGTalk Moderation
03-16-2006, 03:19 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.