Sign in to follow this  
VladWorks

How do I change the player 'model' into the other 'model'?

Recommended Posts

I have an 'armour1.x' model with an 'armour1 variable' and when the player pics up an 'armour2 variable' I want to change 'armour1.x' to 'armour2.x'. Can anyone please tell me how it's done in the code. A small example is all i need. Thank you VERY much in advance guys! [Edited by - VladWorks on September 1, 2004 3:16:25 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Coder
- I'm afraid I don't understand the problem. Could you please clarify a bit?
- Please use descriptive thread titles


It's not a problem really, I just want to see how that would be handeled using code.

Take this for example: You are using 'Model_one.x' (that represents your model) and you have picked up an item 'armour2' and in your engine you get the 'bool variable for 'armour2' set to true, so your engine loads 'Model_two.x' instead of 'Model_one.x'

EDIT: I just want to know how to handel that, and also do I have to 'delete[] Model_one.x if I load Model_two.x'?

Share this post


Link to post
Share on other sites
Unless you have memory problems (you won't with two simple models), you can load them at the same time (and keep them both in memory). loading a model on the fly will greatly slow down your game as you are waiting for the hard disk. When you draw the player, you can simply do an

if (armour1 == true)
displayarmour1(); // code to display armour1.x model
if (armour2 == true)
displayarmour2(); // code to display armour2.x model

Share this post


Link to post
Share on other sites
Quote:
Original post by falkone
Unless you have memory problems (you won't with two simple models), you can load them at the same time (and keep them both in memory). loading a model on the fly will greatly slow down your game as you are waiting for the hard disk. When you draw the player, you can simply do an

if (armour1 == true)
displayarmour1(); // code to display armour1.x model
if (armour2 == true)
displayarmour2(); // code to display armour2.x model



Do I have to set up that code after BeginScene()?

Share this post


Link to post
Share on other sites
I would load both models only once, in your initialization code. The if statements then go inside your scene drawing routine. The displayarmour1 and 2 are where you would place your code to draw either of the armour models.

Share this post


Link to post
Share on other sites
Or you could eliminate those if branches and use an array of pointer to member functions.

probably no huge increase in performance, but i'd be damned if it isn't just about the sexiest code... ;)

notice the lack of ugly 'if' blocks


public CMyClass
{
public:
typedef void (*CMyClass::pfvRenderModel)( void );
enum MODELS { MODEL_A, MODEL_B, NMODELS };
CMyClass() : m_iModel( MODEL_A )
{
m_pfvRender[ MODEL_A ] = &CMyClass::RenderModelA;
m_pfvRender[ MODEL_B ] = &CMyClass::RenderModelB;
}
HRESULT Render( IDirect3DDevice9* )
{
(*this->m_pfvRender[ m_iModel ])();
return S_OK;
}
void SwitchModel( int iModel )
{
m_iModel = iModel;
}
private:
pfvRenderModel m_pfvRender[ NMODELS ];
void RenderModelA();
void RenderModelB();
int m_iModel;
};

Share this post


Link to post
Share on other sites
szsleepy, you should warn that your code causes mild seizures. The only advantage your code would have is the ability to add extra armour packages from accompanying code rather than in the function itself. I'm sure that Vlad prefers the simplicity of an if statement.

Share this post


Link to post
Share on other sites
Quote:
Original post by falkone
szsleepy, you should warn that your code causes mild seizures. The only advantage your code would have is the ability to add extra armour packages from accompanying code rather than in the function itself. I'm sure that Vlad prefers the simplicity of an if statement.



Dude you know me so well.....as funny as that would sound right now I would :D. Anyway falkone you think this code would be ok?


void arm1_load(CharControl *Char_, Video *vid, int id)
{
if(id == 0)
{
vid->GetBackBuffer();
Char_->delete_obj(id);
Char_->create(id,Char_->x,0,Char_->z);
}
}




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