Blender(jusqu'à 2.49)
Python : 
Pointeur souris en opengl
(mise à jour :24/08/2005)
    Début   Index
précédentScript Python
Script python Suivant

 
  • Repérer la  position de la souris 
    • Draw.MOUSEX, Draw.MOUSEY
      Blender.Window.GetMouseCoords() 
  • Mémoriser la position de la osuris 
    • Déposer un carré
  • Repérer les dimensions de la fenêtre python active
    • glGetFloatv(GL_SCISSOR_BOX, size)
  • Tracer des lignes et  des polygones en openGL

Le script
 

import Blender
from Blender.Draw import *
from Blender.BGL import *

mouse_xr=1
mouse_yr=1

POS=[0,0]
XY=[0,0]

size=[]

def draw():
    global mouse_xr,size
    global mouse_yr,POS,XY

    size=Buffer(GL_FLOAT, 4)
    glGetFloatv(GL_SCISSOR_BOX, size)
    size= [int(s) for s in size]

    mouse_x=mouse_xr-size[0]
    mouse_y=mouse_yr-size[1]

    print POS
    print 'XY',XY
    print XY[0]-size[0], XY[1]-size[1]

    glClear(GL_COLOR_BUFFER_BIT)
 

    X=60
    Y=60
    glBegin(GL_POLYGON)
    glVertex2i(POS[0], POS[1])
    glVertex2i(POS[0]+X, POS[1])
    glVertex2i(POS[0]+X, POS[1]+Y)
    glVertex2i(POS[0], POS[1]+Y)
    glVertex2i(POS[0], POS[1])
    glEnd()

    glBegin(GL_LINES)
    glVertex2i(mouse_x-10, 10)
    glVertex2i(mouse_x,     2)
    glVertex2i(mouse_x+10, 10)
    glVertex2i(mouse_x,     2)
    glVertex2i(mouse_x,     2)
    glVertex2i(mouse_x,     25)
    glEnd()

    glBegin(GL_LINES)
    glVertex2i(10,mouse_y-10)
    glVertex2i(2,mouse_y)
    glVertex2i(10,mouse_y+10)
    glVertex2i(2,mouse_y)
    glVertex2i(2,mouse_y)
    glVertex2i(25,mouse_y)
    glEnd()
 

def event(evt, val):
    global mouse_xr
    global mouse_yr, POS, XY,size
    if (evt== QKEY): Exit()
    elif (evt == MOUSEX): mouse_xr = val
    elif (evt == MOUSEY): mouse_yr = val
    elif (evt == MIDDLEMOUSE and not val):
        XY=Blender.Window.GetMouseCoords()[:]
        POS[0]=mouse_xr-size[0]
        POS[1]=mouse_yr-size[1]

    Redraw()

def bevent(evt):
    Redraw()

Blender.Draw.Register(draw, event, bevent)
 


 
précédentScript Python
Script python Suivant
Vers le  Haut de page

Les questions concernant cette page  peuvent être posées sur  :
 news://news.zoo-logique.org/3D.Blender

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube