2
* Pure Data Packet module.
3
* Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
#include "pdp_opengl.h"
25
#include "pdp_3dp_base.h"
27
typedef struct pdp_3d_push_struct
29
t_pdp_3dp_base x_base;
37
static void pdp_3d_push_process_right(t_pdp_3d_push *x)
39
int p = pdp_3dp_base_get_context_packet(x);
42
/* push one of the matrices */
43
glMatrixMode(x->x_matrix);
46
/* set default matrix to modelview */
47
if (!x->x_change_mode) glMatrixMode(GL_MODELVIEW);
51
static void pdp_3d_push_process_left(t_pdp_3d_push *x)
53
int p = pdp_3dp_base_get_context_packet(x);
56
/* restore the saved matrix */
57
glMatrixMode(x->x_matrix);
60
/* set default matrix back to modelview */
61
glMatrixMode(GL_MODELVIEW);
68
static void pdp_3d_mode_process_right(t_pdp_3d_push *x)
70
int p = pdp_3dp_base_get_context_packet(x);
73
/* change matrix mode */
74
glMatrixMode(x->x_matrix);
79
static void pdp_3d_mode_process_left(t_pdp_3d_push *x)
81
int p = pdp_3dp_base_get_context_packet(x);
84
/* restore default matrix to modelview */
85
glMatrixMode(GL_MODELVIEW);
91
static void pdp_3d_push_setmatrix(t_pdp_3d_push *x, t_symbol *s)
95
/* find out which matrix to push */
96
if (s == gensym("projection")) m = GL_PROJECTION;
97
else if (s == gensym("modelview")) m = GL_MODELVIEW;
98
else if (s == gensym("texture")) m = GL_TEXTURE;
99
else if (s == gensym("color")) m = GL_COLOR;
101
/* default is modelview */
102
else m = GL_MODELVIEW;
108
t_class *pdp_3d_push_class;
112
void pdp_3d_push_free(t_pdp_3d_push *x)
114
pdp_3dp_base_free(x);
117
void *pdp_3d_push_mode_new(t_symbol *s)
119
t_pdp_3d_push *x = (t_pdp_3d_push *)pd_new(pdp_3d_push_class);
122
pdp_3dp_base_init(x);
124
/* setup which matrix we are talking about */
125
pdp_3d_push_setmatrix(x, s);
127
x->x_change_mode = 0;
132
void *pdp_3d_push_new(t_symbol *s, t_floatarg f)
134
t_pdp_3d_push *x = (t_pdp_3d_push *)pdp_3d_push_mode_new(s);
136
/* create dpd outlets */
137
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_push_process_left, 0);
138
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_push_process_right, 0);
140
x->x_change_mode = (f != 0.0f);
146
void *pdp_3d_mode_new(t_symbol *s)
148
t_pdp_3d_push *x = (t_pdp_3d_push *)pdp_3d_push_mode_new(s);
150
/* create dpd outlets */
151
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_mode_process_left, 0);
152
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_mode_process_right, 0);
166
void pdp_3d_push_setup(void)
170
pdp_3d_push_class = class_new(gensym("3dp_push"), (t_newmethod)pdp_3d_push_new,
171
(t_method)pdp_3d_push_free, sizeof(t_pdp_3d_push), 0, A_DEFSYMBOL, A_NULL);
173
class_addcreator((t_newmethod)pdp_3d_mode_new, gensym("3dp_mode"), A_DEFSYMBOL, A_NULL);
175
pdp_3dp_base_setup(pdp_3d_push_class);