• 0

[C#] Kinect Skeleton Variable


Question

I am currently loading a Skeleton data from an XML File which contains all the joints' X, Y and Z.

I was hoping to store all the values into a Skeleton variable but I am unable to modify the value of the Joints's Position. Something like this...


Skeleton oneskele;
oneskele.Joints[JointType.AnkleLeft].Position.X = 100.0F;
[/CODE]

I got "Cannot modify the return value of 'Microsoft.Kinect.Joint.Position' because it is not a variable".

So is there any other way to modify its value?

Link to comment
https://www.neowin.net/forum/topic/1076807-c-kinect-skeleton-variable/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Microsoft.Kinect.Joint.Position is a property which returns a SkeletonPoint, a value type. Since it's a value type, returning it creates a copy of the original (rather than return a reference to the original as if SkeletonPoint was a reference type). You're trying to modify a temporary copy of a variable, which thankfully the compiler marks as illegal. To modify the variable, create a new one with the values you want and assign it, i.e.:


var newSkeletonPoint = oneskele.Joints[JointType.AnkleLeft].Position;
newSkeletonPoint.X = 100.0f;
oneskele.Joints[JointType.AnkleLeft].Position = newSkeletonPoint;
[/CODE]

  • 0

Microsoft.Kinect.Joint.Position is a property which returns a SkeletonPoint, a value type. Since it's a value type, returning it creates a copy of the original (rather than return a reference to the original as if SkeletonPoint was a reference type). You're trying to modify a temporary copy of a variable, which thankfully the compiler marks as illegal. To modify the variable, create a new one with the values you want and assign it, i.e.:


var newSkeletonPoint = oneskele.Joints[JointType.AnkleLeft].Position;
newSkeletonPoint.X = 100.0f;
oneskele.Joints[JointType.AnkleLeft].Position = newSkeletonPoint;
[/CODE]

I tried your coding but the same thing happens for me.

  • 0

Oops, Joint is also a value type. So, same logic, one level deeper:

var joint = skeleton.Joints[JointType.AnkleLeft];
var position = joint.Position;
position.X = 100;
joint.Position = position;
skeleton.Joints[JointType.AnkleLeft] = joint;[/CODE]

If Skeleton was also a value type then you'd need to do the same thing for Skeleton as well. Do you understand the idea?

I get the feeling the API is not really designed to be used in this way, but anyway, try it out.

This topic is now closed to further replies.