I am very new to SceneKit and am starting a test application. I have a small cube that moves. I would like to add an axis (X, Y, Z). I created them like that.
SCNVector3 xPositions[] = {SCNVector3Make(-50, 0, 0), SCNVector3Make(50, 0, 0)};
int indicies[] = {0, 1};
NSData *indexData = [NSData dataWithBytes:indicies length:sizeof(indicies)];
SCNGeometrySource *xSource = [SCNGeometrySource geometrySourceWithVertices:xPositions count:2];
SCNGeometryElement *xElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *xAxis = [SCNGeometry geometryWithSources:@[xSource] elements:@[xElement]];
SCNNode *xNode = [SCNNode nodeWithGeometry:xAxis];
[self.gameView.scene.rootNode addChildNode:xNode];
SCNVector3 yPositions[] = {SCNVector3Make(0, -50, 0), SCNVector3Make(0, 50, 0)};
SCNGeometrySource *ySource = [SCNGeometrySource geometrySourceWithVertices:yPositions count:2];
SCNGeometryElement *yElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *yAxis = [SCNGeometry geometryWithSources:@[ySource] elements:@[yElement]];
SCNNode *yNode = [SCNNode nodeWithGeometry:yAxis];
[self.gameView.scene.rootNode addChildNode:yNode];
SCNVector3 zPositions[] = {SCNVector3Make(0, 0, -50), SCNVector3Make(0, 0, 50)};
SCNGeometrySource *zSource = [SCNGeometrySource geometrySourceWithVertices:zPositions count:2];
SCNGeometryElement *zElement = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeLine primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *zAxis = [SCNGeometry geometryWithSources:@[zSource] elements:@[zElement]];
SCNNode *zNode = [SCNNode nodeWithGeometry:zAxis];
[self.gameView.scene.rootNode addChildNode:zNode];
My problem is that I would like to change the color on them so that I can determine what is. Is there a way I can do this, or do I need to create my lines differently? I am making a mac application, not an iOS application, just fyi. Also, I know about code repetition, I'm just tired, and I will fix it.
source
share