Let us see your solution if possible; but to answer the original question; you will need to query the object near a given position.
The following Visual Basic example can be done in DBPRO as aswell; you just need to alter the language using the original commands. Note that the use of [dim] in Visual Basic has been used to declare variables, not arrays.
Note that the use of the [AndAlso] keyword instead of the [And] keyword tells Visual Basic to only test the result of the next expression if the previous one is true; to save a little processing time.
We have created a function called:
GetObjectAt( [x], [y], [z], [defaultId] )
It will get the object at position X,Y,Z or with that location in its bounding box. It will search for the first occurance of this condition and return the first object that meets the requirement.
It will return [defaultId] if none was found.
If you need to control object priority, alter the function accordingly, searching from objects with high priority to the objects with the lowest priority. You could use the OrderBy query to sort a list:
Dim List As New List(Of MyClass)
Dim q = From Entry As Integer In List Order By Entry.Priority Descending
In the above example; q will contain all of your objects in order of their priority highest to low.
Dim List As New List(Of MyClass)
Dim q = From Entry As Integer In List Order By Entry.Priority
OR
Dim List As New List(Of MyClass)
Dim q = From Entry As Integer In List Order By Entry.Priority Ascending
will sort the list from low to high
In this example; the green sphere is used to set the position, and the cubes are coloured green when overlapping that position. In your case, you would want to set the position using literal or other variable parameters.
VB Code:
Imports DGDKPlugins.CDarkGDK
Imports DGDKPlugins
Public Class QueryObjectAt
Public Engine As New CDarkGDK
Public TotalObjects As Integer = 50
Public WithEvents Time As New Timer With {.Interval = 5, .Enabled = True}
Private Sub Time_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Time.Tick
oDB3D.PositionObject(1, oDB3D.ObjectPositionX(1) + oDBInput.RightKey() - oDBInput.LeftKey(), oDB3D.ObjectPositionY(1), oDB3D.ObjectPositionZ(1))
oDBCamera.PointCamera(oDB3D.ObjectPositionX(1), oDB3D.ObjectPositionY(1), oDB3D.ObjectPositionZ(1))
Dim NearestObjectToCamera As Integer = GetObjectAt(oDB3D.ObjectPositionX(1), oDB3D.ObjectPositionY(1), oDB3D.ObjectPositionZ(1), 1)
For I = 2 To TotalObjects
oDB3D.ColorObject(I, RGB(128, 128, 128))
Next
oDBText.Text(0, 0, "Move the sphere [LEFT] and [RIGHT] to select object")
oDB3D.ColorObject(NearestObjectToCamera, RGB(0, 255, 0))
oDBCore.Sync()
End Sub
Private Sub QueryObjectAt_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
oDB3D.MakeObjectSphereB(1, 2)
oDB3D.PositionObject(1, 25, 0, 0)
oDBCamera.PositionCamera(0, 0, 0)
oDB3D.ColorObject(1, oDB2D.Rgb(255, 0, 0))
For I = 2 To TotalObjects
Dim s As Double = (Rnd() * 9) + 1
Console.WriteLine("Object {0} is {1} units in size", I, s)
oDB3D.MakeObjectCube(I, (Rnd() * 9) + 1)
oDB3D.PositionObject(I, 20 * I, 0, 0)
oDB3D.SetObjectFog(I, False)
oDB3D.SetObjectCull(I, False)
Next
End Sub
''' <summary>
''' Get the object ID at a position within its bounding box; or a default ID.
''' www.binarymodular.com
''' </summary>
Public Function GetObjectAt(ByVal dX As Double, ByVal dY As Double, ByVal dZ As Double, Optional ByVal iDefault As Integer = 0)
Dim iResult As Integer = iDefault
For I = 2 To TotalObjects
If oDB3D.ObjectExist(I) Then
Dim x = oDB3D.ObjectPositionX(I)
Dim y = oDB3D.ObjectPositionY(I)
Dim z = oDB3D.ObjectPositionZ(I)
Dim oHX = oDB3D.ObjectSizeXB(I) * 0.5
Dim oHY = oDB3D.ObjectSizeYB(I) * 0.5
Dim oHZ = oDB3D.ObjectSizeYB(I) * 0.5
If x <= dX + oHX AndAlso x >= dX - oHX AndAlso _
y <= dY + oHY AndAlso y >= dY - oHY AndAlso _
z <= dZ + oHZ AndAlso z >= dZ - oHZ Then
Return I
End If
End If
Next
Return iResult
End Function
End Class