Skip to content

Instantly share code, notes, and snippets.

@cuongmzq
cuongmzq / LowResScene.cpp
Created March 4, 2021 17:36 — forked from johngirvin/LowResScene.cpp
Cocos2D-X 2D Camera Test
#include "LowResScene.h"
NewCamera* NewCamera::createOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane)
{
auto ret = new (std::nothrow) NewCamera();
if (ret)
{
ret->initOrthographic(zoomX, zoomY, nearPlane, farPlane);
ret->autorelease();
return ret;
@cuongmzq
cuongmzq / bitwise-hacks.js
Created February 14, 2021 06:19 — forked from leodutra/bitwise-hacks.js
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;
@cuongmzq
cuongmzq / fastTrig.as
Created February 13, 2021 16:34 — forked from geraldyeo/fastTrig.as
Fast and accurate sine/cosine approximation
//1.27323954 = 4/pi
//0.405284735 =-4/(pi^2)
/*********************************************************
* low precision sine/cosine
*********************************************************/
//always wrap input angle to -PI..PI
if (x < -3.14159265)
x += 6.28318531;
@cuongmzq
cuongmzq / atan2_approximation.c
Created February 13, 2021 11:58 — forked from volkansalma/atan2_approximation.c
optimized atan2 approximation
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float atan2_approximation1(float y, float x);
float atan2_approximation2(float y, float x);
int main()
{
float x = 1;
@cuongmzq
cuongmzq / RotatedRectangle.cs
Created October 19, 2020 07:05 — forked from jackmott/RotatedRectangle.cs
Rotated rectangle collision detection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
//Faster linq-style convenience functions https://github.com/jackmott/LinqFaster
using JM.LinqFaster;
namespace DrawAndDrive
{
@cuongmzq
cuongmzq / service.objectPool.js
Created October 15, 2020 16:43 — forked from bartread/service.objectPool.js
Simple JavaScript object pool implementation with some validation in place - depends on pinjector.js
(function () {
'use strict';
pinjector
.module('starCastle')
.factory(
'objectPool',
[
objectPool
]);
class PoolObject {
constructor(data) {
this.data = data;
this.nextFree = null;
this.previousFree = null;
}
}
class Pool {
constructor(objCreator, objReseter, initialSize = 5000) {
@cuongmzq
cuongmzq / ConfigurableJointExtensions.cs
Created August 20, 2020 17:02 — forked from mstevenson/ConfigurableJointExtensions.cs
Unity extension methods for computing a ConfigurableJoint.TargetRotation value from a given local or world rotation.
using UnityEngine;
public static class ConfigurableJointExtensions {
/// <summary>
/// Sets a joint's targetRotation to match a given local rotation.
/// The joint transform's local rotation must be cached on Start and passed into this method.
/// </summary>
public static void SetTargetRotationLocal (this ConfigurableJoint joint, Quaternion targetLocalRotation, Quaternion startLocalRotation)
{
if (joint.configuredInWorldSpace) {
@cuongmzq
cuongmzq / PhysicsHelper.cs
Created August 20, 2020 17:02 — forked from ditzel/PhysicsHelper.cs
Unity Helper for Physic Functions
using UnityEngine;
namespace Ditzelgames
{
public static class PhysicsHelper
{
public static void ApplyForceToReachVelocity(Rigidbody rigidbody, Vector3 velocity, float force = 1, ForceMode mode = ForceMode.Force)
{
if (force == 0 || velocity.magnitude == 0)