u0u0 发布的文章

需求:自动打包文件夹下的所有图片,如果超单纹理大小,自动拆分为多个文件。

TexturePacker  --multipack --texture-format png --format cocos2d --max-width 2048 --max-height 2048 --data {n}.plist --sheet {n}.png /target/rootDirOfPng

注意:rootDirOfPng不会被加入帧名,旗下的二级目录会加入。

2D 中 (C)
参考:https://www.cnblogs.com/yushuo/p/9304218.html

//点PCx,PCy到线段PAx,PAy,PBx,PBy的距离
double GetNearestDistance(double PAx, double PAy,double PBx, double PBy,double PCx, double PCy)
{     
    double a,b,c;  
    a=getDistanceBtwP(PAy,PAx,PBy,PBx);//经纬坐标系中求两点的距离公式
    b=getDistanceBtwP(PBy,PBx,PCy,PCx);//经纬坐标系中求两点的距离公式
    c=getDistanceBtwP(PAy,PAx,PCy,PCx);//经纬坐标系中求两点的距离公式
    if(b*b>=c*c+a*a)return c;   
    if(c*c>=b*b+a*a)return b;  
    double l=(a+b+c)/2;     //周长的一半   
    double s=sqrt(l*(l-a)*(l-b)*(l-c));  //海伦公式求面积 
    return 2*s/a;   
}

3D 中(C#)
参考:https://www.jianshu.com/p/8ba826e6208a

public static float distancePoint2Line(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)
{
    float fProj = Vector3.Dot(point - linePoint1, (linePoint1 - linePoint2).normalized);
    return Mathf.Sqrt((point - linePoint1).sqrMagnitude - fProj * fProj);
}

  1. 多摄像机支持不完整,慎用自定义摄像机渲染fairyGUI
    cameraMask实现不完整。类似Button的容器,内部有多个GObject,但是设置cameraMask只会设置到当前渲染的GObject的displayObject,其它状态的设置不到,异常尴尬。即使修正了setCameraMask,也会GComponent::hitTest的事件分发判断也是不可修正的,fairyRoot分发事件,但是fairyRoot永远是default摄像机,不能引用引擎currentCamera,导致hitTest不能正确判断点击区域。
  2. GList的setVirtualAndLoop之后,顺序有问题,可如下修正。但是循环滚动位置错乱的问题没有定位到原因。

    void GList::removeChildrenToPool(int beginIndex, int endIndex)
    {
        if (endIndex < 0 || endIndex >= _children.size())
            endIndex = (int)_children.size() - 1;
    #if 1
        // fix item order: returnToPool() use push, and getObject() use pop, the order will broken
        for (int i = endIndex; i >= beginIndex; --i)
            removeChildToPoolAt(i);
    #else
        // backup old codes
        for (int i = beginIndex; i <= endIndex; ++i)
            removeChildToPoolAt(beginIndex);
    #endif
    }

需要对象挂有Collider组件才能计算射线,某些情况下不适用。

if (Input.GetMouseButtonDown(0))
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //从摄像机发出到点击坐标的射线
    RaycastHit hit;
    if (Physics.Raycast(ray, out hit)) //需要有Collider组件才能碰撞到
    {
        Debug.Log(hit.point);//碰撞坐标
    }
}

参考
https://blog.csdn.net/abcjennifer/article/details/6688080

public static class MyUtils
{
    /*
     * 求一条直线与平面的交点
     * [param] planeVector, 平面的法线向量.
     * [param] planePoint, 平面经过的一点坐标.
     * [param] lineVector, 直线的方向向量.
     * [param] linePoint, 直线经过的一点坐标.
     * [returns] 是否想交, rtn 是交点坐标.
     */
    public static bool PlaneLineIntersectPoint(ref Vector3 planeVector, ref Vector3 planePoint, ref Vector3 lineVector, ref Vector3 linePoint, out Vector3 rtn)
    {
        float vp1, vp2, vp3, n1, n2, n3, v1, v2, v3, m1, m2, m3, t, vpt;
        vp1 = planeVector.x;
        vp2 = planeVector.y;
        vp3 = planeVector.z;
        n1 = planePoint.x;
        n2 = planePoint.y;
        n3 = planePoint.z;
        v1 = lineVector.x;
        v2 = lineVector.y;
        v3 = lineVector.z;
        m1 = linePoint.x;
        m2 = linePoint.y;
        m3 = linePoint.z;

        vpt = v1 * vp1 + v2 * vp2 + v3 * vp3; //点乘
        //首先判断直线是否与平面平行(正确的浮点判断0方式)
        if (Math.Abs(vpt) <= 0.000001f)
        {
            rtn.x = rtn.y = rtn.z = 0;
            return false;
        }

        t = ((n1 - m1) * vp1 + (n2 - m2) * vp2 + (n3 - m3) * vp3) / vpt;
        rtn.x = m1 + v1 * t;
        rtn.y = m2 + v2 * t;
        rtn.z = m3 + v3 * t;
        return true;
    }
}

display.newSprite("hideback.png"):addTo(self):center()

local render = cc.RenderTexture:create(display.width, display.height):center():addTo(self)
local sp = cc.Sprite:create("HelloWorld.png"):center()

render:begin()
sp:visit()
render:endToLua()

local circle = display.newSolidCircle(20,{color = cc.c4f(0.5, 0.5, 0.5, 0)})
circle:retain()
circle:setBlendFunc(cc.blendFunc(cc.backendBlendFactor.SRC_ALPHA, cc.backendBlendFactor.ZERO))

self:addNodeEventListener(cc.NODE_TOUCH_EVENT,function ( event )
    if event.name == "began" then
        return true
    end

    if event.name == "moved" then
        circle:pos(event.x,event.y)
        render:begin()
        circle:visit()
        render:endToLua()
    end
end)
self:setTouchEnabled(true)