How do I create multiple instances of class?
Because it's managed environment I can't mix native and Managed. So, that's a no go for me at least but will be possible when I create the game in native.
Are you saying you cannot do something similar to this?
public class ModelData {
public void draw() {
device->SetIndexBuffer(...);
...
device->Draw(...);
}
};
public class ModelInstance {
Matrix transform;
ModelData ^model;
public void setTransform();
public Matrix getTransform();
public void draw() {
device->SetWorldMatrix(transform);
model->draw();
}
};
It was a good suggestion though Rami just can't do it within Managed Enviroment. Thanks for the help guys!
You cannot have a native class as value member in a managed class, but you are allowed to have pointers to native classes.
So if "Matrix" is your native class you cannot do:
ref class Model
{
public:
Matrix matrix;
};
but you can do:
ref class Model
{
public:
Matrix* matrix;
};
In your constructor, you have to construct the native matrix with new Matrix().
Having said that, I think you have a bigger problem here as your architecture is totally wrong. A "Model" class should be living the native side of the code, because it is not strictly an "editor" thing... your editor will create and edit models that will then be used by the native engine in the game. In this case what you do? You'll have to implement one model for the native side and one model for the managed side? That is really asking for troubles.
You should have a Model class in native and then, you create a EditorModel managed class that just wraps the native class with properties and member functions.
So if "Matrix" is your native class you cannot do:
ref class Model
{
public:
Matrix matrix;
};
but you can do:
ref class Model
{
public:
Matrix* matrix;
};
In your constructor, you have to construct the native matrix with new Matrix().
Having said that, I think you have a bigger problem here as your architecture is totally wrong. A "Model" class should be living the native side of the code, because it is not strictly an "editor" thing... your editor will create and edit models that will then be used by the native engine in the game. In this case what you do? You'll have to implement one model for the native side and one model for the managed side? That is really asking for troubles.
You should have a Model class in native and then, you create a EditorModel managed class that just wraps the native class with properties and member functions.
ref class EditorModel
{
public:
EditorModel()
{
model=new Model();
}
float getWhatever()
{
return model->getWhatever();
}
private:
Model* model;
};
Ripiz, I'm only targeting DX 11 instead of 9. So, yes I can't do it. Since SetWorldMatrix is part of DirectX 9 when I looked it up on google.
Ripiz, I'm only targeting DX 11 instead of 9. So, yes I can't do it. Since SetWorldMatrix is part of DirectX 9 when I looked it up on google.
Well it was just an abstract example. Store ID3D11Buffer instead of Matrix, and update it when you set new transform (or update it before rendering).
Okay, kunos - now I get it! Thanks! I was becoming confused on that part! Thanks everyone for their input and help!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement