I tried to draw a cylinder between two points on the outer edge of a sphere using SceneKit. I already created a line between these two points using primitive geometry and openGL with the SCNRendering delegate, but now I need to create a cylinder between these two (well, not just two, but any two 3D vectors that sit on the surface of the sphere). I have been working on this for about 3 days right now, and I went through everything I could find when implementing Quaternions to make this happen, but since it is, I can't get it to work. Academic articles, scientific research and nothing, nothing works to rebuild a cylinder between two fixed points. I need an algorithm for this.
In any case, here is my latest code that does not work, but this is just a small fragment of almost 2k lines of code that I have worked with so far without the expected result. I know that I can move on to something more advanced, for example, create my own SCNProgram and / or SCNRenderer, so that I can then access the complexities of GLSL, OpenGL and Metal, but this looks like it should be possible with Scenekit and conversion between the GLKit vector structures in the SCNVector and from structures from it, but so far this is not possible:
code:
The following code processes the coordinates of longitude and latitude and projects them onto the surface of a 3D sphere. These coordinates are returned through the proprietary function that I built, where I got the SCNVector3 coordinates {x, y, z}, which are accurately displayed on my 3D sphere. I draw a line between two sets of longitude and latitude coordinates, where the lines that are drawn using primitives make their way through the center of the sphere. So, as I mentioned above, I need the same functionality, but with cylinders and not with lines (by the way, the longitude and latitude coordinates listed here are fictitious, they are randomly generated, but both fall to the surface of the Earth).
drawLine = [self lat1:37.76830 lon1:-30.40096 height1:tall lat2:3.97620 lon2:63.73095 height2:tall]; float cylHeight = GLKVector3Distance(SCNVector3ToGLKVector3(cooridnateSetOne.position), SCNVector3ToGLKVector3(coordinateSetTwo.position)); SCNCylinder * cylTest = [SCNCylinder cylinderWithRadius:0.2 height:cylHeight]; SCNNode * test = [SCNNode nodeWithGeometry:cylTest]; SCNMaterial *material = [SCNMaterial material]; [[material diffuse] setContents:[SKColor whiteColor]]; material.diffuse.intensity = 60; material.emission.contents = [SKColor whiteColor]; material.lightingModelName = SCNLightingModelConstant; [cylTest setMaterials:@[material]]; GLKVector3 u = SCNVector3ToGLKVector3(cooridnateSetOne.position); GLKVector3 v = SCNVector3ToGLKVector3(cooridnateSetTwo.position); GLKVector3 w = GLKVector3CrossProduct(u, v); GLKQuaternion q = GLKQuaternionMakeWithAngleAndVector3Axis(GLKVector3DotProduct(u,v), GLKVector3Normalize(w)); qw += GLKQuaternionLength(q); q = GLKQuaternionNormalize(q); SCNVector4 final = SCNVector4FromGLKVector4(GLKVector4Make(qx, qy, qz, qw)); test.orientation = final;
Another code I tried includes the same method, in fact, I even built my own math libraries SCNVector3 and SCNVector4 in Objective-C to see if my math methods produce different values โโthan using math GLKit, but I I get the same results with both methods. Any help would be awesome, but for now I don't want to jump into something more complicated than SceneKit. I will not dive into Metal and / or OpenGL for another month or two. Thanks!
EDIT:
The variables "cooridnateSetOne" and "cooridnateSetTwo" are SCNNodes, which are created by another function that forces the primitive linear geometry in this node, and then returns it to the SCNScene subclass implementation.