String conversion and AnimationEndCallBack

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

String conversion and AnimationEndCallBack

Post by AshmenGlue »

I've got 2 questions.


1. How do I convert a char array into a const wchar_t so I can display it in Irrlicht? I have a

char name[256];


2. How EXACTLY do I use the setAnimationEndCallBack function in IAnimatedMeshSceneNode. I've already declared an IAnimationEndCallBack. I'm not sure what to do with the OnAnimationEnd fuction and all that.

Thanks for helping.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

1.
char name[256];
char* nam;
nam = name;
wchar_t string = wstring(nam).c_str();

maybe it also works when u do:
char name[256];
wchar_t string = wstring(name).c_str();

but i dont know....first one should just work perfectly
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

Here's what I did:

Code: Select all


char name[256];
char* playernametemp;
const wchar_t* playername;

playernametemp = name;
playername = std::wstring(playernametemp).c_str();

When I compile I have an error that says "left of c_str() must have class/struct/union type" and right below it is a "type cast: cannot convert from char* to std::basic_string"
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

ups...i think u don't need the .c_str()
its only needed when u have something else in there like an int....
my fault
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Re: String conversion and AnimationEndCallBack

Post by dhenton9000 »

AshmenGlue wrote:I've got 2 questions.


2. How EXACTLY do I use the setAnimationEndCallBack function in IAnimatedMeshSceneNode. I've already declared an IAnimationEndCallBack. I'm not sure what to do with the OnAnimationEnd fuction and all that.

Thanks for helping.

I've got an animationcallback sample at http://www.s-fonline.com/webhosting/dhenton9000 Look for the menu option for the NewtonIrrlicht integration FPS demo. Then grep the source for OnAnimationEnd. The milkshape animation signals to Newton to put up the door barrier when the door is in closed mode.

hth
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

Sudi: Even after removing the c_str() I still get the second type cast error. Why is that so?

dhenton9000: I'm downloading it right now. Thanks.
rincewind
Posts: 35
Joined: Thu Mar 25, 2004 5:28 pm
Location: Germany --> Bonn

Post by rincewind »

Don't use the STL wstring but the irrlicht built-in stringw:

Code: Select all

char name[256];
// fill name array with data
// ...
const wchar_t *string = irr::core::stringw(name).c_str();
It has long been an axiom of mine that the little things are
infinitely the most important.
-- Sir Arthur Conan Doyle, "A Case of Identity"
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

This is really really very frustrating. rincewind your code compiles fine but when I try to print it I get some crazy symbols or hexidecimal.

I've tried printing the result with printf (I get crazy stuff), with cout (hexidecimal), with wcout(nothing shows up). I even tried converting the wchar_t back to a string with:

std::string converback;
convertback = stringc(playername).c_str(); //playername is a converted wchar

and all it shows me is more crazy symbols when I try to print it. What is wrong here? Is it my conversion? My printing?
hybrid

Post by hybrid »

I think you should start over and check the basics of pointers and classes in C++. You're completely messing around with pointer to (w_)chars and (w)string classes. If you do a c_str() you'll get a pointer to char, while stringc(X) will give you an object of whatever. std::string is also a class, but use a char assignement instead of copy constructor with explicit constructor on RHS.
And please check these thousands of threads on string conversion from the beginner's forum. You're not the only one who wants to display strings in Irrlicht.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

@rincewise thats what i meant i mixed it up.....ups

@AshmenGlue u can't print w_chars on the screen without the irrlicht functions!
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Code: Select all

char name[256];
// fill name array with data
// ...
const wchar_t *string = irr::core::stringw(name).c_str(); 
The problem with this code is that you are storing a pointer to memory allocated for a temporary object. Try this instead

Code: Select all

stringw tmpName=name;
const wchar_t* wname=tmpName.c_str();
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
AshmenGlue
Posts: 29
Joined: Wed Oct 12, 2005 9:09 am

Post by AshmenGlue »

Sorry for not replying here. I've found the answer to the string problem. I used the STL func mbstowcs to convert a char* to a wchar_t*. It was that simple. I just store the received string in a char*, passed it into the funct and got my w_char_t* which I can then display on screen.

Sudi: Sorry I didn't elaborate but I wasn't using all of them to print on screen. Some were used to print into a Logger.txt and some were ouput-ed into the console window.
Post Reply