How do I create multiple instances of class?

Started by
16 comments, last by Paul C Skertich 11 years, 8 months ago
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.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
Advertisement
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!
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
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.

ref class EditorModel
{
public:
EditorModel()
{
model=new Model();
}

float getWhatever()
{
return model->getWhatever();
}
private:
Model* model;
};

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

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.
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

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!
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX
As Kunos described creating a Native to Managed Wrapper is scucessfully done. I would like to thank everyone for chipping in!
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

This topic is closed to new replies.

Advertisement