Advertisement

C Programmers : I want u !

Started by February 08, 2002 03:18 PM
5 comments, last by openhelpmegl 23 years ago
I don''t known C at all but I have to make a MilkShape loader for OpenGL in Delphi, and I have a C example... so I''ve MUCH difficulty to understand. Are there somebody to help me to understand and then to translate this code in Delphi. http://nehe.gamedev.net/trentp/gametutorials/lesson04.asp (just the .MS3D Model Format) Maybe it will take you 15 minutes but me... 15 days =) Thank u very much !! u can answer at bobnco@caramail.com or in this forum...
I''m not going to do the conversion for you, but I suggest that you get a small tutor with the basic syntax. For example, the { and } are about the same as begin and end in Delphi. A variable is declared by a (most times) 3-letter name of the type, and then the name, like :

  int Hello = 10; // This is an integer type                    variable with the name hello, and it is being                   assigned a value of 10 right away....  


Conditions are most times put between () . C++ is mainly very compact. A function like :

  for (int i = 0; i < 100; i++){    printf("Hello!\n");}  


Does a lot. The for loop takes 3 arguments, separated by ; . The first says that an integer i should be created and assigned a value of 0 right away before the start of the loop. The second argument contains the condition to keep running, in this case as long as i is less than 100, and the third condition says to add 1 to i every time the loop has done. In the loop it outputs "Hello" to the screen every time. The \n in our string tells our prog to go to the next line on the screen.

Once you know the small basics like this, you''ll probably notice that delphi and C++ have pretty much in common. And there are more than enough tutors on C++ on the net to get started, so do a bit of a search in google, and do your conversion!

One last thing : all the functions used you''ll have to handle the same way as most people would handle Delphi functions : if you don''t know what it does, look it up in the documentation...
Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
Advertisement
if you cant understand the c code AND the docs explaing the format. maybe you should try using another model format. face it most games are written in c/c++ so there is very little tutorials written in delphi. you have two options:

1. understand the algorithms and file format.

2. actually learn some c, and then translate the code yourself.

in either case, you will be better off and more of a programmer instead of a copy and paste script kiddie. i have seem some delphi code (its basically a prettied up pascal) and can read its somewhat well. i also can read and understand most pogramming languges given that the syntax is not super wierd (like some pearl stuff, heh). all programming is math and manipulation of data. if the varible names are decent (which i am sure they are given its a tutorial) you should be able to convert it with some work. if it takes you 15 days and you learn something, it will be well worth it. having someone do it for you will just degrade you, and this is weher i make a call to all the coders on the board to help with specific questions but NOT convert all the code for him.

looking over the tutorial, you should be able to graps the fundamentals. you may also see if you can find a ms3d file format spec somewhere. realize, i am being harsh because i wrote my own .md2 loader straight from a website with only the file format and structes on the site. no code at all. if i can do that, i am sure you could take an explained set of clean c code and convert to delphi. especially with all the c references around. do some research it wont kill you.

btw you may want to use the md2 format as its probally easier, and then later on after you understand what you are doin, tackle the ms3d format.
quote:

i also can read and understand most pogramming languges given that the syntax is not super wierd (like some pearl stuff, heh)


Hey, Perl is cool. A little bit obfuscated, but it''s not that bad either. The problem is not Perl, it''s some Perl programmers...

Look:

  #!/usr/bin/perl -w# 531-byte qrpff-fast, Keith Winstein and Marc Horowitz <sipb-iap-dvd@mit.edu># MPEG 2 PS VOB file on stdin -> descrambled output on stdout# arguments: title key bytes in least to most-significant order$_=''while(read+STDIN,$_,2048){$a=29;$b=73;$c=142;$t=255;@t=map{$_%16or$t^=$c^=($m=(11,10,116,100,11,122,20,100)[$_/16%8])&110;$t^=(72,@z=(64,72,$a^=12*($_%16-2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271);if((@a=unx"C*",$_)[20]&48){$h=5;$_=unxb24,join"",@b=map{xB8,unxb8,chr($_^$a[--$h+84])}@ARGV;s/...$/1$&/;$d=unxV,xb25,$_;$e=256|(ord$b[4])<<9|ord$b[3];$d=$d>>8^($f=$t&($d>>12^$d>>4^$d^$d/8))<<17,$e=$e>>8^($t&($g=($q=$e>>14&7^$e)^$q*8^$q<<6))<<9,$_=$t[$_]^(($h>>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x"C*",@a}'';s/x/pack+/g;eval  


Neat, eh ? That''s a CSS DVD decrypter. OK, just a little bit obfuscated, but what the hell...
Sorry... I perhaps badly expressed myself but I only want some help to understand some lines of code and then I will be able

to translate in Delphi.

I can give you some examples :

# typedef struct MD2_HEADER_TYP ...
( is there like "type MD2_HEADER = record ..." ? )

# bool Load(char* filename);
( ? )

# void Render(int numFrame);
( like "function Render(numFrame : Integer" ? )

# if(frames==NULL)
return false;
( "==" ? )

# for(loop=0; loop{
vertList[index].u= *((float*)command);
command++;
( "++" and "*" ? )

# unsigned short* triangleIndices
( this type ? )

THAT''S ALL FOR THE MOMENT =)

Thank you for your solidarity.
Have you looked into C/C++ syntax at all? If you are familiar with Delphi it seems similar, I''m sure you''ll get answers pretty quickly. I only know C++ so can only answer some of your questions.

== this is the equality operator, a test of. not like =, which is assigning the right hand value to the variable on the left.

++ increment operator, increases the value of the variable by 1. can be used in front of or behind the variable name, eg i++ or ++i

* indicates a pointer. eg, char* filename, this is a pointer (a memory address) to the first char in the char array called filename. These are difficult to explain and understand but have many uses.

Sorry, I cant be of more help
Advertisement
> can be used in front of or behind the variable name, eg i++ or ++i

WARNING: the results of both operators (the pre- and post-increment) are *different* on context ! Most of the time, they are not interchangeable !

This topic is closed to new replies.

Advertisement