"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Graphics/TriD/OpenGLQ/openglq.pd" between
PDL-2.077.tar.gz and PDL-2.078.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

openglq.pd  (PDL-2.077):openglq.pd  (PDL-2.078)
skipping to change at line 37 skipping to change at line 37
the copyright notice should be included in the file. the copyright notice should be included in the file.
=cut =cut
EOD EOD
pp_addhdr(' pp_addhdr('
#ifdef HAVE_AGL_GLUT #ifdef HAVE_AGL_GLUT
#include <OpenGL/gl.h> #include <OpenGL/gl.h>
#include <OpenGL/glu.h> #include <OpenGL/glu.h>
#include <OpenGL/glut.h>
#else #else
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
#endif #endif
/* #include <GL/glx.h> */ /* #include <GL/glx.h> */
'); ');
my @internal = (Doc => 'internal', NoPthreading => 1); my @internal = (Doc => 'internal', NoPthreading => 1);
pp_def( pp_def(
'line_3x_3c', 'gl_spheres',
GenericTypes => $F, GenericTypes => $F,
Pars => 'coords(tri=3,n); colors(tri,n);', Pars => 'coords(tri=3,n);',
Code => ' OtherPars => 'double radius; int slices; int stacks;',
glBegin(GL_LINE_STRIP); Code => '
loop(n) %{ float oldcoord0 = 0.0, oldcoord1 = 0.0, oldcoord2 = 0.0;
glColor3f( glPushMatrix();
$colors(tri => 0), loop(n) %{
$colors(tri => 1), glTranslatef(
$colors(tri => 2) $coords(tri=>0) - oldcoord0,
); $coords(tri=>1) - oldcoord1,
glVertex3f( $coords(tri=>2) - oldcoord2
$coords(tri => 0), );
$coords(tri => 1), glutSolidSphere($COMP(radius), $COMP(slices), $COMP(stacks));
$coords(tri => 2) oldcoord0 = $coords(tri=>0), oldcoord1 = $coords(tri=>1), oldcoord2 = $coo
); rds(tri=>2);
%} %}
glEnd(); glPopMatrix();
', ',
@internal @internal
); );
sub TRI { my $par = join '', @_; join ',', map "$par(tri => $_)", 0..2 } sub TRI { my $par = join '', @_; join ',', map "$par(tri => $_)", 0..2 }
sub make_tri { shift."(".TRI(@_).");\n" } sub make_tri { shift()."(".TRI(@_).");\n" }
sub COLOR { make_tri("glColor3f",'$colors',@_) } sub COLOR { make_tri("glColor3f",'$colors',@_) }
sub VERTEX { make_tri("glVertex3f",'$coords',@_) } sub VERTEX { make_tri("glVertex3f",'$coords',@_) }
sub NORMAL { make_tri("glNormal3f",'$norm',@_) } sub NORMAL { make_tri("glNormal3f",'$norm',@_) }
sub RPOS { make_tri("glRasterPos3f",'$coords',@_) } sub RPOS { make_tri("glRasterPos3f",'$coords',@_) }
sub ADCOLOR { " sub ADCOLOR { "
{ {
GLfloat ad[] = { ".TRI('$colors'.$_[0]).",1.0 }; GLfloat ad[] = { ".TRI('$colors'.$_[0]).",1.0 };
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE, ad); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE, ad);
} }
" } " }
sub make_func { sub make_func {
my ($name) = @_; my ($name) = @_;
for (['_col', ' colors(tri,n);', COLOR().VERTEX()], ['_nc', '', VERTEX()]) { for (['_col', ' colors(tri,n);', COLOR().VERTEX()], ['_nc', '', VERTEX()]) {
pp_def(lc($name).$_->[0], pp_def(lc($name).$_->[0],
GenericTypes => $F, GenericTypes => $F,
Pars => 'coords(tri=3,n);'.$_->[1], Pars => 'coords(tri=3,n);'.$_->[1],
Code => ' Code => '
skipping to change at line 104 skipping to change at line 106
); );
} }
} }
make_func($_) for qw(gl_line_strip gl_lines gl_points); make_func($_) for qw(gl_line_strip gl_lines gl_points);
pp_def( pp_def(
'gl_texts', 'gl_texts',
GenericTypes => $F, GenericTypes => $F,
Pars => 'coords(tri,x); ', Pars => 'coords(tri,x); ',
OtherPars => 'int base; SV *arr', OtherPars => 'int in_glut; IV base; SV *arr',
Code => ' Code => '
SV *sv = $COMP(arr); SV *sv = $COMP(arr);
AV *arr;
if(!(SvROK(sv) && SvTYPE(SvRV(sv))==SVt_PVAV)) { if(!(SvROK(sv) && SvTYPE(SvRV(sv))==SVt_PVAV)) {
$CROAK("gl_texts requires an array ref"); $CROAK("gl_texts requires an array ref");
} }
arr = (AV *)SvRV(sv); AV *arr = (AV *)SvRV(sv);
if ( !$COMP(in_glut) ) {
glPushAttrib(GL_LIST_BIT); glPushAttrib(GL_LIST_BIT);
glListBase($COMP(base)); glListBase($COMP(base));
}
loop(x) %{ loop(x) %{
SV *elem = *(av_fetch(arr, x, 0)); SV *elem = *(av_fetch(arr, x, 0));
if(elem) { if (!elem) continue;
char *str = SvPV_nolen(elem); char *str = SvPV_nolen(elem);
'.RPOS().' '.RPOS().'
if ( $COMP(in_glut) )
glutBitmapString((void *)$COMP(base), str);
else
glCallLists(strlen(str),GL_UNSIGNED_BYTE, glCallLists(strlen(str),GL_UNSIGNED_BYTE,
(GLubyte*)str); (GLubyte*)str);
}
%} %}
if ( !$COMP(in_glut) )
glPopAttrib(); glPopAttrib();
', ',
@internal @internal
); );
for my $m ( for my $m (
{Suf => '_mat', {Suf => '_mat',
Func => \&ADCOLOR}, Func => \&ADCOLOR},
{Suf => '', {Suf => '',
Func => \&COLOR}, Func => \&COLOR},
) { ) {
skipping to change at line 164 skipping to change at line 167
}, },
{Name => 'gl_triangles_wn', {Name => 'gl_triangles_wn',
NormalArgs => 'norma(tri); normb(tri); normc(tri);', NormalArgs => 'norma(tri); normb(tri); normc(tri);',
(map {("NormalCode".($_ eq 'A'?'':$_),NORMAL(lc $_))} ('A'..'C')), (map {("NormalCode".($_ eq 'A'?'':$_),NORMAL(lc $_))} ('A'..'C')),
}) { }) {
# This may be suboptimal but should still be fast enough.. # This may be suboptimal but should still be fast enough..
# We only do triangles with this. # We only do triangles with this.
pp_def( pp_def(
$_->{Name}.$m->{Suf}, $_->{Name}.$m->{Suf},
GenericTypes => $F, GenericTypes => $F,
Pars => 'coordsa(tri=3); coordsb(tri); Pars => 'coordsa(tri=3); coordsb(tri); coordsc(tri);'.
coordsc(tri);'.
($_->{NormalArgs}//''). ($_->{NormalArgs}//'').
'colorsa(tri); colorsb(tri); 'colorsa(tri); colorsb(tri); colorsc(tri);',
colorsc(tri);
',
Code => ' Code => '
float tmp1[3]; float tmp2[3]; float tmp1[3]; float tmp2[3];
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
broadcastloop %{'. broadcastloop %{'.
($_->{NormalCode}//'') ($_->{NormalCode}//'')
.&{$m->{Func}}("a").VERTEX("a"). .&{$m->{Func}}("a").VERTEX("a").
($_->{NormalCodeB}//'') ($_->{NormalCodeB}//'')
.&{$m->{Func}}("b").VERTEX("b"). .&{$m->{Func}}("b").VERTEX("b").
($_->{NormalCodeC}//'') ($_->{NormalCodeC}//'')
.&{$m->{Func}}("c").VERTEX("c").' .&{$m->{Func}}("c").VERTEX("c").'
%} %}
glEnd(); glEnd();
', ',
@internal @internal
); );
} }
} }
pp_def('gl_arrows', pp_def('gl_arrows',
Pars => 'coords(tri=3,n); int indsa(); int indsb();', Pars => 'coords(tri=3,n); indx indsa(); indx indsb();',
OtherPars => 'float headlen; float width;', OtherPars => 'float headlen; float width;',
Code => ' Code => '
float hl = $COMP(headlen); float hl = $COMP(headlen);
float w = $COMP(width); float w = $COMP(width);
float tmp2[3]; tmp2[0] = 0.000001; tmp2[1] = -0.0001; tmp2[2] = 1 float tmp2[3] = { 0.000001, -0.0001, 1 };
;
glBegin(GL_LINES);
broadcastloop %{ broadcastloop %{
int a = $indsa(); PDL_Indx a = $indsa(), b = $indsb();
int b = $indsb();
float tmp1[3]; float tmp1[3];
float norm[3]; float norm[3];
float norm2[3]; float norm2[3];
float normlen,origlen,norm2len; float normlen,origlen,norm2len;
tmp1[0] = $coords(tri => 0, n => a) - tmp1[0] = $coords(tri => 0, n => a) -
$coords(tri => 0, n => b); $coords(tri => 0, n => b);
tmp1[1] = $coords(tri => 1, n => a) - tmp1[1] = $coords(tri => 1, n => a) -
$coords(tri => 1, n => b); $coords(tri => 1, n => b);
tmp1[2] = $coords(tri => 2, n => a) - tmp1[2] = $coords(tri => 2, n => a) -
$coords(tri => 2, n => b); $coords(tri => 2, n => b);
float partback[3];
partback[0] = $coords(tri => 0, n => b) + hl*tmp1[0];
partback[1] = $coords(tri => 1, n => b) + hl*tmp1[1];
partback[2] = $coords(tri => 2, n => b) + hl*tmp1[2];
norm[0] = tmp1[1]*tmp2[2] - tmp2[1]*tmp1[2]; norm[0] = tmp1[1]*tmp2[2] - tmp2[1]*tmp1[2];
norm[1] = -(tmp1[0]*tmp2[2] - tmp2[0]*tmp1[2]); norm[1] = -(tmp1[0]*tmp2[2] - tmp2[0]*tmp1[2]);
norm[2] = tmp1[0]*tmp2[1] - tmp2[0]*tmp1[1]; norm[2] = tmp1[0]*tmp2[1] - tmp2[0]*tmp1[1];
norm2[0] = tmp1[1]*norm[2] - norm[1]*tmp1[2]; norm2[0] = tmp1[1]*norm[2] - norm[1]*tmp1[2];
norm2[1] = -(tmp1[0]*norm[2] - norm[0]*tmp1[2]); norm2[1] = -(tmp1[0]*norm[2] - norm[0]*tmp1[2]);
norm2[2] = tmp1[0]*norm[1] - norm[0]*tmp1[1]; norm2[2] = tmp1[0]*norm[1] - norm[0]*tmp1[1];
normlen = sqrt(norm[0] * norm[0] + normlen = sqrt(norm[0] * norm[0] +
norm[1] * norm[1] + norm[2] * norm[2]); norm[1] * norm[1] + norm[2] * norm[2]);
norm2len = sqrt(norm2[0] * norm2[0] + norm2len = sqrt(norm2[0] * norm2[0] +
norm2[1] * norm2[1] + norm2[2] * norm2[2]); norm2[1] * norm2[1] + norm2[2] * norm2[2]);
origlen = sqrt(tmp1[0] * tmp1[0] + origlen = sqrt(tmp1[0] * tmp1[0] +
tmp1[1] * tmp1[1] + tmp1[2] * tmp1[2]); tmp1[1] * tmp1[1] + tmp1[2] * tmp1[2]);
norm[0] *= w/normlen; norm[0] *= w/normlen;
norm[1] *= w/normlen; norm[1] *= w/normlen;
norm[2] *= w/normlen; norm[2] *= w/normlen;
norm2[0] *= w/norm2len; norm2[0] *= w/norm2len;
norm2[1] *= w/norm2len; norm2[1] *= w/norm2len;
norm2[2] *= w/norm2len; norm2[2] *= w/norm2len;
tmp1[0] /= origlen; tmp1[0] /= origlen;
tmp1[1] /= origlen; tmp1[1] /= origlen;
tmp1[2] /= origlen; tmp1[2] /= origlen;
glBegin(GL_LINES);
glVertex3d( $coords(tri => 0, n => a) , glVertex3d( $coords(tri => 0, n => a) ,
$coords(tri => 1, n => a) , $coords(tri => 1, n => a) ,
$coords(tri => 2, n => a) ); $coords(tri => 2, n => a) );
glVertex3d( $coords(tri => 0, n => b) , glVertex3d( $coords(tri => 0, n => b) ,
$coords(tri => 1, n => b) , $coords(tri => 1, n => b) ,
$coords(tri => 2, n => b) ); $coords(tri => 2, n => b) );
glEnd();
if(w!=0) { if(w!=0) {
glBegin(GL_TRIANGLES);
glVertex3d( $coords(tri => 0, n => b) , glVertex3d( $coords(tri => 0, n => b) ,
$coords(tri => 1, n => b) , $coords(tri => 1, n => b) ,
$coords(tri => 2, n => b) ); $coords(tri => 2, n => b) );
glVertex3d( $coords(tri => 0, n => b) + hl*tmp1[0] + norm glVertex3d( partback[0] + norm[0],
[0], partback[1] + norm[1],
$coords(tri => 1, n => b) + hl*tmp1[1] + norm partback[2] + norm[2]);
[1], glVertex3d( partback[0] + norm2[0],
$coords(tri => 2, n => b) + hl*tmp1[2] + norm partback[1] + norm2[1],
[2]); partback[2] + norm2[2]);
glVertex3d( $coords(tri => 0, n => b) , glVertex3d( $coords(tri => 0, n => b) ,
$coords(tri => 1, n => b) , $coords(tri => 1, n => b) ,
$coords(tri => 2, n => b) ); $coords(tri => 2, n => b) );
glVertex3d( $coords(tri => 0, n => b) + hl*tmp1[0] - norm glVertex3d( partback[0] - norm[0],
[0], partback[1] - norm[1],
$coords(tri => 1, n => b) + hl*tmp1[1] - norm partback[2] - norm[2]);
[1], glVertex3d( partback[0] - norm2[0],
$coords(tri => 2, n => b) + hl*tmp1[2] - norm partback[1] - norm2[1],
[2]); partback[2] - norm2[2]);
glVertex3d( $coords(tri => 0, n => b) , glVertex3d( $coords(tri => 0, n => b) ,
$coords(tri => 1, n => b) , $coords(tri => 1, n => b) ,
$coords(tri => 2, n => b) ); $coords(tri => 2, n => b) );
glVertex3d( $coords(tri => 0, n => b) + hl*tmp1[0] + norm glVertex3d( partback[0] + norm2[0],
2[0], partback[1] + norm2[1],
$coords(tri => 1, n => b) + hl*tmp1[1] + norm partback[2] + norm2[2]);
2[1], glVertex3d( partback[0] - norm[0],
$coords(tri => 2, n => b) + hl*tmp1[2] + norm partback[1] - norm[1],
2[2]); partback[2] - norm[2]);
glVertex3d( $coords(tri => 0, n => b) , glVertex3d( $coords(tri => 0, n => b) ,
$coords(tri => 1, n => b) , $coords(tri => 1, n => b) ,
$coords(tri => 2, n => b) ); $coords(tri => 2, n => b) );
glVertex3d( $coords(tri => 0, n => b) + hl*tmp1[0] - norm glVertex3d( partback[0] - norm2[0],
2[0], partback[1] - norm2[1],
$coords(tri => 1, n => b) + hl*tmp1[1] - norm partback[2] - norm2[2]);
2[1], glVertex3d( partback[0] + norm[0],
$coords(tri => 2, n => b) + hl*tmp1[2] - norm partback[1] + norm[1],
2[2]); partback[2] + norm[2]);
glEnd();
} }
%} %}
glEnd();
', ',
@internal @internal
); );
pp_done(); pp_done();
 End of changes. 27 change blocks. 
74 lines changed or deleted 76 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)