Notifications
Clear all

[Closed] Hit test viewport grid?

 PEN

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.

13 Replies

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

Based on your mouse position on screen I want the position on the grid. Without using the built in tools.

Ah, I see. Well, it’s going to take a smarter man than I to help you with that one.

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

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

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

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
 	)
 

Thanks PEN, added this to my little collection of script notes

 PEN

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
 	)
 
 
Page 1 / 2