PDA

View Full Version : Help me create a simple drifting insim - i'll host a server for you free 1 month


LeifOlav
24th April 2008, 17:10
Hello. Im trying to do a C# drifting insim, and so far I've managed to make a insim that connects to the server and so on. Now I just missing the "program" that the insim is going to do, and I need some help, because I don't know to much about the coding in C#(sharp) 2008.

So If someone out there want's to give a helping hand, I'll offering to host a server for them in 1 month for free on a fiber-optic 10Mbit / 10Mbit internet connection that runs 24 / 7.

The program I want some help with is a program that shows your driftscore in a insim button, and has a angle-meter ( that shows the angle of your car when drifting) which is something similar to the insim that W.S have.

If this sounds interesting, please send me a PM.


Greetings LeifOlav™fun

AndroidXP
24th April 2008, 17:23
:shhh: InSim application requests go here: http://www.lfsforum.net/forumdisplay.php?f=137

(E: that is, if I interpreted the amount of help you request correctly ;))

LeifOlav
24th April 2008, 17:38
Sorry. Can a moderator move it for me, please?

sun
25th April 2008, 20:28
if you want to make a button in C# then i suggest you need my help ?

dougie-lampkin
25th April 2008, 20:33
if you want to make a button in C# then i suggest you need my help ?

erm...haven't you just made a thread asking why your button isn't working? I don't run into the nearest university and start lecturing Japanese because I can say "konnichiwa"...

sun
25th April 2008, 21:21
err, yes but thtas my km..... i think nobody can help me, lol

Shotglass
25th April 2008, 21:24
i think nobody can help me

im inclined to say indeed but im afraid taa will sit on me till i apologize to him for doing this sort of thing here

Stigpt
25th April 2008, 21:40
managed to make a insim


Heres an insim. Enjoy!
http://www.lfs.net/file_s2.php?id=80

LeifOlav
25th April 2008, 21:50
Heres an insim. Enjoy!
http://www.lfs.net/file_s2.php?id=80

That's lfs Y :really:

tristancliffe
25th April 2008, 21:56
He's taking the mickey, as there is no such thing as "an insim". Insim is part of LFS.

I'll let you off though, because I'm nice. I once had flowers near my name :D

the_angry_angel
25th April 2008, 22:41
im inclined to say indeed but im afraid taa will sit on me till i apologize to him for doing this sort of thing hereI've given out my warning for the day, I'm afraid :p

Nadeo4441
2nd May 2008, 11:20
I was thinking about the angle meter. I have no idea how to calculate the angle ... Any ideas?

Bob Smith
2nd May 2008, 12:11
Compare the heading of travel with the orientation of the body. A little maths will get you the angular difference between the two.

LeifOlav
2nd May 2008, 12:51
I've got the understanding of the angle meter now, but anyone know how the calculate the drifting score ( speed and angle of the car? ) - like in the lfs lapper?

DarkTimes
2nd May 2008, 13:00
The LFSLapper code is open source, so you could have look at how they've done it yourself. :)

Nadeo4441
2nd May 2008, 13:10
Compare the heading of travel with the orientation of the body. A little maths will get you the angular difference between the two.

The maths is the problem..

LeifOlav
2nd May 2008, 13:15
The LFSLapper code is open source, so you could have look at how they've done it yourself. :)


Yea, I've already done, but I dont completely understand it


public class MCI
{
public int numOfPlayers;
public DefCompCar[] compCar = new DefCompCar[8];

public MCI(byte[] packet)
{
numOfPlayers = pakGetByte( packet, 3 );
int offsetStartPlayer = 4;
int lengthPlayer = 28;

for (int i = 0; i < System.Math.Min(8,numOfPlayers); i++)
{
compCar[i] = new DefCompCar();

compCar[i].node =pakGetWord(packet, offsetStartPlayer + i * lengthPlayer + 0);
compCar[i].lap = pakGetWord(packet, offsetStartPlayer + i * lengthPlayer + 2);

compCar[i].PLID = pakGetByte( packet, offsetStartPlayer + i * lengthPlayer + 4 );
compCar[i].x = pakGetInt( packet, offsetStartPlayer + i * lengthPlayer + 8);
compCar[i].y = pakGetInt( packet, offsetStartPlayer + i * lengthPlayer + 12);
compCar[i].z = pakGetInt( packet, offsetStartPlayer + i * lengthPlayer + 16);
compCar[i].speed = pakGetWord( packet, offsetStartPlayer + i * lengthPlayer + 20);
compCar[i].direction = pakGetWord( packet, offsetStartPlayer + i * lengthPlayer + 22);
compCar[i].heading = pakGetWord( packet, offsetStartPlayer + i * lengthPlayer + 24);
compCar[i].angvel = pakGetShort(packet, offsetStartPlayer + i * lengthPlayer + 26);
// System.Console.WriteLine("ID:{0} x:{1} y:{2} z:{3} speed:{4} direction:{5} heading:{6} angvel:{7}", PLID, x, y, z, speed, direction, heading, angvel);

// if(debug)System.Console.WriteLine("{0:F2}m {1:F2}m {2:F2}m {3:F2}km/h {4:F2} {5:F2} {6:F2}", xm, ym, zm, spm, dirm, headm, angm);
}
}
}


If this is the correct code I don't understand how the calculate it

the_angry_angel
2nd May 2008, 13:23
Nope, what you're looking at there is just the code to unpack the compcar structure and make it more usable.

DarkTimes
2nd May 2008, 13:37
I had a quick look through the lapper src, and I think the drift calculation code is in the Players.cs file. Look for the UpdateState method, there's alot of code in there that mentions drifting, angle, velocity, drift-score etc..

LeifOlav
2nd May 2008, 14:03
Yup, I found it. Thanks for helping.

But after a while trying to understand this code, I figured out that it's still to hard for me to understand. So can anyone help me (over msn or whatever) make a code for drifting angle and drifting score? I don't wanna spend so many hours trying to understand all of this, so If anyone could help I would be grateful. :shrug:

Nadeo4441
2nd May 2008, 15:50
I need a complete theory , what divide by what etc. , im noob in maths :D

DarkTimes
2nd May 2008, 18:00
To be honest the code is there in Lapper in the UpdateState method. First it gets the absolute angle of the car, using the direction and heading, then it checks to see if the absolute angle is between the minimum and maximum allowable angle (EG the car is actually drifting), then it updates the drift score. We're really only taking about the first 10 or so lines of the method. It's all there.

dougie-lampkin
2nd May 2008, 18:15
Isn't it just find the difference between heading and direction, and make it positive if it's negative? That's what I used before and it worked :shrug:

You can then do any sort of calculation on the resulting angle to make a score out of it, it depends on what you want :)

Nadeo4441
2nd May 2008, 18:25
thanks , but i got it now ...
(Direction / Heading) * 182 = angle

Bose321
2nd May 2008, 18:29
thanks , but i got it now ...
(Direction / Heading) * 182 = angle

Cool, any idea how i can easily 'let my insim know' what Heading is?
Is there any math included like above in the Quote?

LeifOlav
2nd May 2008, 22:37
thanks , but i got it now ...
(Direction / Heading) * 182 = angle

That doesn't work for me... Sometimes it shows 0 and sometimes 182 and sometimes more

dougie-lampkin
2nd May 2008, 22:52
InSim's MCI packets contain both Heading and Direction values. If you are within the limits of grip, both should be the same (+/- 2 degrees or so). But when you drift, they go further apart, as your heading doesn't change (heading = direction of travel), but your direction changes (direction = where you are pointing). Therefore, by getting the difference between those 2 values, you find how much you're drifting by. But in LFS, the heading and direction units are not degrees, so divide by 180 to get them into degrees.

:schwitz:

LeifOlav
2nd May 2008, 23:27
When I try to get it in messages like this:

InSim.Send_MST_Message("/msg ^1Angle: ^6" + (MCI.Info[0].Direction / MCI.Info[0].Heading) * 180);

I only get angle = 0, 180 and some other random numbers. What's wrong, or is it just not possible to show it in msg? :(

DarkTimes
2nd May 2008, 23:32
Well, I suck at maths too so I can't help on whether the formula is correct, but two things I notice in your code. First of all it should be 182 and not 180. Second of all you're inadvertently casting the result of that sum into an integer, when it should really be a float, which in my experience can cause issues when values get rounded in a way you don't expect. Someone with more maths skill can comment on the basis of what you're doing, but from a C# perspective I would try:


float angle = (MCI.Info[0].Heading / MCI.Info[0].Direction) * 182f;
InSim.Send_MST_Message("/msg ^1Angle: ^6" + angle.ToString());

LeifOlav
2nd May 2008, 23:38
Well, I suck at maths too so I can't help on whether the formula is correct, but two things I notice in your code. First of all it should be 182 and not 180. Second of all you're inadvertently casting the result of that sum into an integer, when it should really be a float, which in my experience can cause issues when values get rounded in a way you don't expect. Someone with more maths skill can comment on the basis of what you're doing, but from a C# perspective I would try:


float angle = (MCI.Info[0].Heading / MCI.Info[0].Direction) * 182f;
InSim.Send_MST_Message("/msg ^1Angle: ^6" + angle;


Thanks for trying to help, but I got the same problem with this code :/

*waiting for some math experts to comment, while im trying to find it out by my self* :thumb:


Edit: Found something that maybe needs to be braided into the code:

word Direction; // direction of car's motion : 0 = world y direction, 32768 = 180 deg

word Heading; // direction of forward axis : 0 = world y direction, 32768 = 180 deg

As I understand it the direction and heading should only get divided or multiplied with 180 when the x or y axis contains 32768?

Nadeo4441
3rd May 2008, 00:16
Sorry ! its my fault
its
(Direction - Heading) / 182 = angle

dougie-lampkin
3rd May 2008, 10:35
Sorry ! its my fault
its
(Direction - Heading) / 182 = angle

I've just said that 2 times :really:

LeifOlav
3rd May 2008, 12:29
Then it's impossible to show it in messages, because what I can see out of that code ((direction - heading) / 182 = angle) is 0, 180 and other random numbers :shrug:

LeifOlav
11th May 2008, 19:46
anyone know how to make a button with text like messages and rules in, and a "ok" button when they join server?

Bose321
12th May 2008, 09:30
easy, but i still havn't figured out the angle because it is doing that weird :x

LeifOlav
12th May 2008, 15:28
easy, but i still havn't figured out the angle because it is doing that weird :x

Tell me how then. I havn't found out of the angle either.

Bose321
15th May 2008, 19:04
well, i could help you out if you add me on msn, or pm me. maybe we could work together :shrug:

LeifOlav
18th May 2008, 08:36
well, i could help you out if you add me on msn, or pm me. maybe we could work together :shrug:


I've sent you a pm. Have you added me to msn?

Bose321
18th May 2008, 12:11
i see nothing :shrug: