small example
http://perso.wanadoo.fr/comtois/sources/Souris3D.zip
- PageUp and PageDown to raise or lower the height of the principal cube .
- Click to place a small cube at the position of the mouse
- Mouse changes color when there is target detection(one sphere and one cube)
Last one :
http://perso.wanadoo.fr/comtois/sources/Souris3D2.zip
Mouse in 3D space
Mouse in 3D space
Last edited by Comtois on Fri Oct 06, 2006 4:36 pm, edited 1 time in total.
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Thank you .
Added calculation of the distances to select an object
http://perso.wanadoo.fr/comtois/sources/Souris3D1.zip
[EDIT]
Small corrections
the file is updated.
Added calculation of the distances to select an object
http://perso.wanadoo.fr/comtois/sources/Souris3D1.zip
[EDIT]
Small corrections
Code: Select all
Global Dim ObjetBoite.s_Boite(#NbBoites)
Global Dim ObjetSphere.s_Sphere(#NbSpheres)
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
In Ogre3D you can create a Ray Object and check if it cuts a bounding box.
Sadly it isnt exportet in the OgreDll used in Pb.
At the moment we need to create an additional bounding box or sphere for each object we want to check.
Its not only the extra resources which are wastet but mainly the enormous programming work that is simply not neccesery if only the existing functions in Ogre would be exportet.
Functions like
#Entity = MouseOverEntity()
x = MouseoverEntityPartX(#Entity)
y = MouseoverEntityPartY(#Entity)
z = MouseoverEntityPartZ(#Entity)
bool = EntityIsInfrontOfCamera(#Entity)
x = MouseOverTerrainX()
y = MouseOverTerrainY()
Would be more than usefull.
And because most of the work is already done by the creators of Ogre there would be no need to reinvent the wheel.
The MouseOverEntity() function on its own would be verry helpfull.
Hopefully someday it will be implementet as a PB standard Function.
Sadly it isnt exportet in the OgreDll used in Pb.
At the moment we need to create an additional bounding box or sphere for each object we want to check.
Its not only the extra resources which are wastet but mainly the enormous programming work that is simply not neccesery if only the existing functions in Ogre would be exportet.
Functions like
#Entity = MouseOverEntity()
x = MouseoverEntityPartX(#Entity)
y = MouseoverEntityPartY(#Entity)
z = MouseoverEntityPartZ(#Entity)
bool = EntityIsInfrontOfCamera(#Entity)
x = MouseOverTerrainX()
y = MouseOverTerrainY()
Would be more than usefull.
And because most of the work is already done by the creators of Ogre there would be no need to reinvent the wheel.
The MouseOverEntity() function on its own would be verry helpfull.
Hopefully someday it will be implementet as a PB standard Function.
Yes that would be better if it were implemented in purebasic.
But while waiting for that, it allows to advance in the projects 3D.
and it is always good to know how it work
Btw here is a new version , added cylinder.
http://perso.wanadoo.fr/comtois/sources/Souris3D2.zip
But while waiting for that, it allows to advance in the projects 3D.
and it is always good to know how it work

Btw here is a new version , added cylinder.
http://perso.wanadoo.fr/comtois/sources/Souris3D2.zip
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
I worked out another aproach to this problem.
In simple words does it imitate the Ogre Raycast function.
In basics we have nearly everything we need.
We have our Camera Position in the World which can be retrieved with the
CameraX()
CameraY()
CameraZ()
Functions.
And we should know where the Camera is looking @.
( The values we give to CameraLookAt(X,Y,Z)
With this information we can create a Vector(StartPoint,Endpoint) where the Startpoint is the Camera Location and the Endpoint is where the Camera looks @.
Now we clone that vector and move both vector Points so the new vector is like Vector([Xstart+MouseOffset,Ystart+Mouseoffset,Zstart),[Xend+MouseOffset,Yend+Mouseoffset,Zend)
Along that vector we create a line/ray Entity+Mesh ( dont know how to describe it better ) with the lengt given by the maximum distence our picable objects are still rendered ( makes no sense to try to pick things we cant see ^^ )
Now we give our Ray a Physical Body with
EntityPhysicBody(#RayEntity, #PB_Entity_StaticBody)
and every pickable Object will get a suitable Physical Body.
When we do our Collission Check we can simply conpute the Object closest to the Camera which had a colission with our ray.
This object is the entity the user pointed on with his mouse.
Problems with this approach are
- we have to recompute the look@ Coordinates if we move the camera because we can set the value but cant retrieve the new value if we move our camera
- with a certain fov the approach wont work
- if the ray gets "out of the world" it will crash
But for things where the camera is always on a 2d plane and the angle to the ground is always the same ( like a 3d rts / rbs ) it should work fine to pick your units.
Still leaves the problem that we cant check colissions with the terrain so we cant order them to move to poin x/y ^^
In simple words does it imitate the Ogre Raycast function.
In basics we have nearly everything we need.
We have our Camera Position in the World which can be retrieved with the
CameraX()
CameraY()
CameraZ()
Functions.
And we should know where the Camera is looking @.
( The values we give to CameraLookAt(X,Y,Z)
With this information we can create a Vector(StartPoint,Endpoint) where the Startpoint is the Camera Location and the Endpoint is where the Camera looks @.
Now we clone that vector and move both vector Points so the new vector is like Vector([Xstart+MouseOffset,Ystart+Mouseoffset,Zstart),[Xend+MouseOffset,Yend+Mouseoffset,Zend)
Along that vector we create a line/ray Entity+Mesh ( dont know how to describe it better ) with the lengt given by the maximum distence our picable objects are still rendered ( makes no sense to try to pick things we cant see ^^ )
Now we give our Ray a Physical Body with
EntityPhysicBody(#RayEntity, #PB_Entity_StaticBody)
and every pickable Object will get a suitable Physical Body.
When we do our Collission Check we can simply conpute the Object closest to the Camera which had a colission with our ray.
This object is the entity the user pointed on with his mouse.
Problems with this approach are
- we have to recompute the look@ Coordinates if we move the camera because we can set the value but cant retrieve the new value if we move our camera
- with a certain fov the approach wont work
- if the ray gets "out of the world" it will crash

But for things where the camera is always on a 2d plane and the angle to the ground is always the same ( like a 3d rts / rbs ) it should work fine to pick your units.
Still leaves the problem that we cant check colissions with the terrain so we cant order them to move to poin x/y ^^