还是回来写代码了 - idle

还是回来写代码了

views63 posted @ 2015年7月07日 23:29 in II with tags Lua C# 为工具所累 工作? , 1908 阅读

毫无准备的情况下成了游戏 lua 脚本,然后就写了自己的第一段代码。

	-- begin 加速表现
	local tBuilderDate = GetBuilderDataMgr():GetBuilderList()  -- 获取建筑的数据
	for i, v in ipairs(tBuilderDate) do
		if v.nSpeedTime ~= nil and v.nSpeedTime > 0  then 
			local id = v.idBuild
			local SpeedFlag = false
			if tSpeedID ~= nil then  --begin 防止重复添加光效
				for j,k in ipairs(tSpeedID) do
					if k.idBuild == id then
					SpeedFlag = true
					break
					end
				end
			end	 --end 防止重复添加光效
			local oBuiler = g_sPlayerManager:getBuilder(v.idBuild)	--处理光效
			if SpeedFlag == false and  oBuiler then
				SpeedEffectID = oBuiler:getModel():addEffect("heroLottery", -1, -1) --添加光效
				v.nSpeedTime = v.idBuild * 10  --临时测试数据,服务器上的数值太大不便测试
				local tSpeedInfoInfo = {idBuild = v.idBuild, nSpeedTime = v.nSpeedTime, FormatTime = nil, SpeedEffectID = SpeedEffectID}
				table.insert(tSpeedID, tSpeedInfoInfo) --tSpeedID 初始为空,是 tSpeedInfoInfo 的集合
				g_sEventManager:registerTimeoutEvent(1000, true, "SpeedBuilder_ProgressBar_Callback")	--计时器回调 参数 间隔时间,是否循环,回调函数名
			end
		end
	end	
	--end 加速表现

类似这种,一写就是半年多(去年打的草稿,现在翻出来),接着又是 C#。这一年多来过得比以往感觉都快,两点一线式的生活,上班-加班-下班。

最近因为工作遇到,再去看了一下 Bezier 曲线,发现网上广为流传的一段代码貌似有问题

using UnityEngine; 

[System.Serializable] 
public class Bezier : System.Object
 
{
 
    public Vector3 p0;
 
    public Vector3 p1;
 
    public Vector3 p2;
 
    public Vector3 p3;
 
    public float ti = 0f;
 
    private Vector3 b0 = Vector3.zero;
 
    private Vector3 b1 = Vector3.zero;
 
    private Vector3 b2 = Vector3.zero;
 
    private Vector3 b3 = Vector3.zero;
 
    private float Ax;
 
    private float Ay;
 
    private float Az;
 
    private float Bx;
 
    private float By;
 
    private float Bz;
 
    private float Cx;
 
    private float Cy;
 
    private float Cz;
 
    // Init function v0 = 1st point, v1 = handle of the 1st point , v2 = handle of the 2nd point, v3 = 2nd point
 
    // handle1 = v0 + v1
 
    // handle2 = v3 + v2
 
    public Bezier( Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3 )
 
    {
 
        this.p0 = v0;
 
        this.p1 = v1;
 
        this.p2 = v2;
 
        this.p3 = v3;
 
    }
 
    // 0.0 >= t <= 1.0
 
    public Vector3 GetPointAtTime( float t )
 
    {
 
        this.CheckConstant();
 
        float t2 = t * t;
 
        float t3 = t * t * t;
 
        float x = this.Ax * t3 + this.Bx * t2 + this.Cx * t + p0.x;
 
        float y = this.Ay * t3 + this.By * t2 + this.Cy * t + p0.y;
 
        float z = this.Az * t3 + this.Bz * t2 + this.Cz * t + p0.z;
 
        return new Vector3( x, y, z );
 
    }
 
    private void SetConstant()
 
    {
 
        this.Cx = 3f * ( ( this.p0.x + this.p1.x ) - this.p0.x );
 
        this.Bx = 3f * ( ( this.p3.x + this.p2.x ) - ( this.p0.x + this.p1.x ) ) - this.Cx;
 
        this.Ax = this.p3.x - this.p0.x - this.Cx - this.Bx;
 
        this.Cy = 3f * ( ( this.p0.y + this.p1.y ) - this.p0.y );
 
        this.By = 3f * ( ( this.p3.y + this.p2.y ) - ( this.p0.y + this.p1.y ) ) - this.Cy;
 
        this.Ay = this.p3.y - this.p0.y - this.Cy - this.By;
 
        this.Cz = 3f * ( ( this.p0.z + this.p1.z ) - this.p0.z );
 
        this.Bz = 3f * ( ( this.p3.z + this.p2.z ) - ( this.p0.z + this.p1.z ) ) - this.Cz;
 
        this.Az = this.p3.z - this.p0.z - this.Cz - this.Bz;
 
    }
 
    // Check if p0, p1, p2 or p3 have changed
 
    private void CheckConstant()
 
    {
 
        if( this.p0 != this.b0 || this.p1 != this.b1 || this.p2 != this.b2 || this.p3 != this.b3 )
 
        {
 
            this.SetConstant();
 
            this.b0 = this.p0;
 
            this.b1 = this.p1;
 
            this.b2 = this.p2;
 
            this.b3 = this.p3;
 
        }
 
    }
 
}

不知作者处于何种目的考虑 SetConstant 中那些可以化简的式子一个都没化简,而且写的非常绕,例如 

this.Cx = 3f * ( ( this.p0.x + this.p1.x ) - this.p0.x );

不能化简成如下结果?

 this.Cx = 3f *this.p1.x;

不过好像大家都不在意这些,这段代码网上到处可见,也用得“好好的”。

自己化简了下,应该可以写成下面这样。

Func<Vector3, Vector3, Vector3, Vector3, Func<float, Vector3>> GetBezierPoint = (a, b, c, d) => t => a + (-3 * a + 3 * b) * t + (3 * a - 6 * b + 3 * c) * t * t + (-a + 3 * b - 3 * c + d) * t * t * t;
我为卿狂 说:
2015年7月08日 12:39

看来你真的很忙,只有在忙碌中才感觉时间过得很快。

Avatar_small
views63 说:
2015年7月08日 15:39

@我为卿狂: 当初不想做程序员这也是很重要的一个原因。反过来也说明自己能力很一般,程序员做得很吃力

seoservise 说:
2021年9月12日 22:15

Find the best essays on is my friend's profile page. Babies first birthday gift

seoservise 说:
2021年9月14日 22:19

Keep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information. Thanks for your valuable efforts. Website

NCERT GK Sample Pape 说:
2022年9月17日 01:05

GK stands for General knowledge which was introduced as one of the subjects. It is beginning from the foundation education to help the students by getting minimum knowledge. GK also play a key role in competitive examinations, NCERT GK Sample Paper Class 2 that’s the way NCERT included General knowledge is a subject that everyone should know and learn from Primary Education.Downloading NCERT GK Sample Paper 2023 Class 2 utilizes candidates who have to know the new examination pattern and want to get high scores smoothly for all formats of exams conducted in Term-1, Term-2 such as SA-1, SA-2, FA-1, FA-2, FA-3, FA-4, Assignments and other types of exams to Hindi Medium, English medium and Urdu Medium students.

ekhan.net 说:
2023年4月16日 14:42

How to Update/Register Your Cell Number with Indian Overseas Bank, The Reserve Bank of India’s guidelines are followed by the national bank Indian Overseas Bank. The bank has been providing its clients in the public banking sector with a wealth of convenient services and amenities. Indian Overseas Bank (IOB) Mobile Banking Registration, How to Update/Register Your Cell Number with Indian Overseas Bank, The Reserve Bank of India’s guidelines are followed by the national bank Indian Overseas Bank. ekhan.net The bank has been providing its clients in the public banking sector with a wealth of convenient services and amenities. Indian Overseas Bank (IOB) Mobile Banking Registration.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter
Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee