Jump to content

  • Log In with Google      Sign In   
  • Create Account

WiredCat

Member Since 09 Apr 2011
Offline Last Active Today, 05:41 PM

#5199234 C++ how to declare something that isn't declared?!?

Posted by WiredCat on 20 December 2014 - 05:01 AM

Just to be clear __fastcall get off me you little rat.

 

I am not following any borland conventions i am not following any convention except my own convention:







struct TSubparticle
{
double * charm;
TSubparticleP * ConsistsOf;

virtual void ReactWith(TSubparticle * p) {}

		TSubparticle& operator=(const TSubparticle& in)
		{
			charm = in.charm;
			ConsistsOf = in.ConsistsOf;
			return *this;
		}
};

My convention is simple structNameP = equals to array of this structure* (array of pointers)

so when i have this i can easily







TSubparticle MEME;

MEME.ConsistsOf = new TSubparticleP[ number ];

for (int i; i < number; i++) MEME.ConsistsOf[i] = new TSubparticle(); //or attach other



the main reason was in the past ONCE UPON A TIME i had a problem :P i couldnt manage to make TSubparticle ** arr; to create an array of pointers

so i used typedef instead


END OF STORY

TSubparticle




#5198939 C++ how to declare something that isn't declared?!?

Posted by WiredCat on 18 December 2014 - 08:22 AM

struct TSubparticle
{
TSubparticleP * <-- here i want to declare that typedef below
};

typedef TSubparticle * TSubparticleP;

cheers.




#5191509 Extracting From Final Transform Matrix

Posted by WiredCat on 06 November 2014 - 07:39 AM

if you are delaing with rot pos and scale its doable (after getting info from matrix, you must untransform results )

 

for gl matrix its like:

 

if not using that gllike matrix you need to transpose it and you will get everything you need: (i dont know where scaling is its probably where zeros are)



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




#5188001 Ray plane intersection problem (need verification to the code)

Posted by WiredCat on 19 October 2014 - 09:40 AM

pls buckeye dont eat me lol :P ok ill debug it




#5186692 Drawing a cricle on the plane

Posted by WiredCat on 13 October 2014 - 07:10 AM

SOLVED        SOLVED        SOLVED      SOLVED

 

 

 

 

 

So i have a plane that has a normal n and distance d (normal normalzied)

 

 

i want to draw a circle on it (set some vertices there on the surface)

 

my code looks like this:

determine what direction face (plane) is facing (x or y or z)

 

go through a loop



if (ShockSurfH.algined == 2) { //Y algin so XZ calculus
t1.y = 0;
t1.x = cos(angle*imopi)*(radius-1.0f);
t1.z = sin(angle*imopi)*(radius-1.0f);

t2.y = 0;
t2.x = cos(angle*imopi)*radius;
t2.z = sin(angle*imopi)*radius;

t3.y = 0;
t3.x = cos(angle2*imopi)*radius;
t3.z = sin(angle2*imopi)*radius;

t4.y = 0;
t4.x = cos(angle2*imopi)*(radius-1.0f);
t4.z = sin(angle2*imopi)*(radius-1.0f);

							 }


shockwaveH[i*4+0] = pos+ ( nH * (t1*nH));
shockwaveH[i*4+1] = pos+ ( nH * (t2*nH));
shockwaveH[i*4+2] = pos+ ( nH * (t3*nH));
shockwaveH[i*4+3] = pos+ ( nH * (t4*nH));

i set circle verts on the 'axis' and then project it onto the plane (the 2nd code) however the bigger slope of the plane circle starts to look like an ellipse.

 

How to draw a normal circle?




#5185527 Dropping a not guided bomb

Posted by WiredCat on 07 October 2014 - 08:04 AM

 

Just a comment, but your weight-force looks suspicious as it appears to be based on position (and you don't mention what "Q") is. If you're trying to account for the slight change of gravity due to height, you should base it only on height, not position.



float Q = eGForce * Weight; // gravity force val  eGForce is 9.81 gravity const     Q euals to m * g //in school they tought me that Q = mg 
(maybe you name it somehow differently)

float squareSpeed = VectorLength(vel); //speed squared ;p

t3dpoint WeightForce = Normalize(-pos) * Q; //since i have almost round globe (not just flat ground with heightmap) 
i Normalize reversed position to obtain a gravity direction vector and multiple it by weight force

t3dpoint DragForce = Normalize(-vel) * (DragCoeff * ((1.250 * squareSpeed)/2.0f) * 0.760f); bla bla bla 0.768 is an area for mk84 ;] and 1.250 is air dens 
(here constant but i have a function for determining the proper airdens)

t3dpoint Acceleration = (WeightForce + DragForce) / Weight; yep still no stabilizators, but it hink they will make bomb go further (checked it by shooting 
arrows with bow ;])

pos = pos + (vel * dt);
vel = vel + (Acceleration * dt); //where dt is time between frames

btw thanks for your replies i will iterate towards ground




#5184121 Problem with positioning an object after no collision :) sounds strange?:P

Posted by WiredCat on 30 September 2014 - 01:44 PM

Hi, i have a problem with calculating position of a tank that its position is calculated from 4 points (see image below there are 4 spheres on the corners of tank hull - red green white and blue)

 

tankf.jpg

 

 

 

So i do following steps:

 

First i calculate forces that are acting on the tank (in this example tank is dropped from 20 meters above the surface), i simplified the formula so force acting on the tank is gravity (weight) only. It should fall to the point on the surface this big red sphere ;]

 

Then after setting new position of a tank i check whenever there was a collision with the surface[ from tank old position to the new one) and if there was i set the tank to the proper position. BUT problem occurs when theres no collision at all

 

let me start from begin:

 

calculate forces acting on tank

for each collision sphere (white,red,green,blue):

check collision (from old position to the new position - new pos, is a pos where we want to go with the tank) if there was no collision return that point where we want to go (new pos)









fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl); <-- last value is the returned point
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);

col_front_left, col_front_right, col_rear_left, col_rear_right are positions of these collision spheres. the return point of collision or no collision is

rfl for front left , rfr for front right, rrl for rear left, rrr for rear right

 

fl,fr,rl,rr are bools to help me determinate where collision occured.

 

then i calculate the actual pitch and roll of the tank, and the new roll and pitch after collision(or no collision)

 

then i subtract them to see the difference (and then i can rotate tank by this angle)

 

a(anglename) stands for actual(anglename)         n(anglename) stands for new(anglename)









t3dpoint aroll  = ( (col_front_left - col_front_right) + (col_rear_left - col_rear_right) ) /2.0f;

t3dpoint apitch = ( (col_front_left - col_rear_left) + (col_front_right - col_rear_right) ) /2.0f;

t3dpoint nroll 	= ( (rfl - rfr) + (rrl - rrr) ) / 2.0f;

t3dpoint npitch = ( (rfl - rrl) + (rfr - rrr) ) / 2.0f;

so now we are here since tank position and rotation is represented by 4 points (these collision spheres)

i calculate the position like

 

pos = (rfl+rfr+rrl+rrr) / 4.0f; (add all sphere positions  and then divide it by the amount of spheres) and this is the main line causing problems, whenever i want to go down it goes infront...

 

heres the full code:











void __fastcall CheckForCollision()
{
int facei = ReturnFaceIndex(oldc);

t3dpoint movement_ray = vectorAB(oldc,pos); //oldc is a point before movement, pos is a point where we want to go (after movement).

t3dpoint rfl, rfr, rrl, rrr;
bool fl,fr,rl,rr;

rfl = col_front_left;
rfr = col_front_right;

rrl = col_rear_left;
rrr = col_rear_right;

     // &PS, //
fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl);
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);



t3dpoint aroll  = ( (col_front_left - col_front_right) + (col_rear_left - col_rear_right) ) /2.0f;

t3dpoint apitch = ( (col_front_left - col_rear_left) + (col_front_right - col_rear_right) ) /2.0f;

t3dpoint nroll 	= ( (rfl - rfr) + (rrl - rrr) ) / 2.0f;

t3dpoint npitch = ( (rfl - rrl) + (rfr - rrr) ) / 2.0f;


//. u = v - n * dot(n, v)
//
// cross(n, cross(v, n))

t3dpoint A,B, n;

A =  vectorAB(sector->VBO_V[sector->VBO_BE[facei].INDEX_START],sector->VBO_V[sector->VBO_BE[facei].INDEX_START+1]);

B =  vectorAB(sector->VBO_V[sector->VBO_BE[facei].INDEX_START],
sector->VBO_V[sector->VBO_BE[facei].INDEX_START+3]);
n = vectorcross(A,B);

t3dpoint proj_surfacev_apitch = n * (apitch*n);
t3dpoint proj_surfacev_npitch = vectorcross(n, vectorcross(npitch,n));

t3dpoint proj_surfacev_aroll = vectorcross(n, vectorcross(aroll,n));
t3dpoint proj_surfacev_nroll = vectorcross(n, vectorcross(nroll,n));

float pitcha = AngleBetweenVectors(proj_surfacev_apitch, apitch);
float rolla = AngleBetweenVectors(proj_surfacev_aroll, aroll);
float pitchn = AngleBetweenVectors(proj_surfacev_npitch, npitch);
float rolln = AngleBetweenVectors(proj_surfacev_nroll, nroll);

float res_pitch = pitchn - pitcha;
float res_roll = rolln - rolla;


hull.rotation.pitch( cos(res_pitch), sin(res_pitch) );
hull.rotation.DoRotation();

hull.rotation.roll( cos(res_roll), sin(res_roll) );
hull.rotation.DoRotation();



pos = (rfl+rfr+rrl+rrr) / 4.0f;

}


any suggestions? i think the code is fine, maybe someone else will tell me that,  it should work but somehow it isn'teverything btween las sphere_intersect_polygon and pos = (xx) / 4.0f is irrevelant to the topic.

 

 

so the code that is responsible for this is like:



void __fastcall CheckForCollision()
{
int facei = ReturnFaceIndex(oldc);

t3dpoint movement_ray = vectorAB(oldc,pos); //oldc is a point before movement, pos is a point where we want to go (after movement).

t3dpoint rfl, rfr, rrl, rrr;
bool fl,fr,rl,rr;

rfl = col_front_left;
rfr = col_front_right;

rrl = col_rear_left;
rrr = col_rear_right;

     // &PS, //
fl = col->SPHERE_INTERSECT_POLYGON(col_front_left,col_front_left + movement_ray,2.0f,sector,facei,rfl);
fr = col->SPHERE_INTERSECT_POLYGON(col_front_right,col_front_right + movement_ray,2.0f,sector,facei,rfr);

rl = col->SPHERE_INTERSECT_POLYGON(col_rear_left,col_rear_left + movement_ray,2.0f,sector,facei,rrl);
rr = col->SPHERE_INTERSECT_POLYGON(col_rear_right,col_rear_right + movement_ray,2.0f,sector,facei,rrr);



pos = (rfl+rfr+rrl+rrr) / 4.0f;

}

maybe il post a vid what i get:

 

 




#5183545 OpenGL rotation matrix, [math] rotates in different direction

Posted by WiredCat on 28 September 2014 - 02:59 PM

First of all i would like you to see this:

tank01.jpg

 

 

 

 

Image shows a tank (not rotated, static) with 4 collision spheres (white, red, green, blue) 

 

 

/ note: three lines what you see (white,red,green) show the positive side of an axis, so for red its +x, for green its +y and for white its +z,

 

 

My problem is whenever i try to rotate a tank spheres are rotated backwards. like on this video:

 

 

To rotate a tank i use exactly the same rotation matrix i use to rotate these spheres.

 

 

 

now to explain it more deeply: sphere base position (in relation to unrotated tank) is calculated like this:

 

 

front_left sphere which is white (span_dist, 0, front_dist) [xyz]

front_right (red) (-span_dist, 0, front_dist) [xyz]

 

 

rear_left (green) (span_dist, 0, -front_dist)

rear_right (blue) (-span_dist, 0, -front_dist)

 

 

 

 

i draw the tank like this:





glPushMatrix();
glLoadIdentity();

gluLookAt(eyepos.x,eyepos.y,eyepos.z,lookat.x,lookat.y,lookat.z,up.x,up.y,up.z);

glTranslatef(pos.x,pos.y,pos.z);
glMultMatrixf(hull.rotation.AIR_MATRIX);
 
						hull.model->DrawSimpleModel();

glPopMatrix(); 

hull.rotation.AIR_MATRIX <- this is my rotation matrix (it only has rotation data, - no translation and scale data)

 

 

now i calculate spheres positions like:



float rotm[16];    int i;
for (i=0; i<16;i++) rotm[i] = hull.rotation.AIR_MATRIX[i];

col_front_left = front_left * rotm;
col_front_left = col_front_left + pos;

col_front_right = front_right * rotm;
col_front_right = col_front_right + pos;

col_rear_left = rear_left * rotm;
col_rear_left = col_rear_left + pos;

col_rear_right = rear_right * rotm;
col_rear_right = col_rear_right + pos;

where rotm is a copied hull.rotation.AIR_MATRIX (ofc same values)

a code for multiplying a vertex by a matrix is:



	  t3dpoint operator*(const float in[16]) const
		{     //since its an opengl engine i use this order
		//note that i do not add translation data and do not use scaling
			return t3dpoint(
in[0]*x+in[1]*y+in[2]*z,

in[4]*x+in[5]*y+in[6]*z,

in[8]*x+in[9]*y+in[10]*z);
		}

No i should say something about how do i calculate rotation matrix:

lets say i have three vectors front, right and up vector

 

 

i rotate them by calling pitch, yaw, roll funcitons

and then i build a matrix like this:



			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;

Hopefully its enough info for someone that can help me ;x

 

oh i forgot to add that whenever i try to pitch the rotation matrix (opengl model draws properly) but i get stranger spheres pos.




#5180818 Simulation of drag in flightsims

Posted by WiredCat on 16 September 2014 - 02:59 PM

sorry i have so little knowledge about flight dynamics but i saw you are talking about torque, i have a different view

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

float elevator_drag_force = 0.90f *  ((dens * squareSpeed )/ 2.0f) * Abs(elevationangle) * 2.0f*13.2040f;
float leverlen = 8.50f;
float alphaangularity =	 (dt*((leverlen * elevator_drag_force) * sin( (elevationangle*(17.50f+ 90.0f) )*imopi) ) )/ (mass * leverlen*leverlen);// elevator_drag_force*elevator_drag_force);
float angvel = alphaangularity*dt;



#5172305 Triangle vectors on the circle

Posted by WiredCat on 08 August 2014 - 10:11 AM

circle2.jpg
 

 

 

 

ofc every blue line is angled at 30 degrees. geez i forgot to draw a bottom line of that triangle (that with blue lines since its a cut triangle) so it looks that angles are from circle itself to segment.

 

 

I could build up a matrix where red line unit vec is front z+ is up vector and crossproduct of these two is right vec then i could just yaw it. But i am looking for easier solution

 

 

 

 

just was looking at this and you are right alvaro  making average of these two red lines and making a full trianglei can rotate this avg red line by 30 degs, thanks

 

 

 

OK I will gladly post a solution

 

 Graphics::TBitmap * bmp =      new               Graphics::TBitmap;

bmp->PixelFormat = pf24bit;

bmp->Width  = 1000;

bmp->Height = 1000;

 

int bmpcx = bmp->Width / 2;

int bmpcy = bmp->Height / 2;

 

long double angle = 0.0;

long double scale = 60.0;

                           //cm

long double CircleRadius = 6.0*scale;// 6 * 60 = 360 pixels of radius / diameter 720 pixels

 

long double x;

long double y;

 

long double numofteeth = 16;

 

long double circumreference = 2.0 * pild * CircleRadius;

 

long double teethwidth = circumreference / numofteeth;

long double teethheight = 1.0 * scale; //1 cm height

 

int i;

for (angle=0; angle <360; angle= angle + 0.1)

{

x = CircleRadius*cosl(angle*imopild);

y = CircleRadius*sinl(angle*imopild);

 

    bmp->Canvas->Pixels[bmpcx+int(x)][bmpcy+int(y)] = clBlack;

}

 

  int reach = int(numofteeth);

long double tmp = 0;

long double angler1 = 0;

long double angler2 = 0;

long double vecx;

long double vecy;

 

long double avecx;

long double avecy;

 

long double bvecx;

long double bvecy;

 

 

TPoint A,B,C;

 

t3dpoint vec; vec.z = 0.0;

t3dpoint vecb; vecb.z = 0.0;

for (i=0; i < reach; i++)

{

angler1 = 360.0 * ( tmp / circumreference );

angler2 = 360.0 * ( (tmp+teethwidth) / circumreference );

tmp = tmp + teethwidth;

angle = (angler1 + angler2) / 2.0;

 

//lets say add 30 degs to it so triangle will have 60 30 30

 

        vecx = CircleRadius * cosl((angle)*imopild);

        vecy = CircleRadius * sinl((angle)*imopild);

 

 

        vec.x = float(vecx);

        vec.y = float(vecy);

        vec.z = 0.0f;

        vec = Normalize(vec);

 

        vecx = vecx + ( (long double)vec.x * (teethwidth / 2.0) );

        vecy = vecy + ( (long double)vec.y * (teethwidth / 2.0) );

 

        

        avecx = CircleRadius * cosl((angler1)*imopild);

        avecy = CircleRadius * sinl((angler1)*imopild);

 

        bvecx = CircleRadius * cosl((angler2)*imopild);

        bvecy = CircleRadius * sinl((angler2)*imopild);

 

C.x = int(vecx);

C.y = int(vecy);

 

A.x = int(avecx);

A.y = int(avecy);

 

B.x = int(bvecx);

B.y = int(bvecy);

bmp->Canvas->Brush->Style = bsSolid;

bmp->Canvas->Brush->Color = clBlack;

bmp->Canvas->MoveTo(bmpcx+C.x,bmpcy+C.y);

bmp->Canvas->LineTo(bmpcx+A.x,bmpcy+A.y);

 

bmp->Canvas->MoveTo(bmpcx+C.x,bmpcy+C.y);

bmp->Canvas->LineTo(bmpcx+B.x,bmpcy+B.y);

}

bmp->SaveToFile("E:\\FFS_WTF.bmp");

result

 

 

FFS_WTF.jpg




#5171280 Quaternion angle with itself > 0.001

Posted by WiredCat on 03 August 2014 - 11:20 AM

well you could check long double for it

 

 

just make something lie this 

 

 

rewrite dot4 so it will get quaterions (like old did but i will operate on long doubles and will return long double)

ofc function returns long double

then  return  2.0 * acosl( fabsl( DotDouble4( qa, qb ) ) ); }

 

this could use the best precision for floats

 

 

anyway try to rotate something by in ex 90 degrees and try to find that angle.




#5169311 Which is faster/better - glClearColor/glClear or glClearBuffer* ?

Posted by WiredCat on 26 July 2014 - 09:45 AM

glClearCOlor  does not clear anything

 

 

The glClearColor function specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values specified by glClearColor are clamped to the range [0,1].

 

https://www.opengl.org/sdk/docs/man/html/glClearColor.xhtml

http://msdn.microsoft.com/en-us/library/windows/desktop/dd318377(v=vs.85).aspx




#5168496 projected lines

Posted by WiredCat on 22 July 2014 - 04:40 PM

omg, that worked! :D




#5167961 Black screen of DOOM!

Posted by WiredCat on 20 July 2014 - 10:34 AM

yes possiblycalling meth0ods between glbegin glend fails everything. if you want to parse model eveytime you call drawing you should do a simplier method, anyway if you dont need such task, load model once and draw it., anyway try to lower z_near value maybe you have set it to 1

 

 

hah but wait.

       glBegin(GL_POLYGON); 
          a=subs[1];
          b=subs[2];
          c=subs[3];
           x=stringToDouble(a);
           y=stringToDouble(b);
           z=stringToDouble(c);
           /****draw 3D vertex*****/
           glVertex3f(x,y,z); 
           glEnd();

What sort of dark magic is this 

 

when you call glBegin(something) glENd it requires at least 1 glvertex3f for a point, 2 glvertex3f for a line, and at least 3 glvertex3f for a poly,

 

i see that you put only one glvertex3f betweeen glbegin(GL_POLYGON); glend(); where you should put at least three of them




#5163629 encounter weird problem when turn on the color blending.

Posted by WiredCat on 29 June 2014 - 08:56 AM

so less details, but anyway try this:

divide whole model to different organs, then try to render every organ where you begin from those that are deep in the body and you end with drawing lungs

 

also glBlendFunc needs to be set properly (and sometimes glColor4f <- alpha value)

 

we also dont know if your textures have alpha channel but i guess they don't)

 

At first you need to draw parts that are not transparent and then you draw transparent organs in proper order.

 

 

if you manage to sort your faces you will get almost the same effect like disabling GL_DEPTH_TEST but you'll see properly displayed model

 

 

this also try to lower z_near value (in glFrustum) 

 

or scale in ex lungs so lungs faces wont touch other organs

 

 

 

=====================

anyway youll have to sort faces or that would be far way faster and easier -organs

 

 

this is what ahppens when you sort faces.

yu.jpg

 

 

 

 

one that i can say is i see there z fighting problem or wrong face order or wrong blending factors






PARTNERS