Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / New to C++ and struggling

Author
Message
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 21st Jul 2008 19:52
Hi guys! I've been working on a 3d limb-animation package using DB Classic, but I'm finding it impossible to read in the animation data of a .x or .3ds object (It's a long story, but the "Limb Direction Z" command of DBC always returns zero and it shouldn't). I did find that I could do get the data out if I used GDK, where the command appears to have been fixed.

So, I wrote this little program using DBC:



to save the animation data to the file format my program uses. Only I'm struggling to port the code over to GDK. This is as far as I've got, and it's not compiling:



I keep getting the error "error C2061: syntax error : identifier 'dbLower'" And if I chop out the dbLower commnd, it starts complaining about dbRight instead. Can anyone give me a pointer in the right direction?

If I admit that I'm lying, am I telling the truth?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jul 2008 20:47 Edited at: 21st Jul 2008 20:47


In C++, if statements are formatted as follows:



So, first off, you need this
to be this
.

Then, there is the fact that dbLower does not return a 1 or 0 value. So, it does not fufill it's purpose as an conditional-expression. You have to have a function that returns a 1 or 0.

Another thing: you can't compare strings with ==. C++ is not that high-level (for good reason). You can't treat it like DBPro or Java. You have to use a standard library command such as strcmp.

I recommend completing the entire C++ tutorial before continuing with the GDK.
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 21st Jul 2008 22:30 Edited at: 21st Jul 2008 22:30
A value of one is returned by strcmp is the strings are different, 0 if they are the same. So to compare the return value of dbRight(dbGetFileName(),2) and ".x", you would use this conditional if-statement:

If-statements DO NOT have a semicolon following them, in the same fashion that function declarations do not have semicolons, nor while/do statements. Adding an extraneous semicolon will not produce the desired result.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Jul 2008 22:36
Also, remember to put this at the beginning of your code:

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 21st Jul 2008 23:04
Quote: "A value of one is returned by strcmp is the strings are different, 0 if they are the same. "


There's a fallacy in that statement. strcmp subtracts the ascii value of the characters in the two strings positionally. If it reaches a null terminator in both then it returns zero. If the subtraction of any of the characters in the string results in anything other than zero before it reaches the null terminator in both strings it returns the difference between the two ascii values. This provides a means of determining which, if either, of the strings is larger. The result can be less than or greater than zero if the strings don't match.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 23rd Jul 2008 13:17 Edited at: 23rd Jul 2008 13:18
First let me say thanks for all your help! I've managed to get it working, and I've been googling for C++ tutorials (the language is a lot harder than I ever imagined!) There a still a couple of points I was wondering if you could help me on:
1) What's the difference between Char and Char*? And how do they work as strings, given that the help files seem to define them as a 1-byte integer?

2)Is it possible to write an expression of the type "if x=1 or x=3"? I haven't come accross it in the tutorials I found, but I'd like to be able to call this:


3) The dbPerformChecklistForObjectLimbs tells me that an object has 19 limbs, when in DBC the command tells me there are only 18 limbs. Is the checklist counting the root data as a limb, and if so, how do I prevent the program from writing this out?

Here's my code, in case you need it:

I've had to write out all the data as strings, otherwise DBC won't stand a chance of reading it (dbWriteFloat seems to be writing 8-byte floats instead of 4-byte ones, and DBC only reads 4-byte floats). Actually, is it possible to write out a 4-byte float?

If I admit that I'm lying, am I telling the truth?
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 23rd Jul 2008 16:50
The C++ tutorial I've been using is
http://www.cplusplus.com/doc/tutorial/

You can use an OR statement in C++, (or you can use the || shorthand). The format is something like this:

if ( (statement1) OR (statement2) OR (statement3) )
{
code to execute if any of the statements returns TRUE;
}

also remember to use == instead of = when checking for equality. so in your mini example of "if x=1 or x=3" you would actually use:

if ( (x==1) or (x==3) )
{code}
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Jul 2008 17:52
Quote: "What's the difference between Char and Char*?"


It's a rather involved subject. Essentially a char represents a single character. A char* represents a variable that holds the address of a character. It's a pointer to a char variable. Pointers are quite useful but you really need to study them. It's a topic that's too extensive to cover well in a forum. Suffice to say that a string is typically an array of chars and is usually terminated with a char of value zero to mark the end of the string. A char* can hold the address of the first character of the string and can be manipulated to address each char in the string by incrementing/decrementing the address it holds.

Quote: "Is it possible to write an expression of the type "if x=1 or x=3"?"


The equal sign is for assignment. A double equal sign (==) is used test for equality. But if you're going to be testing for string equality you need to use functions such as strcmp() since using == for such things will only test for the equality of the addresses and not the content of the string.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 23rd Jul 2008 19:50 Edited at: 23rd Jul 2008 19:50
I don't know what level of knowledge you have yet, but to simply Lilith's wonderful (though possibly over your head) explanation, char*'s are references to static locations in memory. You use them as a complete string. When you type this;



string stores the hexadecimal memory address of "hello there". While string is sometimes used almost as if it equaled the string "hello there", it is most often used as equal to the memory address of the string. So, while you can do this:



You can't do this:



Well, you can, but it will only compare the hex address of each string and see which is a larger number.

I hope that helps.

P.S. Just in case I wasn't clear, Lilith's explanation was wonderful. I just know that I would have understood none of it as a beginner.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Jul 2008 19:59
Quote: "P.S. Just in case I wasn't clear, Lilith's explanation was wonderful. I just know that I would have understood none of it as a beginner."


Which is why I can't stress enough the need to sit down and study the language. C++ is not something you can really understand by asking random questions. I came to realize a long time ago that in order to understand why C/C++ is designed the way it is and how best to use it, you need a marginally comprehensive overview of the language so you know where everything fits, even if you don't quite understand the individual parts. I read through my book first with little effort to do things with it. I learned what was available and when I went back for a second, more intense, reading I knew why what I was working on could be used with what else was available.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 23rd Jul 2008 20:09
Exactly. It takes a comprehensive study of the language. Also, as I'm learning about x86 architecture and assembly, I'm starting to see exactly how the frustrating aspects of blocked code and such comes to be.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 24th Jul 2008 16:41
Thanks guys, I'm starting to understand things now. I will take your advice and try learning a bit more about C++ before I go further with coding in it - I think I'll need it!

I mean, I realised earlier today I'd made a foolish mistake when I said dbWriteFloat didn't seem to be writing 4-byte floats - it was, it's just that I hadn't realised that GDK allows negative angles and DBC didn't, so DBC crashed every time!

If I admit that I'm lying, am I telling the truth?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 24th Jul 2008 19:39
Don't sweat it. You should have seen my thread about writing a map file. I didn't do to great, either. But, once you finish off a tutorial over C++, you'll be doing just fine. It takes a lot of practice.

On the topic of a tutorial, this one proved instrumental in learning C++ for me.

http://msdn.microsoft.com/en-us/beginner/cc305129.aspx

Download the whole thing in either XPS or PDF. (I recommend XPS, if you have the dedicated viewer from Microsoft.) It's a very good book. I learned much from it. It goes into more detail than www.cplusplus.com did.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 25th Jul 2008 09:05
What about this?

? You're comparing the data it references to... right?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jul 2008 09:11
That would compare the address for each char*.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 25th Jul 2008 09:16
No, that would compare the first characters, i.e. it will compare 'H' with 'B'.

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 25th Jul 2008 11:20
Mahoney... =( It'd have to be &string1 and &string2 for that... =(
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 25th Jul 2008 11:55
No, to compare the addresses you'd use i'if (string1 == string2)' if you wish to compare the addresses that store the address to your chars(or c-style strings in this case) you'd use i'if (&string1 == &string2)'.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jul 2008 18:43
I missed the *'s. Yeah, that would compare the first letters. But, without the *'s, it would compare addresses. No &'s needed.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Merak Spielman
16
Years of Service
User Offline
Joined: 14th Jul 2008
Location:
Posted: 25th Jul 2008 21:40 Edited at: 25th Jul 2008 21:41
There is a string class, if you want to use it. I'm kind of new myself, so I'm not sure why some people don't like it.

you have to use
#include <string>

at the beginning of the program.

Then you can declare string variables, and you can even compare them to each other.

console code:
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 25th Jul 2008 21:53
Quote: "There is a string class, if you want to use it. I'm kind of new myself, so I'm not sure why some people don't like it."


Just my POV on string class, aside from the fact that it didn't exist when I first learned C.

The string class is useful and has its place. However, I learned to either depend on the str* functions that came with the standard C distribution or learned to write my own routines. When I first used BASIC I didn't feel that I could rely on those LEFT$, CHR$, MID$, etc. functions. It felt too kludgey. To some extent that's how I felt/feel about the str* family of functions. There was too much engineering to get them to do what I wanted and usually it was something for the immediate need, not the general purpose.

Using my own functions that relied mostly on pointers I knew exactly what the code was doing and I found that things like parsing test was a lot more reliable than trying to combine all those other functions inside loops to achieve the same result.

The string class, to a large extent in C++, makes me reliant on those type of built-in functions that made me nervous in BASIC and in C# it's worse because they won't let me use pointers. <sniff>

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jul 2008 21:54
I prefer to use as little outside libraries as possible. That's why I don't use it. But, you'll have to if you want to compare two strings easily.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jul 2008 21:55
C# doesn't have pointers?

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 25th Jul 2008 22:11
Quote: "C# doesn't have pointers?"


It's something of a confusing issue. Pointers actually do exist but it's considered to be unsafe and has be be dealt with in the context of the data being unmanaged. Unlike with C++, with the exception of certain data types, everything is handled by reference rather than value. The advantage of using a string is that you don't have to be as concerned about storage space and reserving enough space for an operation. I've read in extremely large files and parsed the lines in them into arrays of strings using the built-in methods and a minimal number code lines. But manipulating that data internal to the string isn't as simple for me. I dislike using index access to text because to me pointers are more efficient. But with a string class you have to be careful about manipulating the data because the string class has to keep track of changes and actually ends up referencing a new copy of the string with each change.

I'm still a bit of a novice with C# so I don't know if I've made myself clear nor am I confident that my perceptions of the workings of it are spot on. So take everything I say with a pinch of salt.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 25th Jul 2008 22:36 Edited at: 25th Jul 2008 22:38
It's been fascinating reading all you've been saying - I barely understand it, but it's still fascinating. I've downloaded the first couple of chapters of that book Mahoney suggested, I'll start reading in the next day or so

I'm afraid I have another, perhaps unconnected, question. It concerns limbs - I've found a way to extract limb data from a .x file. dbLimbOffset and dbLimbAngle only ever seem to return 0 (which I understand in a way, as each limb at a frame is rotated 0,0,0 relative to its parent). When I use dbLimbDirection, I get the world angle of the limb - but I need the limb angle relative to the limb's parent. I can calculate this by saying:

(it's not proper code, I know). But how can I find what the parent limb is? I'd prefer not to have the user manually key in the limb hierarchy, which is already in the .x file. I confess I'm not 100% sure this will work, but the couple of tests I did seem to suggest it will. Help???

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jul 2008 23:05
Quote: "It's been fascinating reading all you've been saying - I barely understand it, but it's still fascinating."


I know how you feel. You should read some of Jason P. Sage's post. Always interesting/helpful. Lilith is the same.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Jul 2008 17:12
Quote: "There is a string class, if you want to use it. I'm kind of new myself, so I'm not sure why some people don't like it. "


One reason is some stuff doesn't link right with DarkGDK - and even though it usually can be overcome (Lilith has done it numerous times) it's a PITA when you just want to compile and go. Especially since GDK doesn't come with a debug version of the DLL's, and that makes things sometimes tricky to deal with - debugging etc.

Now I've personally had good luck with the string.h lib, but I use only a subset of it... I wrote my own string handler, and now I actually have two versions - One for Ascii and one for Unicode - and the Unicode version has code in it to convert unicode to ascii and back (for USA chars its pretty decent - dunno about other non latin/romantic based languages...) If the alphabet is "A thru Z" then it works good!

I am not a huge fan of operator overloading... so I made my classes wotrk basically like this with both a case sensitive mechanism as well as a case insensitive mechanism:



The Ascii one is available in that DarkGDK OOP lib I released, but if you guys want the unicode one also - I can make the latest versions available.

Note - that as a "good dube" I should tell you to learn the "standard lib" ways - because they are mainstream and generally accepted. Mine however - work nice with GDK and though not standard, quite a few people on here are using them for their ease of use - both in DarkGDK and writing pure DX apps like what I've been doing as of late.

--Jason

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 26th Jul 2008 17:24 Edited at: 26th Jul 2008 17:26
I just looked over your library. It looks great. Wonderful code, as usual. But I want to stick with the standard. :/

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo

Login to post a reply

Server time is: 2024-11-20 17:37:25
Your offset time is: 2024-11-20 17:37:25