GIMPY73 Posted April 17, 2010 Share Posted April 17, 2010 Ok after going through the BMax tut's that Foolish converted , I started to play about with the Pick commands. Now what i'm after is : Select a cube with the mouse. Attach the cube to the mouse's x,y,z coordinates while the mouse button is held. Drop the cube when mouse button is released. Here is what i have sofar: 'Use the Leadwerks Engine module as our base Framework leadwerks.engine 'Create an OpenGL graphics window Graphics 800, 600 'Allows the engine to find files and load files from zip packages RegisterAbstractPath AppDir 'Create a world If Not CreateWorld() RuntimeError "Failed to create world." 'Create a camera cam:TCamera = CreateCamera() CameraClearColor(cam, Vec4(0, 0, 1, 1)) MoveEntity cam, Vec3(0, 20, - 35) 'create a ligt light:TLight = CreateDirectionalLight() RotateEntity(light, Vec3(65, 45, 0)) 'Create a render Buffer buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL) 'create a mesh cube:TMesh = CreateCube() Local pick:TPick 'create materials selectionmaterial:TMaterial = CreateMaterial() SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1)) pointentity cam , cube 'Main loop While Not KeyHit(KEY_ESCAPE) 'pick objects with the mouse If MouseDown(1) PaintEntity(cube, 0) pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000)) If pick Then PaintEntity(pick.entity, selectionmaterial) positionentity (pick.entity , vec3(pick.x,0,pick.z)) End If End If 'Update timing, physics, and other miscellaneous updates UpdateWorld 'Draw the world SetBuffer(buffer) RenderWorld 'render lighting SetBuffer(BackBuffer()) RenderLights(buffer) 'Swap the graphics buffers so we can see what we drew Flip Wend It kinda works , but the cube keeps letting go , even if i still have the mouse button held down??? Any ideas Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 This maybe of help I'll have a run through your code in a few Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Canardia Posted April 17, 2010 Share Posted April 17, 2010 You might need to press the mouse button with both hands. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 You might need to press the mouse button with both hands. No just move the mouse really .. really slowly Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
Canardia Posted April 17, 2010 Share Posted April 17, 2010 You can also stop taking a new pick in each loop, since it will sometimes grab nothing and then the box falls down and may get damaged: If MouseDown(1) PaintEntity(cube, 0) If Not pick Then pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000)) If pick Then PaintEntity(pick.entity, selectionmaterial) positionentity (pick.entity , vec3(pick.x,0,pick.z)) End If Else pick = Null End If Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 but a single pick will only create one new position to move to and then only if the distance the cursor is moved still keeps the pick on the cube then another click will have to be made surely? The problem seems to be the method for picking and the speed the mouse cursor moves in Gimpys original code. Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 Yep thats what is happening MG Maybe i need to add somit about the mouse speed ?? Anyway thanks for looking @Lumooja I'll try holding the mouse button down with 2 hands lol Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 HA HA MG Just read the link to the super glue Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 Yep thats what is happening MG Maybe i need to add somit about the mouse speed ?? Well think about the pick, if its not on the cube then no pick results. This can be seen in this slight alteration to your code: 'Use the Leadwerks Engine module as our base Framework leadwerks.engine 'Create an OpenGL graphics window Graphics 800, 600 'Allows the engine to find files and load files from zip packages RegisterAbstractPath AppDir 'Create a world If Not CreateWorld() RuntimeError "Failed to create world." 'Create a camera cam:TCamera = CreateCamera() CameraClearColor(cam, Vec4(0, 0, 1, 1)) MoveEntity cam, Vec3(0, 20, - 35) 'create a ligt light:TLight = CreateDirectionalLight() RotateEntity(light, Vec3(65, 45, 0)) 'Create a render Buffer buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL) 'create a mesh cube:TMesh = CreateCube() ScaleEntity(cube,Vec3(2,2,2)) ground:TMesh = CreateCube() ScaleEntity(ground,Vec3(40,0.01,40)) PositionEntity(ground,Vec3(0,-2,0)) Local pick:TPick 'create materials selectionmaterial:TMaterial = CreateMaterial() SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1)) pointentity cam , cube 'Main loop Global loctite:Int = 1 While Not KeyHit(KEY_ESCAPE) If MouseDown(1) PaintEntity(cube, 0) PaintEntity(ground, 0) pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000)) If pick PaintEntity(pick.entity, selectionmaterial) positionentity (pick.entity , vec3(pick.x,0,pick.z)) End If End If 'Update timing, physics, and other miscellaneous updates UpdateWorld 'Draw the world SetBuffer(buffer) RenderWorld 'render lighting SetBuffer(BackBuffer()) RenderLights(buffer) 'Swap the graphics buffers so we can see what we drew Flip Wend Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 Ok i see what is happening there MG. So maybe i need to set some kind of flag , that turns the pick off once an entity is selected ??? Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 if you turn the pick off you are no longer getting getting a new position to move the cube to. You could use the pick to maybe select the cube but then use something like CameraProject to create world cordinates from the mouse pointer and move the cube to that position? Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 Ahh a new command to look into Cheers MG , will try CameraProject command and see what i can come up with. Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 17, 2010 Share Posted April 17, 2010 will try CameraProject not really looked into it but I think cameraproject takes 2D to 3D. Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 Ok had a play with CameraProject , aint gota clue what im doing lol 'Use the Leadwerks Engine module as our base Framework leadwerks.engine 'Create an OpenGL graphics window Graphics 800, 600 'Allows the engine to find files and load files from zip packages RegisterAbstractPath AppDir 'Create a world If Not CreateWorld() RuntimeError "Failed to create world." 'Create a camera cam:TCamera = CreateCamera() CameraClearColor(cam, Vec4(0, 0, 1, 1)) MoveEntity cam, Vec3(0, 30, -10) 'create a ligt light:TLight = CreateDirectionalLight() RotateEntity(light, Vec3(65, 45, 0)) 'Create a render Buffer buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL) 'create a mesh cube:TMesh = CreateCube() sphere:TMesh = Createsphere() positionentity sphere,vec3(0,10,0) Local pick:TPick 'create materials selectionmaterial:TMaterial = CreateMaterial() SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1)) pointentity cam , cube debugphysics(1) depth:Float = 0.0 near:Float = 1.0 far:Float = 10.0 'Main loop While Not KeyHit(KEY_ESCAPE) 'pick objects with the mouse If MouseDown(1) PaintEntity(cube, 0) PaintEntity(sphere, 0) pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000)) If pick Then PaintEntity(pick.entity, selectionmaterial) glReadPixels(MouseX(), GraphicsHeight() - MouseY(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr(depth)) z:Float = near / (far - depth * (far - near)) * far; pos:TVec3 = CameraProject(cam, Vec3(MouseX(), MouseY(), z)) positionentity (pick.entity, Vec3(pos.x,pos.y,pos.z)) End If End If 'Update timing, physics, and other miscellaneous updates UpdateWorld 'Draw the world SetBuffer(buffer) RenderWorld DrawText "Depth: " + depth, 0, 0 DrawText "Projected: " + pos.x + ", " + pos.y + ", " + pos.z,0,12 'render lighting SetBuffer(BackBuffer()) RenderLights(buffer) 'Swap the graphics buffers so we can see what we drew Flip Wend It seems to hold onto the mouse better , but it still don't seem right. Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
AggrorJorn Posted April 17, 2010 Share Posted April 17, 2010 Perhaps this helps you. It is not blitzmax but perhaps it can give you a direction to look in to. You can run it directly in the editor. also the link of the topic: http://leadwerks.com/werkspace/index.php?/topic/1620-solved-placing-objects-in-front-of-you/ FPSpickupObjects.zip Quote Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 17, 2010 Author Share Posted April 17, 2010 Thanks Aggror , will check it out Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 18, 2010 Author Share Posted April 18, 2010 Well still no luck with this , but i did come up with a simple Point'N'Click routine Thanks Gimyp73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Marleys Ghost Posted April 18, 2010 Share Posted April 18, 2010 Not sure what it is you want to do with this but have a quick look at this thread on the old forum Quote AMD Bulldozer FX-4 Quad Core 4100 Black Edition 2 x 4GB DDR3 1333Mhz Memory Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5 Windows 7 Home 64 bit BlitzMax 1.50 • Lua 5.1 • MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro 3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET LE 2.5/3.4 • Skyline • UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0 Marleys Ghost's YouTube Channel • Marleys Ghost's Blog "I used to be alive like you .... then I took an arrow to the head" Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 18, 2010 Author Share Posted April 18, 2010 Cheers For the link MG , will take a look I'm also going over Aggror's lua code again I'm just after selecting a cube/sphere/model etc.. , then lock it to the mouse's X,Y,Z. Then release the mouse button to place the cube/sphere/model etc.. The code i did kinda works , but as you've seen if the mouse is moved fast it lets go of the selected object. Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Joh Posted April 19, 2010 Share Posted April 19, 2010 This probably is a pick-positionentity issue. Remeber that pick is done on updateworld, so probably if you move fast it "lost" the the object, you should just do a pick, something like this: Check if mousedown, check if a boolean pick is true, if not cast a raycast, if yes just position the object till you don't release the button (to do this you can simply put another boolean on top of loop and set it to false, if mouse is down you reset i to true, on the end of the loop you check that variable, if false put the pick to nulland release the object) In this case you'll never lose the object. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks Joh Will give your method a try Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Joh Posted April 19, 2010 Share Posted April 19, 2010 Yeah something like this.. I haven't tested it. 'Use the Leadwerks Engine module as our base Framework leadwerks.engine 'Create an OpenGL graphics window Graphics 800, 600 'Allows the engine to find files and load files from zip packages RegisterAbstractPath AppDir 'Create a world If Not CreateWorld() RuntimeError "Failed to create world." 'Create a camera cam:TCamera = CreateCamera() CameraClearColor(cam, Vec4(0, 0, 1, 1)) MoveEntity cam, Vec3(0, 30, -10) 'create a ligt light:TLight = CreateDirectionalLight() RotateEntity(light, Vec3(65, 45, 0)) 'Create a render Buffer buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL) 'create a mesh cube:TMesh = CreateCube() sphere:TMesh = Createsphere() positionentity sphere,vec3(0,10,0) Local pick:TPick 'create materials selectionmaterial:TMaterial = CreateMaterial() SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1)) pointentity cam , cube debugphysics(1) depth:Float = 0.0 near:Float = 1.0 far:Float = 10.0 'MODIFY local pick:TPick = null 'Main loop While Not KeyHit(KEY_ESCAPE) 'MODIFY local check:int = false 'pick objects with the mouse If MouseDown(1) 'MODIFY check = true PaintEntity(cube, 0) PaintEntity(sphere, 0) 'MODIFY if pick = null pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000)) endif If pick Then PaintEntity(pick.entity, selectionmaterial) glReadPixels(MouseX(), GraphicsHeight() - MouseY(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr(depth)) z:Float = near / (far - depth * (far - near)) * far; pos:TVec3 = CameraProject(cam, Vec3(MouseX(), MouseY(), z)) positionentity (pick.entity, Vec3(pos.x,pos.y,pos.z)) End If End If 'Update timing, physics, and other miscellaneous updates UpdateWorld 'Draw the world SetBuffer(buffer) RenderWorld 'MODIFY if check = flase then pick=null DrawText "Depth: " + depth, 0, 0 DrawText "Projected: " + pos.x + ", " + pos.y + ", " + pos.z,0,12 'render lighting SetBuffer(BackBuffer()) RenderLights(buffer) 'Swap the graphics buffers so we can see what we drew Flip Wend Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
GIMPY73 Posted April 19, 2010 Author Share Posted April 19, 2010 Your code works great joh Gona read through it and see what i was doing wrong lol Thanks Gimpy73 Quote http://www.fallingpixel.com/mac10-3d-model/26203 (MAC-10) http://www.fallingpixel.com/glock17-3d-model/26471 (Glock-17) http://www.youtube.com/user/MRGIMPY73 Link to comment Share on other sites More sharing options...
Joh Posted April 19, 2010 Share Posted April 19, 2010 No problem. Quote Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.