Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
c3799528
Commit
c3799528
authored
Apr 05, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mouse_to_ray function to get a ray from current mouse position
parent
60166d80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
+34
-4
panel.py
printrun/gl/panel.py
+34
-4
No files found.
printrun/gl/panel.py
View file @
c3799528
...
@@ -38,9 +38,9 @@ from pyglet.gl import glEnable, glDisable, GL_LIGHTING, glLightfv, \
...
@@ -38,9 +38,9 @@ from pyglet.gl import glEnable, glDisable, GL_LIGHTING, glLightfv, \
GL_MODELVIEW_MATRIX
,
GL_ONE_MINUS_SRC_ALPHA
,
glOrtho
,
\
GL_MODELVIEW_MATRIX
,
GL_ONE_MINUS_SRC_ALPHA
,
glOrtho
,
\
GL_PROJECTION
,
GL_PROJECTION_MATRIX
,
glScalef
,
\
GL_PROJECTION
,
GL_PROJECTION_MATRIX
,
glScalef
,
\
GL_SRC_ALPHA
,
glTranslatef
,
gluPerspective
,
gluUnProject
,
\
GL_SRC_ALPHA
,
glTranslatef
,
gluPerspective
,
gluUnProject
,
\
glViewport
,
GL_VIEWPORT
glViewport
,
GL_VIEWPORT
,
glPushMatrix
,
glPopMatrix
,
glMultMatrixd
from
pyglet
import
gl
from
pyglet
import
gl
from
.trackball
import
trackball
,
mulquat
from
.trackball
import
trackball
,
mulquat
,
build_rotmatrix
from
.libtatlin.actors
import
vec
from
.libtatlin.actors
import
vec
class
wxGLPanel
(
wx
.
Panel
):
class
wxGLPanel
(
wx
.
Panel
):
...
@@ -248,7 +248,19 @@ class wxGLPanel(wx.Panel):
...
@@ -248,7 +248,19 @@ class wxGLPanel(wx.Panel):
# ==========================================================================
# ==========================================================================
# Utils
# Utils
# ==========================================================================
# ==========================================================================
def
mouse_to_3d
(
self
,
x
,
y
,
z
=
1.0
):
def
get_modelview_mat
(
self
,
mult_rot
):
mvmat
=
(
GLdouble
*
16
)()
if
mult_rot
:
glPushMatrix
()
# Rotate according to trackball
glMultMatrixd
(
build_rotmatrix
(
self
.
basequat
))
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
mvmat
)
glPopMatrix
()
else
:
glGetDoublev
(
GL_MODELVIEW_MATRIX
,
mvmat
)
return
mvmat
def
mouse_to_3d
(
self
,
x
,
y
,
z
=
1.0
,
mult_rot
=
False
):
x
=
float
(
x
)
x
=
float
(
x
)
y
=
self
.
height
-
float
(
y
)
y
=
self
.
height
-
float
(
y
)
# The following could work if we were not initially scaling to zoom on
# The following could work if we were not initially scaling to zoom on
...
@@ -256,7 +268,7 @@ class wxGLPanel(wx.Panel):
...
@@ -256,7 +268,7 @@ class wxGLPanel(wx.Panel):
# if self.orthographic:
# if self.orthographic:
# return (x - self.width / 2, y - self.height / 2, 0)
# return (x - self.width / 2, y - self.height / 2, 0)
pmat
=
(
GLdouble
*
16
)()
pmat
=
(
GLdouble
*
16
)()
mvmat
=
(
GLdouble
*
16
)(
)
mvmat
=
self
.
get_modelview_mat
(
mult_rot
)
viewport
=
(
GLint
*
4
)()
viewport
=
(
GLint
*
4
)()
px
=
(
GLdouble
)()
px
=
(
GLdouble
)()
py
=
(
GLdouble
)()
py
=
(
GLdouble
)()
...
@@ -267,6 +279,24 @@ class wxGLPanel(wx.Panel):
...
@@ -267,6 +279,24 @@ class wxGLPanel(wx.Panel):
gluUnProject
(
x
,
y
,
z
,
mvmat
,
pmat
,
viewport
,
px
,
py
,
pz
)
gluUnProject
(
x
,
y
,
z
,
mvmat
,
pmat
,
viewport
,
px
,
py
,
pz
)
return
(
px
.
value
,
py
.
value
,
pz
.
value
)
return
(
px
.
value
,
py
.
value
,
pz
.
value
)
def
mouse_to_ray
(
self
,
x
,
y
,
mult_rot
=
False
):
x
=
float
(
x
)
y
=
self
.
height
-
float
(
y
)
pmat
=
(
GLdouble
*
16
)()
mvmat
=
(
GLdouble
*
16
)()
viewport
=
(
GLint
*
4
)()
px
=
(
GLdouble
)()
py
=
(
GLdouble
)()
pz
=
(
GLdouble
)()
glGetIntegerv
(
GL_VIEWPORT
,
viewport
)
glGetDoublev
(
GL_PROJECTION_MATRIX
,
pmat
)
mvmat
=
self
.
get_modelview_mat
(
mult_rot
)
gluUnProject
(
x
,
y
,
0
,
mvmat
,
pmat
,
viewport
,
px
,
py
,
pz
)
ray_far
=
(
px
.
value
,
py
.
value
,
pz
.
value
)
gluUnProject
(
x
,
y
,
1.
,
mvmat
,
pmat
,
viewport
,
px
,
py
,
pz
)
ray_near
=
(
px
.
value
,
py
.
value
,
pz
.
value
)
return
ray_near
,
ray_far
def
zoom
(
self
,
factor
,
to
=
None
):
def
zoom
(
self
,
factor
,
to
=
None
):
glMatrixMode
(
GL_MODELVIEW
)
glMatrixMode
(
GL_MODELVIEW
)
if
to
:
if
to
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment