Jump to content

Point'N'Click


GIMPY73
 Share

Recommended Posts

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
Link to comment
Share on other sites

Ok ive been playing abit more with this and ran into a problem.

 

 

'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()

'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()
PositionEntity cube,vec3(0,.5,0)

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+60,cube.position.z-30))
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

'Zoom in / out	
Select MouseZSpeed()

Case 1
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

	zoom#=zoom#+1

Case -1
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	zoom#=zoom#-1

End Select

If zoom#<1 Then zoom#=1 
If zoom#>5 Then zoom#=5
CameraZoom cam,zoom#


If MouseDown(2) = True
	speed#=0
	mx# = MouseXSpeed()*.3
	TurnEntity cam,vec3(0,mx#,0)
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

 

Im trying to get the camera to point and rotate around the cube when the right mouse button is held down.

I used some old code from a Blitz3D project and that worked fine for Blitz3D.

 

I can get the camera to point and rotate around the cube as a seperate program , but i don't want to work with the above code.

 

Any pointers on this???

 

Thanks

Gimpy73 :)

Link to comment
Share on other sites

Never mind , i fixed it by adding another pivot for the camera :)

 

It seems to snap when you press the right mouse button , but atleast it works :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."

campiv=CreatePivot()
'Create a camera 
cam:TCamera = CreateCamera(campiv)
PositionEntity cam,vec3(0,60,-30)

'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()
PositionEntity cube,vec3(0,.5,0)

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) 

mx# = GraphicsWidth()/2 - MouseX()

PositionEntity (campiv,vec3(cube.position.x,cube.position.y,cube.position.z))
'PositionEntity (cam,vec3(cube.position.x,cube.position.y+60,cube.position.z-30))
PointEntity cam,campiv

'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

'Zoom in / out	
Select MouseZSpeed()

Case 1
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

	zoom#=zoom#+1

Case -1
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	zoom#=zoom#-1

End Select

If zoom#<1 Then zoom#=1 
If zoom#>5 Then zoom#=5
CameraZoom cam,zoom#

If MouseDown(2) = True
	speed#=0
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	TurnEntity campiv,vec3(0,mx#,0)
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

 

Thanks

Gimpy73 :blink:

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...