Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 1,012 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Handy defines and functions #303310
12/27/09 23:37
12/27/09 23:37
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
I have a few I always use in a common.c file:

Code:
#define new( x )	malloc(sizeof( x ))
#define remove( x )	free( x )

#define NULLVECTOR	nullvector

#define BOOL	short
#define TRUE	1
#define FALSE	0


#define halt(x) 	while(x) wait(1)



What are yours?

Last edited by Joozey; 01/05/10 12:00.

Click and join the 3dgs irc community!
Room: #3dgs
Re: Handy defines [Re: Joozey] #304081
01/04/10 22:04
01/04/10 22:04
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline
Senior Member
Razoron  Offline
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
I also define TRUE and FALSE since i made a really silly mistake with inverting 1 and 0....

Re: Handy defines [Re: Razoron] #304097
01/04/10 23:47
01/04/10 23:47
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Not defines, but some useful functions

Code:
/* general purpose temp variables */
VECTOR vecTemp;
ANGLE  angTemp;
COLOR  colTemp;
var    vTemp;
int    iTemp;
char   cTemp;
float  fTemp;
long   lTemp;

void vec_ang(ANGLE* pang)
{
	pang->pan = ang(pang->pan);
	pang->tilt = ang(pang->tilt);
	pang->roll = ang(pang->roll);
}

void vec_hys(VECTOR* pvec, var vHys)
{
	if (abs(pvec->x) < vHys) pvec->x = 0;
	if (abs(pvec->y) < vHys) pvec->y = 0;
	if (abs(pvec->z) < vHys) pvec->z = 0;
}

void vec_clamp(VECTOR* pvec, var vMinLim, var vMaxLim)
{
	clamp (pvec->x, vMinLim, vMaxLim);	
	clamp (pvec->y, vMinLim, vMaxLim);	
	clamp (pvec->z, vMinLim, vMaxLim);	
}

void vec_cross(VECTOR* pvecN, VECTOR* pvec1, VECTOR* pvec2)
{
	pvecN->x = pvec1->y * pvec2->z - pvec1->z * pvec2->y;
	pvecN->y = pvec1->z * pvec2->x - pvec1->x * pvec2->z;
	pvecN->z = pvec1->x * pvec2->y - pvec1->y * pvec2->x;	
}



The vec_hys function should be improved as it currently only check hysteresis around 0.

I like the bool stuff and think I'll add it to my acklib.

Re: Handy defines [Re: FBL] #304132
01/05/10 09:49
01/05/10 09:49
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
if we're going for functions, I always add these two to my projects, then put on_f3 = saveScreenshot; in my main function.

spares you the whole process of printing, then pasting a screen and saves the screens according to the date into a subfolder callsed "screenshot".

Code:
STRING* getTime()
{
	STRING* theTime = str_create("");
	str_cat_num(theTime,"%.0f",sys_year);
	str_cat(theTime,"_");
	str_cat_num(theTime,"%02.0f",sys_month);
	str_cat(theTime,"_");
	str_cat_num(theTime,"%02.0f",sys_day);
	str_cat(theTime,"-");
	str_cat_num(theTime,"%02.0f",sys_hours);
	str_cat(theTime,"_");
	str_cat_num(theTime,"%02.0f",sys_minutes);
	return(theTime);
	//	str_remove(theTime);
}


void saveScreenshot()
{
	STRING* fileName = str_create("");
	
	str_cpy(save_dir,"Screenshots");
	
	STRING* theTime = getTime();
	
	str_cpy(fileName,theTime);		//append the current time
	str_cat(fileName,"_");
	str_cat(fileName,".png");
	
	//	str_cpy(fileName,"test.jpg");
	
	file_for_screen(fileName,sys_seconds);
	
	str_cpy(save_dir,"");
	str_remove(theTime);
	str_remove(fileName);
}



Sorry, I don't have many of those nice defines either. None that you haven't mentioned already, except that I often define names for certain values


~"I never let school interfere with my education"~
-Mark Twain
Re: Handy defines [Re: Germanunkol] #304148
01/05/10 12:00
01/05/10 12:00
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Functions are fine as well laugh. Nice stuff. Keep it coming ^^.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Handy defines [Re: Joozey] #304168
01/05/10 15:38
01/05/10 15:38
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
I always end up using one function from the RUDI library's made by HeelX:

Code:
// returns smallest angle
// function borrowed from RUDI open-source project
VECTOR* ang_lerp(VECTOR* resultVec, VECTOR* srcVec, VECTOR* destVec, var blendFactor)
{
	VECTOR ANG_LERP_VEC; // calculation vector
	vec_set(ANG_LERP_VEC, nullvector);
	
	vec_set(resultVec, srcVec);						// Copy source into result
	vec_diff(ANG_LERP_VEC, destVec, resultVec);  // Difference vector

	ANG_LERP_VEC.x = ang(ANG_LERP_VEC.x);			// Adjust angle validity
	ANG_LERP_VEC.y = ang(ANG_LERP_VEC.y);
	ANG_LERP_VEC.z = ang(ANG_LERP_VEC.z);

	vec_scale(ANG_LERP_VEC.x, blendFactor);		// Interpolate the rotation
	vec_add(resultVec, ANG_LERP_VEC);				// Apply interpolated angle

	return(resultVec);									// Return result angle
}



To me, most definatly the most usefull snippet i found in ages laugh
(again, thanks HeelX... if you read this :P)

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Handy defines [Re: Helghast] #304193
01/05/10 17:34
01/05/10 17:34
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
lol, I still use pretty much the same code from the same guy^^. Thanks from me as well!


~"I never let school interfere with my education"~
-Mark Twain
Re: Handy defines [Re: Germanunkol] #304286
01/06/10 13:05
01/06/10 13:05
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline
Senior Member
Razoron  Offline
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
I made a single script file for functions like these:
Code:
function ent_scale(ENTITY*ent,var factor)
{
 ent.scale_x=factor;
 ent.scale_y=factor;
 ent.scale_z=factor;
}

function ent_pos(ENTITY*ent,var posx,var posy,var posz)
{
 ent.x=posx;
 ent.y=posy;
 ent.z=posz;
}

function pan_scale(PANEL*pnl, var factor)
{
 pnl.scale_x=factor;
 pnl.scale_y=factor;
}

function pan_pos(PANEL*pnl, var posx, var posy)
{
 pnl.pos_x=posx;
 pnl.pos_y=posy;
}

function pan_color(PANEL*pnl, var cred, var cgreen, var cblue)
{
 pnl.red=cred;
 pnl.green=cgreen;
 pnl.blue=cblue;
}



Re: Handy defines [Re: Razoron] #304399
01/07/10 13:32
01/07/10 13:32
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
Hey Guys, very nice snippets i found here! So this is my input for you:

I allways use the following functions to place panels (or other objects) on the screen to have no problems with any resolution. For this I need a information with this format:
pos > 0 --> positioning from the left/top
pos < 0 --> positioning from the right/bottom
pos > -1 && pos < 1 --> positioning percental from the given border (see above)

some examples:
100 --> 100pixels freespace from the left/top
-75 --> 75pixels freespace from the right/bottom
-0.2 --> 20% freespace from the right/bottom

hope you get it... sry for my plain english

Code:
var parsePosX(PANEL *panTemp, var posX) {
	
	var tempPosX = posX;
	if(posX > 0 && posX < 1) { tempPosX = screen_size.x * posX; }
	if(posX < 0 && posX > -1) { tempPosX = screen_size.x + screen_size.x*posX - panTemp.size_x; }
	if(posX <= -1) { tempPosX = screen_size.x + posX - panTemp.size_x; }
	
	return tempPosX;
}


var parsePosY(PANEL *panTemp, var posY) {
	
	var tempPosY = posY;
	if(posY > 0 && posY < 1) { tempPosY = screen_size.y * posY; }
	if(posY < 0 && posY > -1) { tempPosY = screen_size.y + screen_size.x*posY - panTemp.size_y; }
	if(posY <= -1) { tempPosY = screen_size.y + posY - panTemp.size_y; }
	
	return tempPosY;
}



Re: Handy defines [Re: GorNaKosh] #304501
01/08/10 13:17
01/08/10 13:17
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
@GorNaKosh:

-0.2 --> 20% freespace from the right/bottom

a good idea, i implement it to my project.

Page 1 of 2 1 2

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