//触屏事件处理 void HelloWorld::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { //屏幕转换到射线 kmVec3 tPt; kmVec3 tDir; // 获取点在视图中的坐标 CCPoint touchLocation = touches[0]->getLocation(); auto visibleSize = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); //线条容器 std::vector<LightLineRender::Line> lines; //设置线条位置 //闪电的起点和终点 Vec2 tFishPos(Vec2(visibleSize / 2) + origin); tFishPos = m_FishLayer->GetSpritePosition() + origin; Vec3 segStart = Vec3(0,0,-8); Vec3 segEnd = Vec3(touchLocation.x - tFishPos.x ,touchLocation.y - tFishPos.y ,-8); //取得方向 Vec3 dir = segEnd - segStart ; float fLength = dir.length(); dir.normalize(); //顺时针转动45度形成一个偏移点做为第一个闪电链线段。 Vec3 rotate_left; Mat4 rotate_left_Mat; kmMat4RotationZ(&rotate_left_Mat,MATH_DEG_TO_RAD(-45)); kmVec3TransformCoord(&rotate_left,&dir,&rotate_left_Mat); rotate_left.normalize(); //逆时针转动45度形成一个偏移点做为第一个闪电链线段。 Vec3 rotate_right; Mat4 rotate_right_Mat; kmMat4RotationZ(&rotate_right_Mat,MATH_DEG_TO_RAD(45)); kmVec3TransformCoord(&rotate_right,&dir,&rotate_right_Mat); rotate_right.normalize(); //分成三段闪电链 Vec3 v1_s = segStart ; Vec3 v1_e = segStart + dir * fLength / 4.0 + rotate_left * (fLength / 6.0); Vec3 v2_s = v1_e ; Vec3 v2_e = segStart + dir * fLength / 2.0 + rotate_right * (fLength / 6.0); Vec3 v3_s = v2_e ; Vec3 v3_e = segEnd; lines.push_back( LightLineRender::Line( v1_s, v1_e, 0 ) ); lines.push_back( LightLineRender::Line( v2_s, v2_e, 0 ) ); lines.push_back( LightLineRender::Line( v3_s, v3_e, 0 ) ); //创建出闪光链 LightLineRender* _lighting = dynamic_cast<LightLineRender*>(getChildByTag(10)); //使用线段容器创建闪电链 _lighting->setLines( lines ); _lighting->setPosition(tFishPos); //这一句可以让闪电链在1秒内渐渐消隐。它通过调节Shader中的u_color值从1变为0来实现。 _lighting->OpenAlphaToZero(1.0); //击中乌龟,让乌龟翻身。 m_FishLayer->AttackWuGui(); }
void lite3d_bounding_vol_translate(struct lite3d_bounding_vol *volOut, const struct lite3d_bounding_vol *volIn, const struct kmMat4 *tr) { int i; //kmVec3 center; SDL_assert(volOut); SDL_assert(volIn); SDL_assert(tr); for (i = 0; i < 8; ++i) { kmVec3TransformCoord(&volOut->box[i], &volIn->box[i], tr); } kmVec3TransformCoord(&volOut->sphereCenter, &volIn->sphereCenter, tr); /* TODO: calculate radius */ //kmVec3Subtract(¢er, &volIn->sphereCenter, &volIn->box[0]); //kmVec3MultiplyMat4(¢er, ¢er, tr); //volOut->radius = kmVec3Length(¢er); }
void LayerColor::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) { _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(LayerColor::onDraw, this, transform, transformUpdated); renderer->addCommand(&_customCommand); for(int i = 0; i < 4; ++i) { kmVec3 pos; pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ; kmVec3TransformCoord(&pos, &pos, &_modelViewTransform); _noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z); } }
/* \brief calculates relative view coordinates for a point in world coordinates */ GLHCKAPI kmVec2* glhckCameraPointViewCoordinates(glhckCamera *object, kmVec2 *pOut, const kmVec3 *point) { CALL(2, "%p, "VEC3S, pOut, VEC3(point)); if (!glhckFrustumContainsPoint(&object->frustum, point)) return NULL; kmVec3 p; kmVec3TransformCoord(&p, point, &object->view.viewProj); pOut->x = (p.x + 1)/2; pOut->y = (p.y + 1)/2; RET(2, VEC2S, VEC2(pOut)); return pOut; }
void vs(float* _in, float* _out) { VSIn* in = (VSIn*)_in; VSOut* out = (VSOut*)_out; kmVec3TransformCoord(&out->position, &in->position, &mvp); }