Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
4 registered members (AndrewAMD, Quad, soulman3, Ayumi), 675 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
angle function #156449
09/23/07 09:57
09/23/07 09:57
Joined: Sep 2007
Posts: 2
dicethrower Offline OP
Guest
dicethrower  Offline OP
Guest

Joined: Sep 2007
Posts: 2
ok you might think this is something covered before, but i have a problem with my angle function....here is what it is

Code:
 
function getAngle(ENTITY* pObject1, ENTITY* pObject2){
return atan((pObject1.y - pObject2.y) / (pObject1.z - pObject2.z));
}
action roll_me ()
{
while(1){
var angle = getAngle(g_cCharacters[0].eChar, g_cCharacters[1].eChar);
me.roll = angle;
wait(1);
}
}
int main(){
g_cCharacters[0].eChar = ent_create("block.mdl", vector(-144,-112,160) , cursor_me);// mouse
g_cCharacters[1].eChar = ent_create("block.mdl", vector(-144,-112,160) , roll_me);// player/gun
}



NOTE: its in 3d so don't get confused to see Y and Z instead of X and Y. I know the cursor_me action is missing it's just a complex calculation to put the object in 3d on the exact spot where my mouse is in 2d on my screen.

Ok my problem is I get a E1513 error. If I do that calculations in the roll_me action itself it works just fine only with this simple function it does not work....any thoughts anyone?

Last edited by dicethrower; 09/23/07 10:28.
Re: angle function [Re: dicethrower] #156450
09/23/07 13:07
09/23/07 13:07
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hi,

Quote:

(pObject1.y - pObject2.y) / (pObject1.z - pObject2.z)



According to your ent_create functions in your main, both entities have the same height. In this case the calculation above would lead to a division by zero.

Also make sure, that g_cCharacters[1].eChar already exists, when getAngle is executed.

Re: angle function [Re: Fenriswolf] #156451
09/23/07 18:04
09/23/07 18:04
Joined: Oct 2006
Posts: 106
i_program_games Offline
Member
i_program_games  Offline
Member

Joined: Oct 2006
Posts: 106
Here is some code but make sure your arguments are set properly. Here are some examples:

/*
//Example 1: Two VECTORS or two arrays of a length less than 3
vec myAngle = GetAngle(fromAngle,toAngle);

//Example 2: a VECTOR or array with a length < 3 and an entity
vec myAngle = GetAngle(fromAngle,my.x); //notice that my is entered as my.x

//Example 3: an entity and a VECTOR or array with a length < 3
vec myAngle = GetAngle(my.x,toAngle); //notice that my is entered as my.x

//Example 3: two entities
vec myAngle = GetAngle(my.x,you.x); //notice that the my and you entities are entered as my.x and you.x respectivly
*/
///////////////////////////////////
//CODE
///////////////////////////////////

//Custom struct for easier reading
typedef struct
{
var x;
var y;
}VEC_XY;

//function prototypes
function atan2(var nY,var nX);
function GetAngle(var* vecFrom, var* vecTo);

//function definations
function GetAngle(var* vecFrom, var* vecTo)
{
VEC_XY vecTranslatedVector;
vecTranslatedVector.x = vecTo[0]-vecFrom[0];
vecTranslatedVector.y = vecTo[1]-vecFrom[1];
return(atan2(vecTranslatedVector.y,vecTranslatedVector.x));
}


function atan2(var nY,var nX)
{
var nPI = 180;

if(nX > 0)//first or forth quadrent
{
return(atan(nY/nX));
}

if(nX<0)//second or third quadrent
{
if(nY>=0)//second quadrent
{
return(atan(nY/nX)+nPI);
}
else //y<0 //third quadrant
{
return(abs(atan(nY/nX))+nPI);
}

}
else //x=0;
{
if(nY>0)
{
return(nPI/2);
}

if(nY<0)
{
return(-(nPI/2));
}
else //y=0
{
//undefined
}
}

}

Last edited by i_program_games; 09/23/07 19:23.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1