How do I create multiple instances of class?

Started by
16 comments, last by Paul C Skertich 11 years, 8 months ago
Say for instance, inside my C++ .NET Editor, I want to import a mesh and another mesh and another mesh. What I notice is for instance, "Cube1" and "Cube2" both using same shader and same set to a position. When I run the editor only one will show. Does it have to do with the final matrixs? For instance the:


cBuffer.final = worldMatrix * viewMatrix * projectionMatrix;



Could it be because both basic colored cubes are using the same World Matrix? Do they have to be different World Matrixes?

I looked into creating the model class in a default indexer class, just not really sure if this would be a good idea.

All I need to know is what to do when regarding multiple instances of the same class so, I can set the position and rotation, shaders or what not independantly.

Thanks for all the help and time.
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
worldMatrix defines where object is, if you use same matrix for both cubes you just end up drawing two cubes at the same place, therefore you cannot see second one. So yes, you need different world matrix.
Thanks Ripiz!
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
For some odd reason my brain is having more Brain Farts than usual. It's been like this all day today. I created a property index and configured worldMatrix to have multiple ones. I'm not sure if I was clear but when I go in my editor and for instance import a mesh - I want ti create a incremental index. I also want the class to know okay, since this is a new index then we'll use this.

If I say,



Cube1 ^ = Model = gcnew(Model);
Cube2 ^ = Model = gcnew(Model);



I want the Cube1 to have it's own index and the Cube2 have it's own index, so therefore it can difficuate when using worldMatrix. So, Cube1 generates index 0 and cube2 generates a index 1. Both seperate indexes. I wonder if it's because when I created a Model(const Model ^) { } it copied or something. I don't know much of CLI C++ still learning more about it.

Thanks for the reply!
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
Okay, so I had to set the index property in the editor. Now, I got it - kind of. But hey, at least it's somewhat good. Thanks Ripiz again!
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
Why nog let the world matrix reside inside your modelclass in some way? This way, every cube (or other model) gets its own representation.
I could but for some reason inside the editor when I would create a new class - it would automatically assume to position one cube. The managed dll it like this:


namespace ModelManager {

public ref class Model {
private:

public:

Model() {

}

// This use to be in there.

Model(const Model^) {

}

};

}


I'm not sure if the Model(const Model^) is a copy constructor or what. I'm fairly understanding C++ .NET. So, what I was talking about is inside the Editor when I would say in the Form1 public constructor.


Cube1 = gcnew(Model);
Cube2 = gcnew(Model);



it wouldn't realize that there's a difference. But your idea Sami was what I was heading for. Wait, my gears are turning and I think we're syncing. Okay, so you mean the WorldMatrix created inside the model class, right? As of now I have the worldMatrix to be global outside of the whole entire managed environment. Is this what you mean?
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

I could but for some reason inside the editor when I would create a new class - it would automatically assume to position one cube. The managed dll it like this:


...


it wouldn't realize that there's a difference. But your idea Sami was what I was heading for. Wait, my gears are turning and I think we're syncing. Okay, so you mean the WorldMatrix created inside the model class, right? As of now I have the worldMatrix to be global outside of the whole entire managed environment. Is this what you mean?


I mean that you should have the world matrix as a member in your Model class, together with appropriate getters and setters and manipulation methods. Methods could be such ones that translates, rotates, scales...
Since it's a managed DLL for the editor's engine - it reports with a error saying Mixed types are not supported in Managed. So, that's why I declared them above the managed namespaces. However, your idea Sami what I had in mind.
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
I responded too soon. Sorry about that! Hold on for a second. I'll post a response soon.
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