Commits

Cliff Biffle committed 780397a

Added GL lighting.

Comments (0)

Files changed (3)

English.lproj/MainMenu.xib

 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
+			<integer value="296"/>
 			<integer value="372"/>
-			<integer value="296"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
 									<reference key="NSOnImage" ref="35465992"/>
 									<reference key="NSMixedImage" ref="502551668"/>
 								</object>
+								<object class="NSMenuItem" id="433488773">
+									<reference key="NSMenu" ref="466310130"/>
+									<string key="NSTitle">Use Lighting</string>
+									<string key="NSKeyEquiv">l</string>
+									<int key="NSKeyEquivModMask">1048576</int>
+									<int key="NSMnemonicLoc">2147483647</int>
+									<reference key="NSOnImage" ref="35465992"/>
+									<reference key="NSMixedImage" ref="502551668"/>
+								</object>
 								<object class="NSMenuItem" id="851891320">
 									<reference key="NSMenu" ref="466310130"/>
 									<bool key="NSIsDisabled">YES</bool>
 					</object>
 					<int key="connectionID">551</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBActionConnection" key="connection">
+						<string key="label">toggleLighting:</string>
+						<reference key="source" ref="1014"/>
+						<reference key="destination" ref="433488773"/>
+					</object>
+					<int key="connectionID">553</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
 							<reference ref="578250298"/>
 							<reference ref="1068619292"/>
 							<reference ref="406940919"/>
+							<reference ref="433488773"/>
 						</object>
 						<reference key="parent" ref="586577488"/>
 					</object>
 						<reference key="object" ref="406940919"/>
 						<reference key="parent" ref="466310130"/>
 					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">552</int>
+						<reference key="object" ref="433488773"/>
+						<reference key="parent" ref="466310130"/>
+					</object>
 				</object>
 			</object>
 			<object class="NSMutableDictionary" key="flattenedProperties">
 					<string>541.IBPluginDependency</string>
 					<string>542.IBPluginDependency</string>
 					<string>550.IBPluginDependency</string>
+					<string>552.IBPluginDependency</string>
 					<string>56.IBPluginDependency</string>
 					<string>56.ImportedFromIB2</string>
 					<string>57.IBEditorWindowLastContentRect</string>
 					<string>{74, 862}</string>
 					<string>{{6, 978}, {478, 20}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
-					<string>{{657, 623}, {231, 213}}</string>
+					<string>{{657, 603}, {231, 233}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>{{475, 832}, {234, 43}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<integer value="1"/>
 					<string>{{286, 129}, {275, 183}}</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">551</int>
+			<int key="maxID">553</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 							<string>selectMeshedTriRenderer:</string>
 							<string>selectPointCloudRenderer:</string>
 							<string>toggleDepthFieldUpdates:</string>
+							<string>toggleLighting:</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<string>id</string>
 							<string>id</string>
 							<string>id</string>
+							<string>id</string>
 						</object>
 					</object>
 					<object class="NSMutableDictionary" key="actionInfosByName">
 							<string>selectMeshedTriRenderer:</string>
 							<string>selectPointCloudRenderer:</string>
 							<string>toggleDepthFieldUpdates:</string>
+							<string>toggleLighting:</string>
 						</object>
 						<object class="NSMutableArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 								<string key="name">toggleDepthFieldUpdates:</string>
 								<string key="candidateClassName">id</string>
 							</object>
+							<object class="IBActionInfo">
+								<string key="name">toggleLighting:</string>
+								<string key="candidateClassName">id</string>
+							</object>
 						</object>
 					</object>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
   
   GLfloat depthTable[2048];
   
-  BOOL frozen;
   void (^renderAction)();
 }
 
 @property(retain) NSMutableData *rawDepthField;
 @property(copy) void (^renderAction)();
 @property(assign) BOOL frozen;
+@property(assign) BOOL lightsOn;
 
 - (void) depthFieldUpdated: (KFKinect *)kinect;
 
 - (IBAction) selectMeshedTriRenderer: sender;
 
 - (IBAction) toggleDepthFieldUpdates: sender;
+- (IBAction) toggleLighting: sender;
 @end
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_CULL_FACE);
   glFrontFace(GL_CCW);
-  glShadeModel(GL_SMOOTH);
+  glShadeModel(GL_FLAT);
+  
+  GLfloat lightPos[4] = { 0, 0, 1, 1 };
+  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+  
+  GLfloat ambientColor[4] = { 0, 0, 0, 1 };
+  glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
+  
+  GLfloat diffuseColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
+  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
+  
+  GLfloat globalAmbient[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
+  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);
+  
+  glEnable(GL_LIGHTING);
+  glEnable(GL_LIGHT0);
+  
+  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+  glEnable(GL_COLOR_MATERIAL);
   
   glPolygonOffset(1.0, 1.0);  // I believe this lets edge lines show on top of polys.
   glClearColor(0, 0, 0, 0);
   [sender setState: self.frozen? NSOnState : NSOffState];
 }
 
+- (IBAction) toggleLighting: sender {
+  self.lightsOn = !self.lightsOn;
+  [sender setState: self.lightsOn? NSOnState : NSOffState];
+  [[self openGLContext] makeCurrentContext];
+  if (self.lightsOn) {
+    glEnable(GL_LIGHTING);
+  } else {
+    glDisable(GL_LIGHTING);
+  }
+  [self setNeedsDisplay: YES];
+}
+
 #pragma mark --- Properties ---
 
 @synthesize rawDepthField;
 @synthesize renderAction;
 @synthesize frozen;
+@synthesize lightsOn;
 
 @end
 
             camera.target.x, camera.target.y, camera.target.z,
             camera.up.x, camera.up.y, camera.up.z);
   
+  GLfloat lightPos[4] = { camera.pos.x, camera.pos.y, 1, 0 };
+  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+
   glRotatef(trackballRotation[0], trackballRotation[1], trackballRotation[2], trackballRotation[3]);
   glRotatef(worldRotation[0], worldRotation[1], worldRotation[2], worldRotation[3]);
   glRotatef(spin, 0, 1, 0);
   const GLfloat *depths = [linearDepthField bytes];
   
   glBegin(GL_QUADS);
+  glNormal3f(0, 0, 1);
   for (int y = 0; y < 480; y++) {
     for (int x = 0; x < 640; x++) {
       GLfloat d1 = depths[y * 640 + x];