Source cable car engine

I am creating a 3D graphics engine, and one of the requirements is ropes that behave like in a Valve source engine.

Thus, in the source engine, the rope section is an ATV that rotates along its axis of direction to the camera, so if the section of the rope is in the + Z direction, it will rotate along the Z axis, so that the face refers to the center position of the camera.

At the moment I have certain sections of the ropes, so I can have a good curved rope, but now I'm trying to build a matrix that will rotate it along the direction vector.

I already have a matrix for rendering billboards based on this poster: Building a matrix of billboards And at the moment I'm trying to redo it so that the Right, Up, Forward vector matches the direction vector of the rope segment.

My rope consists of several sections, each section is a rectangle consisting of two triangles, as I said above, I can get the position and sections perfectly, it rotates towards the camera, which causes me a lot of problems.

This is in OpenGL ES2 and is written in C.

I studied the Doom 3 ray rendering code in Model_beam.cpp, the method used there is to calculate the offset based on the normals, and not to use the matrices, so I created a similar method in my C code and its kinds of work, at least It works as much as I need now.

So, for those who are also trying to figure it out, use the cross product of the middle of the rope against the position of the camera, normalize this, and then multiply it by how wide you want the rope to be, then when building vertices we shift each vertex to + or - direction of the resulting vector.

Further help would be great, although this is not perfect!

thanks

+6
source share
1 answer

Give up on fooobar.com/questions/852357 / ... It refers to the lighthouse3d tutorial, which is pretty good to read. Here are the highlights of the technique:

void billboardCylindricalBegin( float camX, float camY, float camZ, float objPosX, float objPosY, float objPosZ) { float lookAt[3],objToCamProj[3],upAux[3]; float modelview[16],angleCosine; glPushMatrix(); // objToCamProj is the vector in world coordinates from the // local origin to the camera projected in the XZ plane objToCamProj[0] = camX - objPosX ; objToCamProj[1] = 0; objToCamProj[2] = camZ - objPosZ ; // This is the original lookAt vector for the object // in world coordinates lookAt[0] = 0; lookAt[1] = 0; lookAt[2] = 1; // normalize both vectors to get the cosine directly afterwards mathsNormalize(objToCamProj); // easy fix to determine wether the angle is negative or positive // for positive angles upAux will be a vector pointing in the // positive y direction, otherwise upAux will point downwards // effectively reversing the rotation. mathsCrossProduct(upAux,lookAt,objToCamProj); // compute the angle angleCosine = mathsInnerProduct(lookAt,objToCamProj); // perform the rotation. The if statement is used for stability reasons // if the lookAt and objToCamProj vectors are too close together then // |angleCosine| could be bigger than 1 due to lack of precision if ((angleCosine < 0.99990) && (angleCosine > -0.9999)) glRotatef(acos(angleCosine)*180/3.14,upAux[0], upAux[1], upAux[2]); } 
+1
source

All Articles