Mathe für Schranz0r

Previous topic - Next topic

WPShadow

Hi!

Hast du Bock auf Mathe? Ich bastle seit gestern Abend dran herum, aber die blöden Vektoren machen alles, bloß das nicht, was ich möchte... =/

Was ich brauche, ist ein Wert, der sich auf X & Y, je nach Winkel aufteilt, also:

0°:  X = 5000 Y = 0

45°: X = 2500 Y = 2500

90°: X = 0 Y = 5000

usw.

Soweit funktioniert es bei mir ja auch, aber wenn ich in den negativen Bereich gehe, dann fährt mein Ding rückwörds. Und ich bin bei Gott nicht der geborene Mathematiker!

Bitte Hilfe?

Gruß

W.
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Kitty Hello

Also, die Koordinaten, wenn Du ein Quadrat mit einer schrägen linie schneidest?

WPShadow

Kurz erklärt:

Ich möchte ja mein Raumschiff beschleunigen. Dafür benutze ich NewtonBodyAddForce (oder so). Auf jeden Fall benutze ich force[0] und force[1]. Problem ist, daß ich die Kräfte, je nach Winkel aufteilen muß. Und da liegt auch schon mein Problem...

Gewissermaßen eine Beschleunigung gerade aus (also Gas geben) und den Winkel verändern, in dessen Richtung ich fliegen möchte und in die die Kraft wirkt.

Mit 5000 meine ich eigentlich die Kraft, die wirkt und die auf force[] aufgeteilt werden soll...
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

bigsofty

*Cough*ATAN2*Cough* request :P
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Kitty Hello

force[0] = cos(phi) * kraft
force[1] = -sin(phi) * kraft

ATAN is ATAN"2" (has 2 parameters)

bigsofty

Atan and Atan2 are quite different? ATAN2 is needed to select the correct quadrant for the angle, maybe it should be called ATAN2?

Quoteatan() takes x and returns y of arc tangents (in radians)

atan2() takes two arguments and returns quadrant correct arc tangents z (in radians)
Good to know its in though! ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

WPShadow

Supersupersuper Danke!
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Kitty Hello

atan returns -180 ... +180
atan2 returns the full -180 ... 180 ... -180

bigsofty

I realise that Gernot, but nearly every language under the sun has ATAN and ATAN2. In this case ATAN takes 2 parameters and acts like ATAN2. It kinda makes it non standard for formulae. This is really just a question of syntax rather than functionality. I'd put in the correct function names for clarity.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

WPShadow

HI!

Nächstes Problem! Wie kriege ich die aktuelle Rotation raus? Ich vermute ich brauche mit

NewtonBodyGetMatrix
NewtonBodySetMatrix

Ich habe es nicht hinbekommen mat[] ein oder auszulesen. Problem dabei ist, daß ich im Prinzip die Bewegung jetzt hinbekommen habe, aber der Winkel der Rotation nicht übereinstimmt.

Ich möchte nämlich den aktuellen Winkel (0 - 359) direkt ans  Schiff übergeben, damit die Richtung mit der Rotation wieder übereinstimmt.

Gruß

W.
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Schranz0r

Haste Code dazu ?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

WPShadow

Hier ist der Code. Wie genau kann ich da machen?


Code (glbasic) Select
//================================
// TIMER

lost_init_timer()

//================================






NewtonBodySetPosition(ownship, 0,0,0)
//
NewtonConvexCollisionCalculateInertialMatrix(ownship, 1)
//
NewtonBodySetForceAndTorqueCallback(ownship)
//
NewtonBodySetAutoFreeze(ownship, FALSE)

NewtonSetWorldSize(minp[], maxp[])

// Hauptschleife

WHILE TRUE

MOUSESTATE mx, my, b1, b2



//lost_interface_main()



NewtonUpdate(lost_GT, 0)

// force[0] = -MOUSEAXIS(0)*3
// force[2] = -MOUSEAXIS(1)*3

//force[0] = COS(phi) * 5000
//force[2] = -SIN(phi) * 5000
//
//force[1] = 500

//=====================================================
IF KEY(200) = 1
force_a[0] = COS(phi) * 5000
force_a[2] = -SIN(phi) * 5000
ELSE
force_a[0] = 0
force_a[2] = 0
NewtonBodySetLinearDamping(ownship, 5.9)
ENDIF
NewtonBodyAddForce(ownship, force_a[])
//=====================================================
IF KEY(203) = 1
force[1] = -5000
phi = phi - 1
IF phi < 0 THEN phi = 359

ELSE
force[1] = 0
NewtonBodySetAngularDamping(ownship, rotdamping[])
ENDIF
NewtonBodyAddTorque(ownship, force[])

//force[0] = -MOUSEAXIS(0)*300
//force[1] = -MOUSEAXIS(0)*3000
Das ist bloß ein kurzer Auszug, also nicht aufregen...

Im übrigen ist es gerade NewtonBodySetAngularDamping das nicht dazu paßt. Ich möchte im Prinzip das Raumschiff in die Richtung drehen, in die auch die Kraft zeigt. Und das macht es etwas schwierig...
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Kitty Hello

Naja, mach eine Matrix mit NewtonBuildMatrix, dann überschreib die Werte [12]...[14] mit den originalen (das ist x,y,z - Position). Dann wieder ans Objekt ranpacken.

WPShadow

Das habe ich schon versucht, aber mir hat das Ding bloß Fehler ausgespuckt sobald ich versucht habe mat[1] o.ä. zuzuweisen, bis ich einfach nur mat[] eingegeben habe. Und ganz egal, was ich versucht habe mat[] zuzuweisen, ob manuell, mit DIMDATA oder sonst wie, das Ding hat sich gewehrt, ohne Ende.

Kannst du mir ein kleines Beispiel geben, wie ich das angehen kann? Einen Fingerzeig, damit ich weiß, wie ich weiter machen muß?
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Schranz0r

So da hast du!

Mit NewtonBodyGetPositionX bis Z kannst du ja die werte holen...
( Hab ich dir glaub auch mal gemacht oder? Steht jetzt aber standartmässig mit drin lustriger weise) :D

und damit kannst du übergeben:

FINGERZEIG->

Code (glbasic) Select
FUNCTION NewtonBodySetPositionX: body_index, posX
LOCAL mat[]
NewtonBodyGetMatrix(body_index,mat[])
mat[12] = posX
NewtonBodySetMatrix(body_index,mat[])
ENDFUNCTION

FUNCTION NewtonBodySetPositionY: body_index, posY
LOCAL mat[]
NewtonBodyGetMatrix(body_index,mat[])
mat[13] = posY
NewtonBodySetMatrix(body_index,mat[])
ENDFUNCTION

FUNCTION NewtonBodySetPositionZ: body_index, posZ
LOCAL mat[]
NewtonBodyGetMatrix(body_index,mat[])
mat[14] = posZ
NewtonBodySetMatrix(body_index,mat[])
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard