• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Paul C Skertich

How do I create multiple instances of class?

17 posts in this topic

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:

[code]
cBuffer.final = worldMatrix * viewMatrix * projectionMatrix;

[/code]

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.
0

Share this post


Link to post
Share on other sites
[i]worldMatrix [/i]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.
1

Share this post


Link to post
Share on other sites
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,

[code]

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

[/code]

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!
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
Why nog let the world matrix reside inside your modelclass in some way? This way, every cube (or other model) gets its own representation.
1

Share this post


Link to post
Share on other sites
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:

[code]
namespace ModelManager {

public ref class Model {
private:

public:

Model() {

}

// This use to be in there.

Model(const Model^) {

}

};

}
[/code]

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.

[code]
Cube1 = gcnew(Model);
Cube2 = gcnew(Model);

[/code]

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?
0

Share this post


Link to post
Share on other sites
[quote name='SIC Games' timestamp='1344190868' post='4966413']
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:

[code]
...
[/code]

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?
[/quote]

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... Edited by SamiHuutoniemi
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
Are you saying you cannot do something similar to this?
[CODE]
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();
}
};
[/CODE] Edited by Ripiz
0

Share this post


Link to post
Share on other sites
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.

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

float getWhatever()
{
return model->getWhatever();
}
private:
Model* model;
};[/CODE] Edited by kunos
1

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='SIC Games' timestamp='1344193112' post='4966430']
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.
[/quote]
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). Edited by Ripiz
0

Share this post


Link to post
Share on other sites
Okay, kunos - now I get it! Thanks! I was becoming confused on that part! Thanks everyone for their input and help!
0

Share this post


Link to post
Share on other sites
As Kunos described creating a Native to Managed Wrapper is scucessfully done. I would like to thank everyone for chipping in!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0