J
Jason Bell
Every example of properties I've seen have used simple types such as
integers and strings.
Here's the scenario I'm trying to work out (3D graphics programming):
I have a class called Matrix16f, containing 16 floats that define the
matrix, which in turn defines an object's position and orientation in 3D
space. As well I want it to have a "position" property, which is a 3D
vector that sets the Position values of the matrix.
public class Vector3f
{
public float x;
public float y;
public float z;
public void Set( float X, float Y, float Z )
{
x = X; y = Y; z = Z;
}
}
public class Matrix16f
{
private float Values[16];
public Vector3f Position
{
set
{
Values[12] = value.x;
Values[13] = value.y;
Values[14] = value.z;
}
}
}
So ideally I'd like to be able to do something like:
SomeMatrix.Position.z = 12.4f;
This doesn't work though: accessing the members of an object through a
property seems to have no effect. Instead you'd have to do something
like:
SomeVector.Set( 0.0f, 0.0f, 12.4f );
SomeMatrix.Position = SomeVector;
Which is obviously uglier. Any thoughts on how to do it using the first
approach?
integers and strings.
Here's the scenario I'm trying to work out (3D graphics programming):
I have a class called Matrix16f, containing 16 floats that define the
matrix, which in turn defines an object's position and orientation in 3D
space. As well I want it to have a "position" property, which is a 3D
vector that sets the Position values of the matrix.
public class Vector3f
{
public float x;
public float y;
public float z;
public void Set( float X, float Y, float Z )
{
x = X; y = Y; z = Z;
}
}
public class Matrix16f
{
private float Values[16];
public Vector3f Position
{
set
{
Values[12] = value.x;
Values[13] = value.y;
Values[14] = value.z;
}
}
}
So ideally I'd like to be able to do something like:
SomeMatrix.Position.z = 12.4f;
This doesn't work though: accessing the members of an object through a
property seems to have no effect. Instead you'd have to do something
like:
SomeVector.Set( 0.0f, 0.0f, 12.4f );
SomeMatrix.Position = SomeVector;
Which is obviously uglier. Any thoughts on how to do it using the first
approach?