=================================================================== RCS file: /home/cvs/OpenXM/src/cfep/MyOpenGLView.m,v retrieving revision 1.1.1.1 retrieving revision 1.7 diff -u -p -r1.1.1.1 -r1.7 --- OpenXM/src/cfep/MyOpenGLView.m 2006/03/03 23:31:12 1.1.1.1 +++ OpenXM/src/cfep/MyOpenGLView.m 2018/10/18 04:59:45 1.7 @@ -6,9 +6,17 @@ // Copyright 2006 OpenXM.org. All rights reserved. // +#import +#import +#import +#import + #import "MyOpenGLView.h" +#import "MyOpenGLController.h" #include "mygl.h" + + @implementation MyOpenGLView -(id) initWithFrame: (NSRect) frame { NSLog(@"initWithFrame\n"); @@ -20,7 +28,7 @@ yeye = 0.0; zeye = 2.0; initGl = 1; - + myfont = [ NSFont systemFontOfSize: 10]; [super initWithFrame: frame]; if (self) { NSOpenGLPixelFormatAttribute attributes[]={ @@ -36,15 +44,18 @@ return self; } +-(void) showEyePos {[[MyOpenGLController getOglWindow: gid] showEyeX: xeye Y: yeye Z: zeye];} -(IBAction) setXeye: (id) sender { xeye=([sender floatValue]-50)*0.1; initGl = 1; NSLog(@"xeye=%f\n",xeye); + [self showEyePos]; [self setNeedsDisplay: YES]; } -(IBAction) setYeye: (id) sender { float y; y=([sender floatValue]-50)*0.1; initGl = 1; yeye=y; + [self showEyePos]; //NSLog(@"yeye=%f\n",yeye); [self setNeedsDisplay: YES]; } @@ -52,6 +63,7 @@ float z; z=([sender floatValue]-50)*0.1+2.0; initGl = 1; zeye=z; + [self showEyePos]; //NSLog(@"zeye=%f\n",zeye); [self setNeedsDisplay: YES]; } @@ -67,12 +79,16 @@ initGl=1; [self setNeedsDisplay: YES]; } +-(void) setGid: (int) p{ + gid = p; +} -(void) initGL { // Initialization codes are here. glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); [self drawOglInitComm]; } +-(void) setInitGL: (id) sender { initGl = 1; } // It was for a test. -(void) drawRectSimple: (NSRect) rect withColor: (double) c { glClearColor(1.0,1.0,1.0,1.0); @@ -106,11 +122,43 @@ if ([oc isEndGroup] == YES) oglCommSize=[oglComm count]; } if ([oc getOpCode] == CFEPglib_flush) [self setNeedsDisplay: YES]; + else if ([oc getOpCode] == CFEPglFlush) [self setNeedsDisplay: YES]; // If oc is glib_flush, then call drawRect. (Generate an event.) // Calling [self drawOglComm] directly is not safe, because the window might not be ready. } } +-(NSMutableArray *)getListOfOglComm { return oglComm; } +-(NSMutableArray *)getListOfOglInitComm { return oglInitComm; } +-(int) getOglCommSize { return oglCommSize; } +-(int) getOglInitCommSize { return oglInitCommSize; } +-(int) countOfOglComm { return [oglComm count]; } +-(int) countOfOglInitComm { return [oglInitComm count];} +-(int) removeLastOfOglComm { if ([oglComm count]>0) [oglComm removeLastObject]; [self updateOglCommSize]; return [self countOfOglComm];} +-(int) removeLastOfOglInitComm {if ([oglInitComm count]>0) [oglInitComm removeLastObject]; [self updateOglInitCommSize]; return [self countOfOglInitComm];} +-(int) removeAllOfOglComm { if ([oglComm count]>0) [oglComm removeAllObjects]; oglCommSize = 0; return 0; } +-(int) removeAllOfOglInitComm {if ([oglInitComm count]>0) [oglInitComm removeAllObjects]; oglInitCommSize = 0; return 0; } +-(void) updateOglCommSize { + int n,i; + MyOpenGLCommand *cc; + n = [oglComm count]; + for (i=n-1; i>=0; i--) { + cc = [oglComm objectAtIndex: i]; + if ([cc isEndGroup]) { oglCommSize = i+1; return ; } + } + oglCommSize = 0; +} +-(void) updateOglInitCommSize { + int n,i; + MyOpenGLCommand *cc; + n = [oglInitComm count]; + for (i=n-1; i>=0; i--) { + cc = [oglInitComm objectAtIndex: i]; + if ([cc isEndGroup]) { oglInitCommSize = i+1; return ; } + } + oglInitCommSize = 0; +} + -(void) drawOglInitComm { int i,n; MyOpenGLCommand *gc; @@ -130,7 +178,9 @@ @synchronized(self) { if ([oc isEndGroup] == YES) oglInitCommSize=[oglInitComm count]; } - if ([oc getOpCode] == CFEPglib_flush) { initGl = 1; [self setNeedsDisplay: YES]; } + initGl = 1; + if ([oc getOpCode] == CFEPglib_flush) { [self setNeedsDisplay: YES]; } + else if ([oc getOpCode] == CFEPglFlush) [self setNeedsDisplay: YES]; } } @@ -146,26 +196,50 @@ ii = [gc getI4]; x = v[0]; y = v[1]; z = v[2]; c = v[3]; p = ii[0]; q=ii[1]; r=ii[2]; s=ii[3]; - // NSLog(@"opCode=%d, (x,y,z,c)=(%f,%f,%f,%f), (p,q,r,s)=(%d,%d,%d,%d)\n",op,x,y,z,c,p,q,r,s); +// NSLog(@"opCode=%d, (x,y,z,c)=(%f,%f,%f,%f), (p,q,r,s)=(%d,%d,%d,%d)\n",op,x,y,z,c,p,q,r,s); switch(op) { case CFEPglBegin: glBegin(p); break; + case CFEPglClear: + glClear(p); break; + case CFEPglClearColor: + glClearColor(x,y,z,c); break; + case CFEPglClearDepth: + glClearDepth(x); break; case CFEPglColor4f: glColor4f(x,y,z,c); break; + case CFEPglDisable: + glDisable(p); break; + case CFEPglEnable: + glEnable(p); break; case CFEPglEnd: glEnd(); break; + case CFEPglFlush: + glFlush(); [self setInitGL: nil]; [self setNeedsDisplay: YES]; break; + case CFEPglLineStipple: + glLineStipple(p,q); break; + case CFEPglLineWidth: + glLineWidth(x); break; + case CFEPglNormal3f: + glNormal3f(x,y,z); break; + case CFEPglPointSize: + glPointSize(x); break; case CFEPglRectf: glRectf(x,y,z,c); break; case CFEPglVertex3f: glVertex3f(x,y,z); break; + case CFEPglVertex2f: + glVertex2f(x,y); break; case CFEPglib_line: glib_line(x,y,z,c,p); break; case CFEPglib_putpixel: glib_putpixel(x,y,p); break; case CFEPglib_flush: - [self setNeedsDisplay: YES]; break; + [self setInitGL: nil]; [self setNeedsDisplay: YES]; + // [[MyOpenGLController getOglWindow: gid] showCount]; + break; case CFEPglib3_bounding_box: glib3_bounding_box(x); break; @@ -193,7 +267,9 @@ -(void) glib3_std_scene0 { glib3_std_scene0(xeye,yeye,zeye); } - +-(void) mouseDown: (NSEvent *) theEvent { + NSLog(@"Mouse is down\n"); +} @end // Original glib functions