Page 1 sur 1

Picking sur matérial invisible

Publié : mar. 25/juin/2013 20:49
par G-Rom

Code : Tout sélectionner

InitEngine3D()
InitKeyboard()
InitSprite()


window = OpenWindow(#PB_Any,0,0,1024,768,"")
OpenWindowedScreen(WindowID(window),0,0,1024,768)


;
; On créer une texture 
;
texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(texture))
  Box(0,0,512,512,$FFFFFF)
  Ellipse(256,256,25,50,0)
  Ellipse(256,256,12,24,$0000FF)
StopDrawing()

;
; Un material basic pour la texture
;
material = CreateMaterial(#PB_Any,TextureID(texture))

;
; La lumière , on change la couleur ambiente ( très important )
; On ajoute une lumiere de base omnidirectionel
;
AmbientColor($101010)
CreateLight(#PB_Any,$FFFFFF,0,-30,-50)

;
; une camera basic
;
camera = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camera,0,10,-20)
CameraLookAt(camera,0,0,0)


;
; un mesh sphere qui servira de base pour nos yeux
;
sphere_mesh   = CreateSphere(#PB_Any,2,64,64)
TransformMesh(sphere_mesh,0,0,0,1,1,1,0,0,0)
left_eye  = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material),-2,0,0,$0010)
right_eye = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material), 2,0,0,$0010)


;
; une texture "invisible"
;
texture  = CreateTexture(#PB_Any,1,1)
material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialBlendingMode(material, #PB_Material_AlphaBlend)

;
; un plan orienté face à la camera avec le material invisible
; & un pick mask différent
;
plane_mesh   = CreatePlane(#PB_Any,100,100,1,1,1,1)
TransformMesh(plane_mesh,0,0,-15,1,1,1,-CameraPitch(camera),0,0)
UpdateMeshBoundingBox(plane_mesh)
plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001) 



While #True
  
  event = WindowEvent()
  
  If event = #PB_Event_CloseWindow
    Break
  EndIf 
  
  ExamineKeyboard()  
  
  If KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf 
  
  
  ;
  ; On pick sur notre plan invisible & on récupère les coordonées 
  ; du point de picking & on oriente nos yeux , plus le plan est près 
  ; plus les yeux "louche" quand la souris est entre les 2.
  ;
  If MouseRayCast(camera,WindowMouseX(window),WindowMouseY(window),$0001)
    lookAtX.f = PickX()
    lookAtY.f = PickY()
    lookAtZ.f = PickZ()
    EntityLookAt(left_eye,  lookAtX, lookAtY, lookAtZ)
    EntityLookAt(right_eye, lookAtX, lookAtY, lookAtZ)
  EndIf 
  
  
  ClearScreen(0)
  RenderWorld()
  FlipBuffers()
  Delay(1)
Wend 


Re: Picking sur matérial invisible

Publié : mar. 25/juin/2013 21:14
par SPH
Super pour apprendre. Je vais examiner ca :idea:

Re: Picking sur matérial invisible

Publié : mar. 25/juin/2013 21:17
par Ar-S
Nikel :!:

Re: Picking sur matérial invisible

Publié : mar. 25/juin/2013 21:27
par SPH
Pourrais faire une sorte de tuto avec des petits exemples comme celui la ? :mrgreen:

Re: Picking sur matérial invisible

Publié : mar. 25/juin/2013 21:29
par G-Rom
File moi 100 balles :mrgreen:
non, j'ai pas le temps de faire plus malheureusement.
mais si tu as une idée sur la laquelle tu bloques , y a toujours le forum.

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 9:17
par Mesa
Ah, j'ai un bug avec Xp 32b et pb5.20b2.

Je n'ai qu'un écran gris.

Si je commente les lignes 60 à 63
; plane_mesh = CreatePlane(#PB_Any,100,100,1,1,1,1)
; TransformMesh(plane_mesh,0,0,-15,1,1,1,-CameraPitch(camera),0,0)
; UpdateMeshBoundingBox(plane_mesh)
; plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001)

alors j'ai les "yeux"

Mais si je change TransformMesh(sphere_mesh,0,0,0,1,1,1,0,0,0) en TransformMesh(sphere_mesh,0,0,0,4,4,4,0,0,0) (en dessous de 4 ça ne fonctionne pas)

avec les lignes 60 à 63 non commentées

plane_mesh = CreatePlane(#PB_Any,100,100,1,1,1,1)
TransformMesh(plane_mesh,0,0,-15,1,1,1,-CameraPitch(camera),0,0)
UpdateMeshBoundingBox(plane_mesh)
plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001)
(décommenté)

alors j'ai le "yeux" mais déformés car trop gros je suppose.

Pourtant les exemples 3D fonctionnent d'habitude.

Mesa

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 10:37
par G-Rom

Code : Tout sélectionner

TransformMesh(sphere_mesh,0,0,0,1,1,1,0,0,0)
ne sert à rien , j'ai oublié de le viré.
c'est un problème de texture que tu as sur le plane invisible.

Code : Tout sélectionner

InitEngine3D()
InitKeyboard()
InitSprite()


window = OpenWindow(#PB_Any,0,0,1024,768,"")
OpenWindowedScreen(WindowID(window),0,0,1024,768)


;
; On créer une texture 
;
texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(texture))
  Box(0,0,512,512,$FFFFFF)
  Ellipse(256,256,25,50,0)
  Ellipse(256,256,12,24,$0000FF)
StopDrawing()

;
; Un material basic pour la texture
;
material = CreateMaterial(#PB_Any,TextureID(texture))

;
; La lumière , on change la couleur ambiente ( très important )
; On ajoute une lumiere de base omnidirectionel
;
AmbientColor($101010)
CreateLight(#PB_Any,$FFFFFF,0,-30,-50)

;
; une camera basic
;
camera = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camera,0,10,-20)
CameraLookAt(camera,0,0,0)


;
; un mesh sphere qui servira de base pour nos yeux
;
sphere_mesh   = CreateSphere(#PB_Any,2,64,64)
left_eye  = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material),-2,0,0,$0010)
right_eye = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material), 2,0,0,$0010)


;
; une texture "invisible"
;
texture  = CreateTexture(#PB_Any,1,1)
StartDrawing(TextureOutput(texture))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,1,1,RGBA(0,0,0,0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0,1,1,RGBA(255,0,0,128)) ; <-------------------------------------------------------------------- REMPLACE 128 PAR 0
StopDrawing()
material = CreateMaterial(#PB_Any,TextureID(texture))
DisableMaterialLighting(material,1)
MaterialBlendingMode(material, #PB_Material_AlphaBlend)

;
; un plan orienté face à la camera avec le material invisible
; & un pick mask différent
;
plane_mesh   = CreatePlane(#PB_Any,100,100,1,1,1,1)
TransformMesh(plane_mesh,0,0,-19,1,1,1,-CameraPitch(camera),0,0)
UpdateMeshBoundingBox(plane_mesh)
plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001) 



While #True
  
  event = WindowEvent()
  
  If event = #PB_Event_CloseWindow
    Break
  EndIf 
  
  ExamineKeyboard()  
  
  If KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf 
  
  
  ;
  ; On pick sur notre plan invisible & on récupère les coordonées 
  ; du point de picking & on oriente nos yeux , plus le plan est près 
  ; plus les yeux "louche" quand la souris est entre les 2.
  ;
  If MouseRayCast(camera,WindowMouseX(window),WindowMouseY(window),$0001)
    lookAtX.f = PickX()
    lookAtY.f = PickY()
    lookAtZ.f = PickZ()
    EntityLookAt(left_eye,  lookAtX, lookAtY, lookAtZ)
    EntityLookAt(right_eye, lookAtX, lookAtY, lookAtZ)
  EndIf 
  
  
  ClearScreen(0)
  RenderWorld()
  FlipBuffers()
  Delay(1)
Wend 
tu devrais voir les yeux avec une sorte de fog rouge, regarde ligne 56

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 14:24
par Ar-S
Ou est-ce que l'on gère le fait que la rotation des yeux ne soit pas plus prononcée lorsque l'on bouge le curseur. (par exemple si on place le curseur entre les yeux, comment se fait il qu'ils ne "louchent" pas plus).

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 14:41
par G-Rom
le plan invisible , rapproche le des yeux ( à -5 par exemple ) les yeux loucherons plus.

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 16:18
par Mesa
J'ai un écran tout blanc.

Si je commente la ligne 69
plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001)

et que je change le masque en ligne 93
If MouseRayCast(camera,WindowMouseX(window),WindowMouseY(window),$0010)

ça marche (je pense), à condition que la souris soit sur les yeux.

A la ligne 56, le 128 remplacé par un 0 ne change rien.

M.

Re: Picking sur matérial invisible

Publié : mer. 26/juin/2013 20:20
par G-Rom
Carte graphique pourrie ou pilote pas à jour. :mrgreen: