2D Mousepointer in 3D als Target für 3D Objekte :-) von Markus
Kleines Beispiel wie man einen 2D Mousepointer in 3D umsetzt der
vor der Kamera hängt und wenn man die linke Maustaste drückt
sich ein Entity(3D Objekt) zur Maus bewegt .
Sieht ganz lustig aus wenn man mit der Taste 4 die Kamera nach
vorne bewegt und irgendwo im Raum hinklickt .
Taste 1,2 und 3 drehen die Kamera um Pitch , Yaw und Roll .
Wenn man die Maus erst in der Mitte des Screen klickt sich
gleichzeitig nach vorne bewegt und dann die Maustaste los läßt
fliegt das Objekt weil es ja steht direkt in die Kamera :shock:

HidePointer noch benutzen !
Weil das Sprite stellt die Maus da .
Wenn man die Screen Auflösung verändert /8.0 anpassen !

[code:1:f5bf2cd2fa]
Graphics3D 640,480, 16,0

Global cam=CreateCamera()
PositionEntity cam,0,50,0
; dreht Camera um 60 Grad nach unten
RotateEntity cam,60,0,0
MoveEntity cam,0,-25,0

;------------------------------------------

Global world=CreateCube()
Global worldtx=CreateTexture(64,64)
SetBuffer TextureBuffer(worldtx)
Color 128,128,128
Rect 0,0,64,64
Color 0,0,128
Rect 0,0,32,32
Rect 32,32,32,32
SetBuffer BackBuffer()
ScaleTexture worldtx,0.25,0.25
ScaleMesh world,500,500,500
EntityTexture world,worldtx
UpdateNormals world
FlipMesh world

;------------------------------------------

Global Light=CreateLight(2)
PositionEntity Light, 0 , 0,0
LightRange light,150
;------------------------------------------

Global Player= CreateCube()
EntityColor Player,0,255,0

;------------------------------------------
Global Mouse=CreateSprite()
EntityColor Mouse,255,255,0
EntityOrder Mouse,-1

;------------------------------------------------------
While Not KeyHit(1)

If KeyDown(2) Then ;Taste 1
TurnEntity cam,1,0,0
EndIf
If KeyDown(3) Then ;Taste 2
TurnEntity cam,0,1,0
EndIf
If KeyDown(4) Then ;Taste 3
TurnEntity cam,0,0,1
EndIf
If KeyDown(5) Then ;Taste 4
MoveEntity cam,0,0,0.5
EndIf

Local mx,my

Local px#,py#,pz#

mx=MouseX()
my=MouseY()

px= (mx-GraphicsWidth() /2)/8.0
py=-(my-GraphicsHeight()/2)/8.0
pz=40

TFormPoint px,py,pz,cam,0

px=TFormedX()
py=TFormedY()
pz=TFormedZ()

PositionEntity Mouse,px,py,pz

If MouseDown(1) Then MoveToMouse Player

RenderWorld
Color 255,255,0
Text 0,0,"drücke linke Maustaste und der Würfel bewegt sich zur Maus :-)"
Text 0,20,"Tasten 1=Camera Pitch+ , 2=Camera Yaw+ , 3=Camera Roll+ , 4=Camera Z+ "
Flip
Wend
End

;------------------------------------------------------

Function MoveToMouse(Entity)

If Entity=0 Then RuntimeError "ERR: FUNC MoveToMouse Parameter Entity=0"

Local entf=EntityDistance(Entity,Mouse)

If Abs(entf)>4 Then
PointEntity Entity,Mouse
MoveEntity Entity,0,0,1
EndIf

End Function
[/code:1:f5bf2cd2fa]
===
von ???
Hehe, witzig..
... und brauchbar!



Suche:
(unterstützt mySQL Wildcards ala %)
Titel:
Text:
Autor: