2012-09-27 21 views
7

Esto es para mi primer tema de gráficos en la universidad, y algunas partes de la implementación simplemente no me funcionan. Puedo hacer que las articulaciones dibujen correctamente, pero estoy tratando de escribir una función que ponga 'huesos' entre las articulaciones. En este punto, los huesos son solo cubos que se transforman en prismas rectangulares, en un momento posterior intentaré introducir los modelos adecuados de la licuadora o algo así.Crear un esqueleto completo en 3D con Kinect SDK

Mi problema es con las rotaciones. Después de aproximadamente 5 horas más o menos, mi compañero y yo tenemos un poco de trabajo, pero tan pronto como mueve los brazos o las piernas, los cubos se deforman y se ven extraños. Cualquier ayuda sería apreciada. Debajo está la función que intenta dibujar los huesos.

private void DrawBone(Skeleton skeleton, JointType jointType0, JointType jointType1) 
{ 
    Joint joint0 = skeleton.Joints[jointType0]; 
    Joint joint1 = skeleton.Joints[jointType1]; 

    // If we can't find either of these joints, exit 
    if (joint0.TrackingState == JointTrackingState.NotTracked || 
     joint1.TrackingState == JointTrackingState.NotTracked) 
    { 
     return; 
    } 

    // Don't draw if both points are inferred 
    if (joint0.TrackingState == JointTrackingState.Inferred && 
     joint1.TrackingState == JointTrackingState.Inferred) 
    { 
     return; 
    } 

    // We assume all drawn bones are inferred unless BOTH joints are tracked 
    if (joint0.TrackingState == JointTrackingState.Tracked && joint1.TrackingState == JointTrackingState.Tracked) 

     //jointvector(joint) takes a joint and returns a Vector2 with its position data, with the z invtred to work properly with directx11 
     Vector3 bonevector = Vector3.Subtract(jointVector(joint0), jointVector(joint1)); 
     //cubevector is supposed to describe the initial vector of a cube centred at (0,0,0) with a side length of 2. A fair amount of guesswork has gone into this bit. 
     Vector3 cubevector = new Vector3(0, 2, 0); 
     //midpoint of two joints 
     Vector3 transTest = Vector3.Divide(Vector3.Add(jointVector(joint0),jointVector(joint1)), 2); 
     //divide by two because our original cube has side length 2 
     float scaleFactor = Math.Abs(bonevector.Length()/cubevector.Length()); 

     //we haven't been taught quaternions in class or anything, but after a fair while searching for similar problems they seemed like the go-to option for rotations. 
     world = Matrix.Transformation(new Vector3(0, 0, 0), new Quaternion(0), new Vector3(0.05f, scaleFactor, 0.05f), new Vector3(0, 0, 0), new Quaternion(Vector3.Cross(cubevector, bonevector), (float)Math.Acos(Vector3.Dot(bonevector, cubevector))), transTest);  

     //view and proj are defined elsewhere and are working fine, it's just the world that is being lame   
     worldViewProj = world * view * proj; 
     worldViewProj.Transpose(); 
     sDXdata.context.UpdateSubresource(ref worldViewProj, sDXdata.constantBuffer); 
     //36 vertices of the cube (two triangles per face) defined elsewhere 
     sDXdata.context.Draw(36, 0); 
     return; 
+0

Hola Vince, ¿alguna vez lo hiciste funcionar? Estaría interesado en comprender cómo se muestra el modelo en 3D. –

Respuesta

3

Por orientaciones de hueso, marque:

skeleton.BoneOrientations[joint.JointType] 

que le dará una clase BoneOrientation

http://msdn.microsoft.com/en-us/library/microsoft.kinect.boneorientation.aspx

Desde allí se puede tener la rotación, ya sea como Quaternion/Matrix, ya sea en espacio mundial, o en el espacio óseo parental (para desollar)

También se utiliza:

new Quaternion(0) 

Este es un vector 0, no un cuaternión válida para la rotación, utilice:

Quaternion.Identity; 

que será (0,0,0,1)

1

Aunque esto fue preguntado hace un tiempo, por lo que vale, creo que también hay un error cuando se calcula el ángulo. Tiene:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector) 

creo que necesita:

(float)Math.Acos(Vector3.Dot(bonevector, cubevector)/(bonevector.Length() * 
cubevector.Length())) 

Here es un pequeño ejemplo de las matemáticas. También podría hacerlos vectores de la unidad, por lo que tienen una longitud de uno y no molestarse con la división:

(float)Math.Acos(Vector3.Dot(bonevector.Normalize(), cubevector.Normalize())) 

visita nuestra página MSDN para más información.

Cuestiones relacionadas