• Create Account

# WierdCat

Member Since 09 Apr 2011
Online Last Active Today, 04:57 PM

### Help with aircraft movement (wrong speed etc)

20 January 2014 - 11:31 AM

Hello, i have a problem with thrust force, speed, and overall movement (which is connected to the speed)

So i want to simulate F/A-18.

i have some constants:

```

const float             full_thrust_force = 156.0f * 1000.0f; // Newtons (two F18 engines)
const mass = 14500.0; //kilograms```

I must also tell you that i calculate aircraft velocity after every plane 'movement' frame

====

Please see video. [the model is not scaled to real dimensions)

The first thing is takeoff. (i didin't include firction between wheels and airfield yet but it shouldn't be the main bug)

As you can see model reaches 100 m / s in a matter of seconds, And i am not quite sure why lol. (maybe thurst is too big its 200% with afterburner ;]) well thing is i dont know how much thrust afterburner can provide. (so i decided to make it 200% as it is in some flight sims)

WIth 100% thurst it takes more than 1 minute to 'liftoff'

heres a code where all magic takes place. hope you will point me into right direction.

```

void __fastcall TVehicle::ProcessFrame()

{

Gather_All_INFO();

AIRLIERON_LEFT->Frame_tick();

AIRLIERON_RIGHT->Frame_tick();

ELEVATOR_LEFT->Frame_tick();

ELEVATOR_RIGHT->Frame_tick();

RUDDER_LEFT->Frame_tick();

RUDDER_RIGHT->Frame_tick();

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

double l;

timin->stopTimer();

l = timin->getElapsedTime();

float dt = float(l); //get elapsed time in seconds

timin->startTimer();

if (dt <=0 ) return;

t3dpoint wind_direction; wind_direction.x = 1.0f; wind_direction.y = 0.0f; wind_direction.z = 0.0f;

float Front_force = Throttle_to_force( Throttle ); //thrust force val

float Q = eGForce * mass; // gravity force val

ThrustForce_vec = YPRangle.rf; //thrust force direction

t3dpoint frontf = ThrustForce_vec;

pos_from_plane_to_planet_center = vectorAB(pos, zero);

GForce_vec = Normalize( pos_from_plane_to_planet_center ); //g force direction

//drag coeff * density * v^2/2 * A

DragForce = reverse_point(ThrustForce_vec);

DragForce = vector_multiple(DragForce, 0.260f * 1.2250f * ((V * V) / 2.0f) * 10.420f);

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

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

// THE PITCH CASE (MOVE IT TO PROPER SECTION OF CODE)

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

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

float elevationangle = ELEVATOR_LEFT->GetAngle() * 17.5f; //17.5 is the max degree that elevator can reach

float elevator_drag_force = 1.20f * 1.2250f * ((V * V) / 2.0f) * Abs(elevationangle) * 13.2040f;

float leverlen = 8.50f;// n3ddistance(pos,ELEVATOR_LEFT->model->CENTER_POINT); // half from 17 meters lets say

elevator_drag_force = elevator_drag_force * 2.0f; //two elevators present

/************MATH****************

v = w * r

w = (r x v) / |r|^2 = alpha / t

l = m * r^2

T = m*r^2 * alpha

w x F = m*r^2 * alpha(acceleraton)

alpha = r x F / m * r^2

alpha = r*F*sin(beta) / m * r^2

after half year i started to read my notes, i don't get them.

***********MATH******************/

float alphaangularity = ((leverlen * elevator_drag_force) * sin(elevationangle*imopi) ) / (mass * leverlen*leverlen);// elevator_drag_force*elevator_drag_force);

float angvel = alphaangularity * dt;

YPRangle.pitch(cos(angvel*imopi),sin(angvel*imopi));

YPRangle.DoRotation();

//float angpos =

// alphaangularity is angle acceleration

//elevators drag force in 90* degrees

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

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

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

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

t3dpoint Lift_force;

GForce_vec = vector_multiple(GForce_vec, Q);

ThrustForce_vec = vector_multiple(ThrustForce_vec, Front_force);

result_force = GForce_vec + ThrustForce_vec + DragForce;//add forces

interia_momentum = result_force;

//divide vector by float

Acceleration = result_force / mass; // a = F / m

//At sea level and at 15 °C according to ISA (International Standard Atmosphere), air has a density of approximately 1.225 kg/m3

vel = vel + (Acceleration * dt);

pos = pos + (vel * dt);

V = n3ddistance(pos,old) / dt;

old = pos; //save position

}

```

### Is it worth to make games for phones in java

04 August 2013 - 07:51 AM

Question llike in topic, but for phones that have keyboard not touchscreen.

### how to implement Intertia

23 May 2013 - 01:43 PM

So i have a jet.

I make a force that moves it. but when i set it to 0 (this force) the jet stops, but it shouldn't, it should at least move with this force(because i didn't include drag force )

but i have no idea how to implement intertia there.

lets assume i got drag force (lets call it drag_force)

all forces are vectors with length of acting force and its direction in my case ;]

if this helps you here is the code

```

void __fastcall TVehicle::ProcessFrame()
{

Gather_All_INFO();

AIRLIERON_LEFT->Frame_tick();
AIRLIERON_RIGHT->Frame_tick();
ELEVATOR_LEFT->Frame_tick();
ELEVATOR_RIGHT->Frame_tick();
RUDDER_LEFT->Frame_tick();
RUDDER_RIGHT->Frame_tick();

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double l;
timin->stopTimer();

l = timin->getElapsedTime();

float dt = float(l);
timin->startTimer();

if (dt <=0 ) return;

float Front_force = Throttle_to_force( Throttle );   //thrust force val

float Q = eGForce * mass;    // gravity force val

ThrustForce_vec  = YPRangle.rf;                 //thrust force direction

pos_from_plane_to_planet_center = vectorAB(pos, zero);

GForce_vec  = Normalize( pos_from_plane_to_planet_center ); //g force direction

GForce_vec 		= vector_multiple(GForce_vec, Q);
ThrustForce_vec = vector_multiple(ThrustForce_vec, Front_force);

//divide vector by float
Acceleration = result_force / mass;      // a = F / m

dk = ( dt*dt );

accvel = Normalize( Acceleration );

Translation = vector_multiple(Acceleration, dk);
Translation = vector_multiple(Translation, 0.50f); //(a * t^2 )/ 2
s = V * dt;
accvel = vector_multiple(accvel, s);         //  V0 * t   => convert it to vector
Translation = vectors_add(Translation, accvel);   //add vectors v0t + (at^2)/2   => s= v0t + at^2 / 2
t3dpoint rp = vectors_add(pos, Translation );      //move to new position
if ( rp.y < 0 ) rp.y = 0.0f;
pos = rp;
// v = s / t
V = n3ddistance(pos,old) / dt;  // s = V * t 						v=s/t

old = pos;  //save position

}

```

as you can see i use result_force

this need to be changed to intertia but how? ;x

like always i attach a video

by the way i have problems with calculation velocity properly but as soon i will deal with this problem and add some things i will make a new post ;P

### Problem with construction of two vectors from one [opengl]

23 March 2013 - 07:13 PM

hello, i am trying to create a 3d box from on screen. (from a specified modelview)

here is what i do:

get from modelview 3 vectors (front, right and up) (they're versors)

then i check when i clicked at the beggining and i make a vertex (the first box vertex) call it A (red dot)

after that i check where actually mouse pos is and create a second vertex (the last box front face vertex) call it B (green dot)

i make a vector from first vertex to last vertex (AB)

and then project it onto 2 versors (right and up)

then i make a depth vector (from front versor)

but i does not work : )

here is a vid:

I am using the formula from wikipedia

result = lengthof(projected_vec) * cosine_between_those_2_vectors * versor_direction_of_vec_that_will_be projected_on

please look at my code it looks fine but maybe i can't find bug there

and here is code with (stage 2 - green dot and rest of box creation)

```

void __fastcall TModelGroupHandler::ResizeBox(int X, int Y, HWND hwnd)
{
if (n2ddistance(float(lastx), float(lasty), float(X), float(Y) ) < 10.0f) return;
if (insert_box_first_stage_completed == false) return;

double * m_PickInfo_ModelView = new double[16];
t3dpoint vX; t3dpoint vY;

glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);
/*

AIR_MATRIX[0] = rr.x; //right
AIR_MATRIX[1] = rr.y;
AIR_MATRIX[2] = rr.z;
AIR_MATRIX[3] = 0.0f;
AIR_MATRIX[4] = ru.x; //up
AIR_MATRIX[5] = ru.y;
AIR_MATRIX[6] = ru.z;
AIR_MATRIX[7] = 0.0f;
AIR_MATRIX[8]  = -rf.x; //front
AIR_MATRIX[9]  = -rf.y;
AIR_MATRIX[10] = -rf.z;
AIR_MATRIX[11] = 0.0f;
AIR_MATRIX[12] =  0.0f;  //point
AIR_MATRIX[13] =  0.0f;
AIR_MATRIX[14] =  0.0f;
AIR_MATRIX[15] = 1.0f;

*/

vX.x = float(m_PickInfo_ModelView[0]);
vX.y = float(m_PickInfo_ModelView[1]);
vX.z = float(m_PickInfo_ModelView[2]);

vY.x =	float(m_PickInfo_ModelView[4]);
vY.y =	float(m_PickInfo_ModelView[5]);
vY.z =	float(m_PickInfo_ModelView[6]);
//vector projection onto another vector

t3dpoint nX = vX;
t3dpoint nY = vY;

vX = vector_multiple(vX, 10000.0f);
vY = vector_multiple(vY, 10000.0f);

delete m_PickInfo_ModelView;

t3dpoint res;        t3dpoint res2;

res = GetPositionFromSpaceDepth(X, Y, hwnd); //GREEN DOT

//==================================================================================
//right vector projection
t3dpoint projected_vec;     projected_vec = vectorAB(base->p1, res);

float cos_angle = RadToDeg(   AngleBetweenVectors(vX,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh

float magni;
magni = magnitude( projected_vec );

float fp; /* floating point */
fp = magni * cos_angle;

t3dpoint proper_right_vec = vector_multiple(nX, fp);
//==================================================================================
//down vector projection
//==================================================================================

projected_vec = vectorAB(base->p1, res);

cos_angle = RadToDeg(   AngleBetweenVectors(vY,projected_vec)  );      //vY should be reversed now but i does not matter now because box right vector is wrong too)

cos_angle = cos(cos_angle*imopi);                                 //ssh

fp = magni * cos_angle;

t3dpoint proper_down_vec = vector_multiple(vY, fp);

proper_down_vec = reverse_point( proper_down_vec );

//==================================================================================
t3dpoint depth_v = vectorAB(base->eyepos, base->eyepointingpos);    depth_v = Normalize( depth_v );

depth_v = vector_multiple(depth_v, 50.0f); //default 50 meters depth

//*************************************************
//** proper_down_vec
//** proper_right_vec
//** depth_v
//**
//**  p1    p2       p5  p6
//**
//**   front          back
//**  p4    p3       p8  p7
//**
//**
//**
//*************************************************

base->p3 = res;

box_can_be_drawn = true;
}
```

cheers

### One way list into glVertexPointer

24 January 2013 - 11:03 AM

```struct VertexDynArrayElement {
public:
t3dpoint p;
t3dpoint c;
float 	 a;
textpoint uv;

double VERTEX_R;
double VERTEX_G;
double VERTEX_B;

int VERTEX_Cr;
int VERTEX_Cg;
int VERTEX_Cb;

VertexDynArrayElement * next;
VertexDynArrayElement * prev;
bool blank;
VertexDynArrayElement() {
prev = NULL;
next = NULL;
blank = true;
}
};
```

i want to put this into glvertexpointer or is it any other way to speed up rendering instead of using glbegin glend.

Cheers :}

PARTNERS