场景坐标系z坐标的实现,x与y的夹角为多少?

这篇博客探讨了在游戏或应用开发中如何进行坐标系转换,从cell坐标系到屏幕坐标系,再到世界坐标系的过程。涉及到关键函数如getTileCenterPosition、screenToIso和isoToScreen,以及坐标轴的调整和缩放。此外,还讨论了坐标边界值对屏幕滚动的影响。
摘要由CSDN通过智能技术生成

1. cell坐标系(场景的边界值)

(rect.xStart, rect.yStart) 0 ,-80

(rect.xEnd, rect.yEnd) 250 ,210

 cell坐标系一个是个瓷砖组成,通过瓷砖中心点,经过缩放得到屏幕坐标(坐标轴垂直屏幕的)

static Core::IPoint getTileCenterPosition(int x, int y) { return Core::IPoint(70 * (x + y + 1)/2, 35 * (x - y) / 2); }

        scrollInGarden.xStart = CoordinateSystem().getTileCenterPosition(rect.xStart, rect.yStart).x  - 300.f;   //подобрано эмпирически
        scrollInGarden.xEnd = CoordinateSystem().getTileCenterPosition(rect.xEnd, rect.yEnd).x ;

        scrollInGarden.yStart = CoordinateSystem().getTileCenterPosition(rect.xStart, rect.yEnd).y  - 150.f; //подобрано эмпирически
        scrollInGarden.yEnd = CoordinateSystem().getTileCenterPosition(rect.xEnd, rect.yStart).y  ;

crollInGarden.xStart, scrollInGarden.yStart, scrollInGarden.xEnd, scrollInGarden.yEnd

left,bottom,right,top

-3065,-3825,16135,5775

cell(x,y)

screen(x,y)

bound(x,y)(网格中使用)

(0 ,-80)

(-2800,1400)

(0,68)

(250 ,210)

(16100,700)

(255,59)

(0,210)

(7350,-3675)

(137,0)

(250,-80)

(5950,5775)

(118,128)

 

 

2. 屏幕坐标系(坐标轴平行屏幕的)

红色坐标

 屏幕坐标系经过ScreenToIso转换成世界坐标系


void screenToIso(float& x, float& y, float &z){
    float screenX = x;
    float screenY = y - z;

    isoX = -0.5f * screenX + -1.0f * screenY;
    isoY = 0.5f * screenX + -1.0f * screenY;
}

 2. 世界坐标系(实现z坐标)

两个蓝色坐标轴和一个红色坐标轴

 世界坐标系经过转换可以变为屏幕坐标系

void isoToScreen(float& x, float& y, float &z){
    float isoX = x;
    float isoY = y;

    screenX = -1.0f * isoX + 1.0f * isoY;
    screenY = -0.5f * isoX + -0.5f * isoY + z;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值