Jump to content

GIMPY73

Members
  • Posts

    300
  • Joined

  • Last visited

Posts posted by GIMPY73

  1. 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 :P

  2. Ok here is a simple point'n'click routine:)

     

    '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()
    'MoveEntity cam, Vec3(0, 45, - 45)
    
    '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)
    
    piv=createpivot()
    
    'create a mesh
    cube:TMesh = CreateCube()
    
    Local plane:tentity = CreatePlane()
    ScaleEntity  plane,  Vec3(100,0.1,100)
    
    PaintEntity (plane,LoadMaterial("abstract::cobblestones.mat"))
    
    Local pick:TPick
    
    'Main loop 
    While Not KeyHit(KEY_ESCAPE) 
    
    positionentity (cam,vec3(cube.position.x,cube.position.y+25,cube.position.z-25))
    pointentity cam,cube
    
    'pick objects with the mouse
    If MouseDown(1) = True
    
    	pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))
    
    	If pick Then
    
    		positionentity (piv,vec3(pick.x,.5,pick.z))
    		pointentity cube,piv
    		Local speed#=.3
    
    	End If
    
    End If
    
    If (entitydistance(cube,piv) < 1.2)
    	speed#=0
    End If
    
    moveentity cube,vec3(0,0,speed#)
    
    '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

     

    Could be used for an RPG/RTS style of game.

     

    Feel free to laugh/poke fun at it , just thought i would share :)

     

    Thanks

    Gimpy73 :P

    • Upvote 2
  3. 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 :P

  4. 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 :P

  5. 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 :D

     

    Thanks

    Gimpy73 :)

×
×
  • Create New...