FAO Vorderman re z-virus

Miscellaneous Forums/Blitz Showcase/FAO Vorderman re z-virus

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Was messing about earlier today and I think I've nailed the original mouse control - I haven't implemented yet but can you tell me if this is what you remember?

Mousewheel to change mouse sensitivity...

Sample code ...

Graphics3D 640,480, 16,1

Global HGW# = GraphicsWidth()*.5
Global HGH# = GraphicsHeight()*.5
Global Light = CreateLight()
Global Pivot = CreatePivot()
Global YawPivot = CreatePivot()
Global Mirror = CreateMirror()
Global Plane = CreatePlane()
Global camera = CreateCamera()
Global p.SHIP
Const Gravity# = .005
Global GRAVITYon= True
Global JX#, JZ#, Mx#, Mz#, Thrust#
Global SENS# = 10.0
Global MinDist#, MaxDist#

Const FPS = 30
Global Timer = CreateTimer( FPS )

Type ship
	Field Model
	Field Yaw#
	Field Pitch#
	Field Momentum#
	Field Thrust#
	Field Vx#,Vy#,Vz#
End Type

init()

While Not KeyDown(1)

	WaitTimer Timer

	MOUSEinput()
	SHIPupdate()
		
	RenderWorld()
	OVALdraw( 55,55, Mindist*.25 , 1 , 150, 30, 30 )
	OVALdraw( 55,55, MaxDist*.25,0, 200,200,200 )
	Text 0,140,"Mouse Sensitivity : "+SENS
	OVALdraw( 55 + mx*.25 ,55 + mz*.25,3,0,200,200,50 ) 
	OVALdraw( 55,55,(MinDist+MaxDist)*.5*.25,0, 200,50,50 )
	Flip
	
Wend

;===================================
;===================================
;===================================

Function SHIPupdate()

	p\pitch =  limit( p\pitch + JZ , 0,180 )
	p\yaw = p\yaw + JX 
	RotateEntity yawpivot,0,p\yaw, 0
	RotateEntity p\model , p\pitch , p\yaw , 0
	
	TFormNormal 0,1,0, p\model,0
	p\vx = p\vx * p\momentum + TFormedX() * Thrust
	p\vy = p\vy * p\momentum + TFormedY() * Thrust - gravity
	p\vz = p\vz * p\momentum + TFormedZ() * Thrust
	TranslateEntity p\Model,p\vx,p\vy,p\vz
	If EntityY( p\Model ) < 2
		TranslateEntity p\Model,0,2.0-EntityY(p\model),0
		p\vy = -p\vy * .5
	EndIf
	
	tx# = ( EntityX( p\Model ) - EntityX( camera) ) * .5
	ty# = ( EntityY( p\Model ) - EntityY( camera) ) * .5
	tz# = ( EntityZ( p\Model ) - 10 - EntityZ( camera) ) * .5
	TranslateEntity camera, tx, ty, tz
	PointEntity camera, p\Model
	
End Function

;===================================
;===================================
;===================================

Function OVALdraw( x#, z#, rad# , fill#, r,g,b )

	Color r,g,b
	Oval x-rad, z-rad, rad*2+1,rad*2+1, fill

End Function

;===================================
;===================================
;===================================

Function MOUSEinput()

	;change sensitivity
	SENS = LIMIT (  SENS +  MouseZSpeed() * .25 , 2.0, 10.0 )

	MinDist# = 4.0 * SENS
	MaxDist# = 22.0 * SENS

	dx# = MouseX() - HGW
	dz# = MouseY() - HGH
	d# = Sqr( dx*dx + dz*dz )
	nx# = dx / d
	nz# = dz / d
	d# = limit( d , 0 , MaxDist )
	mx# = nx * d
	mz# = nz * d
	MoveMouse HGW +mx , HGH + mz
	thrust# = MouseDown(1) * p\Thrust

	;yaw
	If d > 0 
		PositionEntity pivot, mx, 0, - mz
		JX# = DeltaYaw( yawpivot , pivot )  * .2
	Else
		JX# = 0
	EndIf	
		
	;pitch
	If d >= MinDist
		JZ# =  ( ( ( d - MinDist) / ( MaxDist - MinDist ) *180.0 ) - p\pitch ) *.2
	Else
		JZ# =  - p\pitch * .1
	EndIf

End Function

;===================================
;===================================
;===================================

Function Init()

	EntityAlpha plane,.5
	EntityColor plane,25,25,100
	
	grid_tex=CreateTexture( 32,32,8 )
	ScaleTexture grid_tex,10,10
	SetBuffer TextureBuffer( grid_tex )
	Color 0,0,64:Rect 0,0,32,32
	Color 0,0,255:Rect 0,0,32,32,False
	SetBuffer BackBuffer()

	plane=CreatePlane()
	EntityTexture plane,grid_tex
	EntityBlend plane,1
	EntityAlpha plane,.6
	EntityFX plane,1
	
	p.ship = New Ship
	p\Model = CreateCone( 5,1 )
	RotateMesh p\Model, 90,0,0
	PositionEntity p\Model, 0,5,0
	EntityColor p\Model,50,200,50
	UpdateNormals p\Model
	ScaleMesh p\Model,.5,.25,.5
	p\thrust = .02
	p\momentum = .9925

	flame = CreateSphere( 3, p\Model )
	ScaleMesh flame,.25,.1,.25
	EntityColor flame,200,200,50
	PositionEntity flame,0,-.1,0

	PositionEntity camera,0,100,-100

	MoveMouse HGW, HGH

End Function

;===================================
;===================================
;===================================

Function LIMIT#(n#,n1#,n2#)
	
	If n>n2 Then n=n2
	If n<n1 Then n=n1	
	Return n

End Function

;===================================
;===================================
;===================================

Function WRAP#( q# , hi# , lo#=0 )
	
	If q < lo Then q = hi + (q-lo)
	If q >= hi Then q = lo + (q-hi)
	Return q
	
End Function