Commit 7964a2e9 authored by Antoine's avatar Antoine

Camera for PX and GU projections.

parent f5d88ce8
...@@ -10,6 +10,8 @@ import org.graphstream.ui.graphicGraph.GraphicNode ...@@ -10,6 +10,8 @@ import org.graphstream.ui.graphicGraph.GraphicNode
import org.graphstream.ui.graphicGraph.GraphicSprite import org.graphstream.ui.graphicGraph.GraphicSprite
import org.graphstream.ui.graphicGraph.GraphicElement import org.graphstream.ui.graphicGraph.GraphicElement
import org.sofa.opengl.MatrixStack import org.sofa.opengl.MatrixStack
import org.graphstream.ui.graphicGraph.stylesheet.Style
import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units
class HobgobelinCamera(graph:GraphicGraph) extends BaseCamera(graph) { class HobgobelinCamera(graph:GraphicGraph) extends BaseCamera(graph) {
//------------------------------------------------------------------------ //------------------------------------------------------------------------
...@@ -55,28 +57,108 @@ class HobgobelinCamera(graph:GraphicGraph) extends BaseCamera(graph) { ...@@ -55,28 +57,108 @@ class HobgobelinCamera(graph:GraphicGraph) extends BaseCamera(graph) {
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Commands // Commands
/** Push an orthographic view where units correspond to pixels. */
def pushPXView(x:Double, y:Double, width:Double, height:Double) { def pushPXView(x:Double, y:Double, width:Double, height:Double) {
setBounds
setPadding
metrics.setSurfaceViewport(x, y, width, height)
Tx.push Tx.push
Tx.push Tx.push
Tx.top.orthographic(0, width, 0, height, -10000, 10000) Tx.top.orthographic(0, width, 0, height, -10000, 10000)
xT.top.inverseOrthographic(0, width, 0, height, -10000, 10000) xT.top.inverseOrthographic(0, width, 0, height, -10000, 10000)
} }
/** Pop the PX view. */
def popPXView() { def popPXView() {
Tx.pop Tx.pop
xT.pop xT.pop
} }
/** Push an orthographic view where units correspond to graph units. */
def pushGUView(x:Double, y:Double, width:Double, height:Double) { def pushGUView(x:Double, y:Double, width:Double, height:Double) {
Tx.push
xT.push
setBounds setBounds
setPadding setPadding
metrics.setSurfaceViewport(x, y, width, height)
Tx.push
xT.push
if(autoFit)
pushAutoFitGUView()
else pushUserGUView()
} }
/** Pop the GU view. */
def popGUView() { def popGUView() {
Tx.pop Tx.pop
xT.pop xT.pop
} }
/** Push the Tx and xT matrices, execute the given code and pop these matrices. */
def pushpop(code: =>Unit) {
Tx.push
xT.push
code
xT.pop
xT.pop
}
protected def pushAutoFitGUView() {
setRatio
val padx = metrics.lengthToGu(padding, 0)
val pady = if(padding.size > 1) metrics.lengthToGu(padding, 1) else padx
val right = metrics.size.data(0)/2 + padx
val left = -right
val top = metrics.size.data(1)/2 + pady
val bottom = -top
zoom = 1
Tx.top.orthographic(left, right, bottom, top, -10000, 10000)
xT.top.inverseOrthographic(left, right, bottom, top, -10000, 10000)
metrics.loVisible.copy(metrics.lo)
metrics.hiVisible.copy(metrics.hi)
}
protected def pushUserGUView() {
}
// -------------------------------------------------------------------------
// Utility
/** Choose the least ratio, in order to be able to convert lengths. */
protected def setRatio() {
val padXgu = paddingXgu * 2
val padYgu = paddingYgu * 2
val padXpx = paddingXpx * 2
val padYpx = paddingYpx * 2
var sx = (metrics.surfaceViewport(0)-padXpx) / (metrics.size.data(0)+padXgu)
var sy = (metrics.surfaceViewport(1)-padYpx) / (metrics.size.data(1)+padYgu)
if(sx>sy) sx = sy else sy = sx
metrics.setRatioPx2Gu(sx)
}
protected def setCenter() {
var tx = metrics.lo.x + (metrics.size.data(0) / 2)
var ty = metrics.lo.y + (metrics.size.data(1) / 2)
center.set(tx, ty, 0)
}
protected def paddingXgu:Double =
if (padding.units == Units.GU && padding.size() > 0) padding.get(0) else 0
protected def paddingYgu:Double =
if (padding.units == Units.GU && padding.size() > 1) padding.get(1) else paddingXgu
protected def paddingXpx:Double =
if (padding.units == Units.PX && padding.size() > 0) padding.get(0) else 0
protected def paddingYpx:Double =
if (padding.units == Units.PX && padding.size() > 1) padding.get(1) else paddingXpx
} }
\ No newline at end of file
...@@ -193,6 +193,7 @@ class HobgobelinGraphRenderer extends GraphRendererBase with JoglGraphRenderer { ...@@ -193,6 +193,7 @@ class HobgobelinGraphRenderer extends GraphRendererBase with JoglGraphRenderer {
plainShader.use plainShader.use
plainShader.uniform("C", 1, 0, 0, 0.5f) plainShader.uniform("C", 1, 0, 0, 0.5f)
camera.Tx.translate(camera.getMetrics.surfaceViewport(2)/2, camera.getMetrics.surfaceViewport(3)/2, 0)
camera.Tx.rotate(90, 1, 0, 0) camera.Tx.rotate(90, 1, 0, 0)
plainShader.uniformMatrix("MVP", camera.Tx.top) plainShader.uniformMatrix("MVP", camera.Tx.top)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment