From bdf2568e247af858c4a1ca8004d97f13fe9b8cb0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 22 Sep 2007 17:01:48 +0000 Subject: [PATCH] Add projection functions Add enable/disable Blender exporter: Fix a deprecation warning --- mesh_export.py | 5 ++-- source/misc.cpp | 14 +++++++++-- source/misc.h | 2 ++ source/projection.cpp | 52 +++++++++++++++++++++++++++++++++++++++++ source/projection.h | 54 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 source/projection.cpp create mode 100644 source/projection.h diff --git a/mesh_export.py b/mesh_export.py index cdab35f3..6b50a4ec 100644 --- a/mesh_export.py +++ b/mesh_export.py @@ -9,6 +9,7 @@ Group: 'Export' import sys import math +import bpy import Blender class Edge: @@ -161,9 +162,9 @@ class Exporter: return result def export(self): - scene=Blender.Scene.GetCurrent() + scene=bpy.data.scenes.active - obj=scene.getActiveObject() + obj=scene.objects.active if obj.getType()!="Mesh": raise Exception, "Can only export Mesh data" diff --git a/source/misc.cpp b/source/misc.cpp index 67b2a142..9815383a 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -10,12 +10,22 @@ Distributed under the LGPL namespace Msp { namespace GL { +void enable(GLenum state) +{ + glEnable(state); +} + +void disable(GLenum state) +{ + glDisable(state); +} + void set(GLenum state, bool value) { if(value) - glEnable(state); + enable(state); else - glDisable(state); + disable(state); } } // namespace GL diff --git a/source/misc.h b/source/misc.h index 87690477..071875cd 100644 --- a/source/misc.h +++ b/source/misc.h @@ -13,6 +13,8 @@ Distributed under the LGPL namespace Msp { namespace GL { +void enable(GLenum); +void disable(GLenum); void set(GLenum, bool); } // namespace GL diff --git a/source/projection.cpp b/source/projection.cpp new file mode 100644 index 00000000..1b7fa61f --- /dev/null +++ b/source/projection.cpp @@ -0,0 +1,52 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include +#include "projection.h" + +namespace Msp { +namespace GL { + +void ortho(double left, double right, double bottom, double top, double near, double far) +{ + glOrtho(left, right, bottom, top, near, far); +} + +void ortho_centered(double width, double height) +{ + ortho(-width/2, width/2, -height/2, height/2, 0, 1); +} + +void ortho_bottomleft(double width, double height) +{ + ortho(0, width, 0, height, 0, 1); +} + +void ortho_topleft(double width, double height) +{ + ortho(0, width, -height, 0, 0, 1); +} + +void frustum(double left, double right, double bottom, double top, double near, double far) +{ + glFrustum(left, right, bottom, top, near, far); +} + +void frustum_centered(double width, double height, double near, double far) +{ + glFrustum(-width/2, width/2, -height/2, height/2, near, far); +} + +void perspective(double fov_y, double aspect, double near, double far) +{ + double hh=tan(fov_y*M_PI/360)*near; + frustum(-hh*aspect, hh*aspect, -hh, hh, near, far); +} + +} // namespace GL +} // namespace Msp diff --git a/source/projection.h b/source/projection.h new file mode 100644 index 00000000..d38aa336 --- /dev/null +++ b/source/projection.h @@ -0,0 +1,54 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef MSP_GL_PROJECTION_H_ +#define MSP_GL_PROJECTION_H_ + +namespace Msp { +namespace GL { + +/** +Sets up an orthogonal projection. +*/ +void ortho(double, double, double, double, double, double); + +/** +Sets up an orthogonal projection, with origin at the center of the screen. +*/ +void ortho_centered(double, double); + +/** +Sets up an orthogonal projection, with origin at the bottom left corner of the +screen. +*/ +void ortho_bottomleft(double, double); + +/** +Sets up an orthogonal projection, with origin at the top left corner of the +screen. The Y coordinate is reversed and grows downwards. +*/ +void ortho_topleft(double, double); + +/** +Sets up a perspective projection. +*/ +void frustum(double, double, double, double, double, double); + +/** +Sets up a perspective projection, with origin at the center of the screen. +*/ +void frustum_centered(double width, double height, double near, double far); + +/** +Sets up a centered perspective projection in a simple way. +*/ +void perspective(double fov_y, double aspect, double near, double far); + +} // namespace GL +} // namespace Msp + +#endif -- 2.45.2