Vue Python: GetFirstHitObject

The VUEInterface Class call GetFirstHitObject looks pretty straightforward in the documentation but I’ve had more emails about it than any other function in Vue’s Python. Hopefully this will help clarify its use.

You call GetFirstHitObject with two parameters. One says where to start trying to find an object from. The other says what direction to look in.

GetFirstHitObject ( vStart, vDirection )

vStart is a tuple of floats [x, y, z] that is the coordinates of the starting point. This uses Vue’s coordinates. It doesn’t use real world units if you’ve got those switched on for display.

vDirection is a tuple of floats [x, y, z] that is a vector of the direction to look for an object in.

So a call of GetFirstHitObject ((0,3.5,50),(0,0,-1)) starts at x=0 y=3.5 and z=50 it checks for an object that is somewhere below that point. If vDirection was (1,0,0) that would look along the x-axis. (1,1,0) would look along the diagonal of the x and y-axis.

Example Script

Get First Hit Object

Version: 0.1
Size: 17.5 KB
October 24, 2010

Python Code

[codesyntax lang=”python” title=”getfirsthitobject.py”]

#******************************************************
#
# Demonstration of GetFirstHitObject()
#
# - getfirsthitobject.py
# - By Mark Caldwell
# - Version 0.1 24th October 2010
# - Tested with Vue 8.5 Infinite
#
# How to use in 3 easy steps
#
# 1. Download this file and GetFirstHitObject.vue
#    onto your computer by downloading the zip file
#    and expanding it
#
# 2. Open GetFirstHitObject.vue in Vue 8.5 or later
#
# 3. Run this script
#
# To run it go to Python -> Run Python Script
# Then locate the file on your computer
#
#******************************************************

DisplayPythonConsole()
clear()

Obj=GetFirstHitObject ((0,3.5,50),(0,0,-1))
print 'Object: '+str(Obj)
if (Obj!=None):
    print 'Object Name: '+Obj.Name()

print

Obj=GetFirstHitObject ((0,3.5,50),(0,0,1))
print 'Object: '+str(Obj)
if (Obj!=None):
    print 'Object Name: '+Obj.Name()

print

[/codesyntax]

Line by Line Example Explanation

Lines 1 to 24 are my standard brief header block so, other than including quick instructions on using the script, you can skip over them.

Line 25 calls DisplayPythonConsole() to open Vue’s Python console if you’ve not already opened it.

Line 26 calls clear() so there isn’t anything else shown in the console.

Line 28 is the first of two calls to GetFirstHitObject.  This one should hit a sphere in the scene called Hit.

Line 29 prints the Object information about the object hit.  It should be something like VUEBasicObject instance at >.

Line 30 tests to see if Obj is an actual hit object. If it is Line 31 prints its name. It should print Hit.

Line 32 to 34 are a bit of spacing in the script and a print to add a blank line to the console display.

Line 35 is a second call to GetFirstHitObject. This one is fired in the opposite direction from the first one and shouldn’t hit anything as it fires off into empty space.

Line 36 prints the Object information about the object hit. Since nothing should be hit None should be printed.

Line 37 tests, just like line 30. Since nothing was hit it shouldn’t print an objects name on the next line.

impworks © Copyright Mark Caldwell 1996 - 2024