| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 518 人关注过本帖
标题:大牛在哪?求个算法!
取消只看楼主 加入收藏
xuenimabia
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-9-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
大牛在哪?求个算法!
小弟目前在开发一款三星盖世3上的墙纸(深海水母),要实现的功能是手机屏幕内随即有几个大小不一的水母,水母运行的速度、距离、方向均随即的。其运行轨迹就是一个布朗运动。
小弟目前的算法有问题,水母的运动轨迹的随即率比较单一(水母的速度、方向)。下面是小弟的算法部分代码,求大牛改进,将真正的布朗运动效果加进来。效果源图也贴一张。

#define JS_NUMBER    10
#define JS_ANGLE        3600
typedef struct
{
    int curr_x;//当前x轴坐标
    int curr_y;//当前y轴坐标
    int curr_z;//当前z轴坐标
    int curr_angle;//当前的旋转角度
    int vx;//x轴的速度
    int vy;//y轴的速度
    int vz;//z轴的速度
    int vangle;//角度的旋转速度
    int ax;//x轴的加速度
    int ay;//y轴的加速度
    int az;//z轴的加速度
    int aangle;//角度的加速度
    int rx;//x轴的阻力
    int ry;//y轴的阻力
    int rz;//z轴的阻力
    int rangle;//角度旋转的阻力
    int flotage_x;//x轴的浮力
    int flotage_y;//y轴的浮力
    int flotage_z;//在轴的浮力
    int flotage_angle;//角度的浮力
    int js_total_time;//水母运动的总时间
    int js_run_time;//当前水母运行的时间
    bool js_is_active;//水母是否已经激活在运行
    bool is_outside;//水母是否在屏幕之外(320*480的分辨率)
}JS_INFO_T;

void Update(COLOR16 *target_buf_ptr, uint16 scr_width, uint16 scr_height)
{
    IMGREF_SIZE_T    js_bg_window = {0,0};
    IMGREF_POINT_T    window_mid =  {0,0};
    IMGREF_SIZE_T    js_up_window = {0,0};
    IMGREF_POINT_T    img_mid = {0,0};
    int    index = 0;
   
    if(PNULL == target_buf_ptr)
    {
        return;
    }

    js_bg_window.w = scr_width;
    js_bg_window.h = scr_height;

    js_up_window.w = js_layer_info_ptr.layer_width;
    js_up_window.h = js_layer_info_ptr.layer_height;

    img_mid.x = (js_up_window.w-1)/2;
    img_mid.y = (js_up_window.h-1)/2;
   
    for(index = 0;index < JS_NUMBER;index++)
    {
        if(!js_life_parm[index].js_is_active)//未激活进行初始化
        {
            js_life_parm[index].flotage_y = 0;            
            if(2 == rand()%50)
            {
                js_life_parm[index].js_is_active = TRUE;
                js_life_parm[index].js_run_time = 0;
                js_life_parm[index].js_total_time = rand()%50+150;
               
                js_life_parm[index].ax = rand()%30+5;
                if(js_life_parm[index].ax%2)
                {
                    js_life_parm[index].ax=-js_life_parm[index].ax;
                }   
                js_life_parm[index].vx = 0;
                js_life_parm[index].rx = 0;
            
                js_life_parm[index].ay = rand()%30+5;
                if(js_life_parm[index].ay%2)
                {
                    js_life_parm[index].ay=-js_life_parm[index].ay;
                }
                js_life_parm[index].vy = 0;
                js_life_parm[index].ry = 0;
            
                js_life_parm[index].az = rand()%50+80;
                if(js_life_parm[index].az%2)
                {
                    js_life_parm[index].az=-js_life_parm[index].az;
                }
                js_life_parm[index].vz = 0;
                js_life_parm[index].rz = 0;
            
                js_life_parm[index].aangle = rand()%15+30;
                if(js_life_parm[index].aangle%2)
                {
                    js_life_parm[index].aangle = -js_life_parm[index].aangle;
                }
                js_life_parm[index].vangle = 0 ;
                js_life_parm[index].rangle = 0;
            }
        }
        if((scr_width+JS_BG_SIZE) < js_life_parm[index].curr_x
            || (scr_height+JS_BG_SIZE) < js_life_parm[index].curr_y
            || js_life_parm[index].curr_x < (0-JS_BG_SIZE)
            || js_life_parm[index].curr_y < (0-JS_BG_SIZE))//如果运行出屏幕之外的处理
        {
            js_life_parm[index].is_outside = TRUE;
            
            js_life_parm[index].ax = -js_life_parm[index].ax;
            js_life_parm[index].vx = -js_life_parm[index].vx;
            js_life_parm[index].vx += rand()%10+5;
            

            js_life_parm[index].ay = -js_life_parm[index].ay;
            js_life_parm[index].vy = -js_life_parm[index].vy;
            js_life_parm[index].vy += rand()%10+5;

            js_life_parm[index].az = -js_life_parm[index].az;
            js_life_parm[index].vz = -js_life_parm[index].vz;
            js_life_parm[index].vz += rand()%10+5;

            js_life_parm[index].aangle = -js_life_parm[index].aangle;
            js_life_parm[index].vangle = -js_life_parm[index].vangle;
            js_life_parm[index].vangle+= rand()%10+5;
            
            
            if (js_life_parm[index].js_run_time >= js_life_parm[index].js_total_time)
            {
                js_life_parm[index].rx = -js_life_parm[index].vx/60;
                js_life_parm[index].ry = -js_life_parm[index].vy/60;
                js_life_parm[index].rz = -js_life_parm[index].vz/50;
                js_life_parm[index].rangle = -js_life_parm[index].vangle/60;
            }
        }
        
        if(js_life_parm[index].js_is_active)//已经激活,开始运动
        {
            if(js_life_parm[index].js_run_time < js_life_parm[index].js_total_time)
            {
                js_life_parm[index].js_run_time++;
               
                js_life_parm[index].curr_x += js_life_parm[index].vx;//当前的坐标等于当前坐标加上本身的速度
                js_life_parm[index].vx += js_life_parm[index].ax;//速度等于本身的速度加上本身的加速度

                js_life_parm[index].curr_y += js_life_parm[index].vy;
                js_life_parm[index].vy += js_life_parm[index].ay;

                js_life_parm[index].curr_z += js_life_parm[index].vz;
                js_life_parm[index].vz += js_life_parm[index].az;

                js_life_parm[index].curr_angle += js_life_parm[index].vangle;
                js_life_parm[index].vangle += js_life_parm[index].aangle;
                                
                if(js_life_parm[index].js_run_time == js_life_parm[index].js_total_time/2)//如果运行时间是总时间的一半,开始减速,rx是阻力
                {
                    js_life_parm[index].rx = -js_life_parm[index].vx/30;
                    js_life_parm[index].ry = -js_life_parm[index].vy/30;
                    js_life_parm[index].rz = -js_life_parm[index].vz/30;
                    js_life_parm[index].rangle = -js_life_parm[index].vangle/20;
                 }
            }
            else
            {
                if(abs(js_life_parm[index].vx) > abs(js_life_parm[index].rx))
                {
                    js_life_parm[index].curr_x+= js_life_parm[index].vx;
                    js_life_parm[index].vx+= js_life_parm[index].rx;

                }
                else
                {
                    js_life_parm[index].js_is_active = FALSE;
                    js_life_parm[index].js_total_time = rand()%100+50;
                    js_life_parm[index].js_run_time = 0;
                }
               
                if(abs(js_life_parm[index].vy) > abs(js_life_parm[index].ry))
                {
                    js_life_parm[index].curr_y += js_life_parm[index].vy;
                    js_life_parm[index].vy += js_life_parm[index].ry;
                }
                else
                {
                    js_life_parm[index].js_is_active = FALSE;
                    js_life_parm[index].js_total_time = rand()%100+50;
                    js_life_parm[index].js_run_time = 0;
                }

                if(abs(js_life_parm[index].vz) > abs(js_life_parm[index].rz))
                {
                    js_life_parm[index].curr_z += js_life_parm[index].vz;
                    js_life_parm[index].vz += js_life_parm[index].rz;
                }
                else
                {
                    js_life_parm[index].js_run_time = 0;
                    js_life_parm[index].js_total_time = rand()%100+50;
                    js_life_parm[index].js_is_active = FALSE;
                }

                if(abs(js_life_parm[index].vangle) > abs(js_life_parm[index].rangle))
                {
                    js_life_parm[index].curr_angle += js_life_parm[index].vangle;
                    js_life_parm[index].vangle += js_life_parm[index].rangle;
                }
                else
                {
                    js_life_parm[index].js_run_time = 0;
                    js_life_parm[index].js_total_time = rand()%100+50;
                    js_life_parm[index].js_is_active = FALSE;
                }
            }
        }
        else
        {
            js_life_parm[index].flotage_x = 0;
            js_life_parm[index].flotage_y = rand()%3+3;
            js_life_parm[index].flotage_z = 0;
            js_life_parm[index].flotage_angle = 0;
            js_life_parm[index].curr_y += js_life_parm[index].vy;
            js_life_parm[index].vy += js_life_parm[index].flotage_y;
         }
            
        window_mid.x = js_life_parm[index].curr_x;
        window_mid.y = js_life_parm[index].curr_y;
        S2d_rotation_slim(js_bg_window,
                            js_up_window,
                            window_mid,        //根据此参数实时在屏幕上绘制水母的位置
                            img_mid,
                            (js_life_parm[index].curr_angle)%JS_ANGLE,
                            (COLOR32 *)js_layer_info_ptr.layer_buf_ptr,//输入buf
                            target_buf_ptr,//屏幕上的输出buf
                            js_life_parm[index].curr_z,
                            g_point_add);
    }
}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 开发 三星盖世 算法 
2012-09-08 17:18
快速回复:大牛在哪?求个算法!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018637 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved