IT Technology

ubuntu 18.04中netplan配置pre-up和post-down

  1. netplan 自身配置文件/etc/netplan/50-cloud-init.yaml
network:
    version: 2
    renderer: networkd
    ethernets:
        ens3:
            addresses:
            - 154.204.42.134/24
            gateway4: 154.204.42.254
            match:
                macaddress: fa:16:3e:b9:65:3b
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
            set-name: ens3

应用修改

sudo netplan apply

阅读全文»

Unity 摄像机射线碰撞

需要对象挂有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);//碰撞坐标
    }
}

Unity 点与平面交点计算函数

参考
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;
    }
}

TMX调试object数据点调试代码

unsigned int length = pointsArray.size(); // XXX
cocos2d::Vec2 *points = new cocos2d::Vec2[length];//XXX
int cnt = 0;// XXX
for (auto& p : pointsArray) {
    ValueMap &a = p.asValueMap();
    Vec2 *th = &points[cnt];//xxx
    th->x = a["x"].asFloat();//xxx
    th->y = a["y"].asFloat();//xxx
    cnt++;//xxx
}
DrawNode *node = DrawNode::create();
node->drawPoly(points, length, true, Color4F(1, 0, 0, 1));
addChild(node);
node->setPosition(xPos);
float rotation = 0;
if (dict.find("rotation") != dict.end()) {
    rotation = dict["rotation"].asFloat();
}
node->setRotation(rotation);
// set data for sort
Vec2 *data = new Vec2(xPos);
node->setUserData((void *)data);

luasokcet直接调用tcp代码备份

int family = iterator->ai_family;
t_socket sock;
const char *err = inet_trycreate(&sock, family, SOCK_STREAM);
if (err) {
    continue; // check next
} else {
    t_timeout tm;
    struct addrinfo connecthints;
    memset(&connecthints, 0, sizeof(connecthints));
    connecthints.ai_socktype = SOCK_STREAM;
    /* make sure we try to connect only to the same family */
    connecthints.ai_family = family;
    
    if (family == PF_INET6) {
        int yes = 1;
        setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes));
    }
    timeout_markstart(&tm);
    err = inet_tryconnect(&sock, &family, (const char *)hbuf, "3006", &tm, &connecthints);
    if (err) {
        socket_destroy(&sock);
        continue; // check next
    } else {
        // find success one
        CCLOG("== xx:%s", hbuf);
    }
}