This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:orx:reference:math:snippets [2014/11/28 02:30 (11 years ago)] – Added OrxOBox and OrxVector snippets sausage | en:orx:reference:math:snippets [2018/01/19 08:45 (8 years ago)] (current) – Moved to examples. Deleted. sausage | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Math: Code Snippets ====== | ||
- | ===== OrxAABox ===== | ||
- | |||
- | ===== OrxMath ===== | ||
- | |||
- | Convert an angle in degrees to a directional vector | ||
- | |||
- | < | ||
- | orxFLOAT degRotation = 45; | ||
- | orxFLOAT radRotation = degRotation * orxMATH_KF_DEG_TO_RAD; | ||
- | |||
- | orxFLOAT x = orxMath_Cos(radRotation); | ||
- | orxFLOAT y = orxMath_Sin(radRotation); | ||
- | |||
- | orxVECTOR directionVector = {x, y, 0}; | ||
- | </ | ||
- | |||
- | ===== OrxOBox ===== | ||
- | |||
- | Function to return an object within a boxed area: | ||
- | |||
- | < | ||
- | orxOBJECT* GetObjectInTheArea(){ | ||
- | |||
- | orxVECTOR objectPickVector; | ||
- | objectPickVector.fX = 878; | ||
- | objectPickVector.fY = 1185; | ||
- | objectPickVector.fZ = -1.0; | ||
- | | ||
- | orxOBOX objectBoxArea; | ||
- | | ||
- | orxVECTOR pivot = {0, 0, 0}; | ||
- | | ||
- | orxVECTOR position; | ||
- | position.fX = 834; | ||
- | position.fY = 1150; | ||
- | position.fZ = -0.1; | ||
- | | ||
- | orxVECTOR size; | ||
- | size.fX = 21; | ||
- | size.fY = 160; | ||
- | size.fZ = 1; | ||
- | | ||
- | orxOBox_2DSet(& | ||
- | | ||
- | orxU32 objectGroupID = orxCamera_GetGroupID(pstCamera, | ||
- | | ||
- | orxOBJECT *objectToFind = orxObject_BoxPick(& | ||
- | return objectToFind; | ||
- | | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | ===== OrxVector ===== | ||
- | |||
- | Some ways to initialise an empty orxVECTOR. | ||
- | |||
- | Avoid this: | ||
- | orxVECTOR position; | ||
- | |||
- | Rather, do one of these: | ||
- | |||
- | orxVECTOR position = {0, 0, 0}; | ||
- | |||
- | orxVECTOR position = orxVECTOR_0; | ||
- | |||
- | orxVECTOR position; | ||
- | position.fX = 0; | ||
- | position.fY = 0; | ||
- | position.fZ = 0; | ||
- | |||
- | Uninitialised orxVECTORs can create unintended consequences in your game. | ||
- | |||
- | You can also do: | ||
- | |||
- | {{section> | ||
- | |||