|
0 registered members (),
1,012
guests, and 8
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Handy defines and functions
#303310
12/27/09 23:37
12/27/09 23:37
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
OP
Expert
|
OP
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
I have a few I always use in a common.c file:
#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: Razoron]
#304097
01/04/10 23:47
01/04/10 23:47
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
Not defines, but some useful functions
/* 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
Expert
|
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".
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: Joozey]
#304168
01/05/10 15:38
01/05/10 15:38
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
I always end up using one function from the RUDI library's made by HeelX:
// 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  (again, thanks HeelX... if you read this :P) regards,
|
|
|
Re: Handy defines
[Re: Helghast]
#304193
01/05/10 17:34
01/05/10 17:34
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
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
Senior Member
|
Senior Member
Joined: May 2009
Posts: 445
Peine, Germany
|
I made a single script file for functions like these:
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
Junior Member
|
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
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;
}
|
|
|
|