Posted: 30th Jun 2015 18:15
Edited at: 30th Jun 2015 19:19
Hi
I have a 3D program with objects that can be selected on screen with the mouse. works great i can position and rotate the objects and select them. But when i scale any objec the ObjectRaycast command cant see the objects anymore.
I Wrote some sample code below that reproduces the error.
It displays two cubes that are identical in every way they are both rotating and positioned on screen
when you pass the mouse over them they display the ID of whichever Object you are pointing at..
now if you click the mouse button the right cube grows to x3 size. and is no longer detectable. even though the only difference is the Scale
i did notice that once in a while it does seem to detect randomly but its very rare.
another experiment i tried was uniform scale (xyz all scaled the same amount) which does detect sometimes but detects as if it wasnt scaled at all . only the small cube area in the middle of the scaled cube selects it ignores the scaled portions. very strange. it also selects only at certain angles to the cube.
Anyway try the code below it doesn't use any external .OBJ files or anything.
And let me know if anyone else verifies this or has a fix.
Thks OminusPrime
// Project: TestScale
// Created: 2015-06-30
// set window properties
SetWindowTitle( "TestScale" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
CreateLightDirectional(1,0,-1,-1,255,255,255)
CreateLightPoint(1,0,0,200,600,155,155,255)
hhh=CreateObjectBox(100,100,100)
ggg=CreateObjectBox(100,100,100)
SetObjectPosition(ggg,70,0,300)
SetObjectPosition(hhh,-70,0,300)
SetObjectLightMode(ggg,1)
SetObjectLightMode(hhh,1)
SetCameraPosition(1,0,0,0)
SetCameraLookAt(1,0,0,300,0)
angle=0
do
print("Move Mouse From Cube to Cube to get ID")
print("Press L_Mouse for Scale")
print("When Cube 2 is scaled RayCast Fails")
//Rotate our object
inc angle
if angle>=360 then angle=0
SetObjectRotation(ggg,angle,angle,0)
SetObjectRotation(hhh,angle,angle,0)
//Code to allow mouse to probe objects
xx=GetPointerx()
yy=GetPointery()
X3D=1000*Get3dVectorXfromScreen(xx,yy)+GetCameraX(1)
Y3D=1000*Get3dVectorYfromScreen(xx,yy)+GetCameray(1)
Z3D=1000*Get3dVectorZfromScreen(xx,yy)+GetCameraz(1)
ObjectRayCast(0,GetCamerax(1),GetCameraY(1),GetCameraZ(1),X3d,Y3d,Z3d)
Hit=GetObjectRayCastHitID(0)
printc("CUBE ID="):print (Hit)
//This Code Gives us some scale if Left mouse Clicked
if GetRawMouseLeftState()
setobjectscale(ggg,1,1,3)
else
setobjectscale(ggg,1,1,1)
endif
Sync()
loop