Exemplo n.º 1
0
void ParticlesGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    // Touch events that don't hit the UI
    // allow the camera to rotate around the particle emitter.
    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        _touched = true;
        _prevX = x;
        _prevY = y;
        break;

    case Touch::TOUCH_RELEASE:
        _touched = false;
        break;

    case Touch::TOUCH_MOVE:
        {
            if (_touched)
            {
                int deltaX = x - _prevX;
                int deltaY = y - _prevY;
                _prevX = x;
                _prevY = y;

                _cameraParent->rotateY(MATH_DEG_TO_RAD(deltaX * -0.5f));
                _cameraParent->rotateX(MATH_DEG_TO_RAD(deltaY * -0.5f));
            }
        }
        break;
    default:
        break;
    };
}
Exemplo n.º 2
0
float Light::computeInnerAngle(float outerAngle)
{
    const float epsilon = 0.15f;

    // Set inner angle to half of outer angle.
    float innerAngle = outerAngle / 2.0f;

    // Try to find the inner angle by sampling the attenuation with steps of angle.
    for (float angle = 0.0; angle < outerAngle; angle += epsilon)
    {
        float outerCosAngle = cos(MATH_DEG_TO_RAD(outerAngle));
        float innerCosAngle = cos(MATH_DEG_TO_RAD(innerAngle));
            
        float cosAngle = cos(MATH_DEG_TO_RAD(angle));
        float att = lerpstep(outerCosAngle, innerCosAngle, cosAngle);
        
        if (att < 1.0f)
        {
            innerAngle = angle;
            break;
        }
    }

    return innerAngle;
}
Exemplo n.º 3
0
//public
bool WaterSample::mouseEvent(gp::Mouse::MouseEvent evt, int x, int y, int wheelDelta)
{
	switch (evt)
	{
	case gp::Mouse::MOUSE_MOVE:
	{
		auto xMovement = MATH_DEG_TO_RAD(-x * mouseSpeed);
		auto yMovement = MATH_DEG_TO_RAD(-y * mouseSpeed);

		m_cameraNode->rotateY(xMovement);
		m_cameraNode->getFirstChild()->rotateX(yMovement);

		m_reflectCamNode->rotateY(xMovement);
		m_reflectCamNode->getFirstChild()->rotateX(-yMovement);
	}
		return true;
	case gp::Mouse::MOUSE_PRESS_LEFT_BUTTON:
		m_inputMask |= Button::Forward;
		return true;
	case gp::Mouse::MOUSE_RELEASE_LEFT_BUTTON:
		m_inputMask &= ~Button::Forward;
		return true;
	case gp::Mouse::MOUSE_PRESS_RIGHT_BUTTON:
		m_inputMask |= Button::Back;
		return true;
	case gp::Mouse::MOUSE_RELEASE_RIGHT_BUTTON:
		m_inputMask &= ~Button::Back;
		return true;
	default: return false;
	}

	return false;
}
Exemplo n.º 4
0
void Light::writeBinary(FILE* file)
{
    Object::writeBinary(file);
    write(_lightType, file);
    write(_color, COLOR_SIZE, file);

    // Compute an approximate light range with Collada's attenuation parameters.
    // This facilitates bringing in the light nodes directly from maya to gameplay.
    if (_range == -1.0f)
    {
        _range = computeRange(_constantAttenuation, _linearAttenuation, _quadraticAttenuation);
    }

    if (_lightType == SpotLight)
    {
        // Compute an approximate inner angle of the spot light using Collada's outer angle.
        _outerAngle = _falloffAngle / 2.0f;
        
        if (_innerAngle == -1.0f)
        {
            _innerAngle = computeInnerAngle(_outerAngle);
        }

        write(_range, file);
        write(MATH_DEG_TO_RAD(_innerAngle), file);
        write(MATH_DEG_TO_RAD(_outerAngle), file);
    }
    else if (_lightType == PointLight)
    {
        write(_range, file);
    }
}
Exemplo n.º 5
0
void Audio3DTest::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        if (x < 75 && y < 50)
        {
            // Toggle Vsync if the user touches the top left corner
            setVsync(!isVsync());
        }
        _prevX = x;
        _prevY = y;
        break;
    case Touch::TOUCH_RELEASE:
        _prevX = 0;
        _prevY = 0;
        break;
    case Touch::TOUCH_MOVE:
    {
        int deltaX = x - _prevX;
        int deltaY = y - _prevY;
        _prevX = x;
        _prevY = y;
        float pitch = -MATH_DEG_TO_RAD(deltaY * 0.5f);
        float yaw = MATH_DEG_TO_RAD(deltaX * 0.5f);
        _fpCamera.rotate(yaw, pitch);
        break;
    }   
    };
}
Exemplo n.º 6
0
void Light::writeText(FILE* file)
{
    fprintElementStart(file);
    fprintfElement(file, "lightType", _lightType);
    fprintfElement(file, "color", _color, COLOR_SIZE);

    // Compute an approximate light range with Collada's attenuation parameters.
    // This facilitates bringing in the light nodes directly from maya to gameplay.
    if (_range == -1.0f)
    {
        _range = computeRange(_constantAttenuation, _linearAttenuation, _quadraticAttenuation);
    }

    if (_lightType == SpotLight)
    {
        // Compute an approximate inner angle of the spot light using Collada's outer angle.
        _outerAngle = _falloffAngle / 2.0f;
        if (_innerAngle == -1.0f)
        {
            _innerAngle = computeInnerAngle(_outerAngle);
        }

        fprintfElement(file, "range", _range);
        fprintfElement(file, "innerAngle", MATH_DEG_TO_RAD(_innerAngle));
        fprintfElement(file, "outerAngle", MATH_DEG_TO_RAD(_outerAngle));
    }
    else if (_lightType == PointLight)
    {
        fprintfElement(file, "range", _range);
    }

    fprintElementEnd(file);
}
Exemplo n.º 7
0
//触屏事件处理
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();
}
Exemplo n.º 8
0
void CameraControl::HandleMouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta) 
{
	Vector3 v = Vector3(camera_node->getTranslation());
	//move to origin
	camera_node->setTranslation(0, 0, 0);
	camera_node->rotateX(MATH_DEG_TO_RAD(y));
	camera_node->rotateY(MATH_DEG_TO_RAD(x));
	camera_node->getMatrix();//flush changes
	//reapply translation
	camera_node->setTranslation(v);
}
Exemplo n.º 9
0
void CharacterGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    // Send the touch event to the gamepad.
    _gamepad->touchEvent(evt, x, y, contactIndex);

	if (!_gamepad->isJoystickActive(0) || contactIndex != _gamepad->getJoystickContactIndex(0))
    {
        switch (evt)
        {
        case Touch::TOUCH_PRESS:
            {
                _rotateX = x;
            }
            break;
        case Touch::TOUCH_RELEASE:
            {
                _rotateX = 0;
            }
            break;
        case Touch::TOUCH_MOVE:
            {
                int deltaX = x - _rotateX;
                _rotateX = x;
                _character->getNode()->rotateY(-MATH_DEG_TO_RAD(deltaX * 0.5f));
            }
            break;
        default:
            break;
        }
    }
}
Exemplo n.º 10
0
void EvilQueenBlade::SetLook(float dirX){
    if(this->getActionByTag(1)){
        this->stopActionByTag(1);
    }
    
    if(dirX > 0){
        rot = 180 - rot;
        if(rot > 180)
            rot = -360 + rot;
    }
    else{
        rot = -30 + 30*option;
    }
    
    this->setPosition(master->getPosition());
    this->setRotation(-90);
    
    look = Vec2(1.0f, 0.0f);
    look.rotate(Vec2::ZERO, MATH_DEG_TO_RAD(rot));
    initialPos = master->GetHitPoint()+look*150.0f*std::abs(dirX);
    
    auto act1 = MoveTo::create(1.0f, initialPos);
    auto act2 = RotateTo::create(1.0f, -rot);
    auto act3 = Spawn::create(act1, act2, NULL);
    
    //        look.rotate(Vec2::ZERO, MATH_DEG_TO_RAD(rot));
    //        look = Normalize(look);
    //        hitPoint.rotate(this->getPosition(), MATH_DEG_TO_RAD(rot));
    
    this->runAction(Sequence::create(act3, DelayTime::create(3.0f), CallFunc::create(CC_CALLBACK_0(EvilQueenBlade::LockOn, this)), NULL));
    
    state = 1;
}
Exemplo n.º 11
0
void Matrix::createPerspective(float fieldOfView, float aspectRatio,
                                     float zNearPlane, float zFarPlane, Matrix* dst)
{
    GP_ASSERT(dst);
    GP_ASSERT(zFarPlane != zNearPlane);

    float f_n = 1.0f / (zFarPlane - zNearPlane);
    float theta = MATH_DEG_TO_RAD(fieldOfView) * 0.5f;
    if (fabs(fmod(theta, MATH_PIOVER2)) < MATH_EPSILON)
    {
        CCLOGERROR("Invalid field of view value (%f) causes attempted calculation tan(%f), which is undefined.", fieldOfView, theta);
        return;
    }
    float divisor = tan(theta);
    GP_ASSERT(divisor);
    float factor = 1.0f / divisor;

    memset(dst, 0, MATRIX_SIZE);

    GP_ASSERT(aspectRatio);
    dst->m[0] = (1.0f / aspectRatio) * factor;
    dst->m[5] = factor;
    dst->m[10] = (-(zFarPlane + zNearPlane)) * f_n;
    dst->m[11] = -1.0f;
    dst->m[14] = -2.0f * zFarPlane * zNearPlane * f_n;
}
Exemplo n.º 12
0
void BillboardSample::initialize()
{
    setMultiTouch(true);

	// Create the font and scene
    _font = Font::create("res/ui/arial.gpb");
	_scene = Scene::create();

	// Initialize the camera
    _camera.initialize(0.1f, 100, 45);
    _camera.setPosition(Vector3(0, BILLBOARD_HEIGHT * 1.5f, GROUND_WIDTH / 2.0f));
	_camera.rotate(0.0f, -MATH_DEG_TO_RAD(10));
    _scene->addNode(_camera.getRootNode());
    _scene->setActiveCamera(_camera.getCamera());

	// Load the ground
	loadGround();

    // Load billboards
    loadBillboards();

    _gamepad = getGamepad(0);
    // This is needed because the virtual gamepad is shared between all samples.
    // SamplesGame always ensures the virtual gamepad is disabled when a sample is exited.
    if (_gamepad && _gamepad->isVirtual())
        _gamepad->getForm()->setEnabled(true);
}
Exemplo n.º 13
0
void EvilQueenBlade::Load(){
    if(state != 1){
        this->setPosition(master->getPosition());
        this->setRotation(-90);
//
        if(master->getScaleX() > 0){ // look right
            rot = 180 - rot;
            if(rot > 180)
                rot = -360 + rot;
        }
        
        look.rotate(Vec2::ZERO, MATH_DEG_TO_RAD(rot));
        initialPos = master->GetHitPoint()+look*150.0f;
        
        auto act1 = MoveTo::create(0.2f, initialPos);
        auto act1_1 = EaseIn::create(act1, 3.0f);
        auto act2 = RotateTo::create(0.2f, -rot);
        auto act3 = Spawn::create(act1_1, act2, NULL);
        act3->setTag(1);
    
        this->runAction(act3);
        
        state = 1;
    }
}
Exemplo n.º 14
0
void MeshGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        {
            _touched = true;
            _touchX = x;
        }
        break;
    case Touch::TOUCH_RELEASE:
        {
            _touched = false;
            _touchX = 0;
        }
        break;
    case Touch::TOUCH_MOVE:
        {
            int deltaX = x - _touchX;
            _touchX = x;
            _modelNode->rotateY(MATH_DEG_TO_RAD(deltaX * 0.5f));
        }
        break;
    default:
        break;
    };
}
Exemplo n.º 15
0
void FormsSample::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    if (_formNode)
    {
        switch (evt)
        {
        case Touch::TOUCH_PRESS:
            {
                _touched = true;
                _touchX = x;
            }
            break;
        case Touch::TOUCH_RELEASE:
            {
                _touched = false;
                _touchX = 0;
            }
            break;
        case Touch::TOUCH_MOVE:
            {
                int deltaX = x - _touchX;
                _touchX = x;
                // Yaw in world frame
                Matrix m;
                _formNodeParent->getWorldMatrix().transpose(&m);
                Vector3 yaw;
                m.getUpVector(&yaw);
                _formNodeParent->rotate(yaw, MATH_DEG_TO_RAD(deltaX * 0.5f));
            }
            break;
        default:
            break;
        };
    }
}
Exemplo n.º 16
0
void CharacterGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{
    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        {
            _rotateX = x;
            _rotateY = y;
        }
        break;
    case Touch::TOUCH_RELEASE:
        {
            _rotateX = 0;
            _rotateY = 0;
        }
        break;
    case Touch::TOUCH_MOVE:
        {
            int deltaX = x - _rotateX;
            int deltaY = y - _rotateY;
            _rotateX = x;
            _rotateY = y;
            _character->getNode()->rotateY(-MATH_DEG_TO_RAD(deltaX * 0.5f));
            //_scene->findNode("Camera")->rotateX(-MATH_DEG_TO_RAD(deltaY * 0.5f));
            //_character->rotateY(-MATH_DEG_TO_RAD(deltaX * 0.5f));
        }
        break;
    default:
        break;
    };
}
Exemplo n.º 17
0
void Camera::buidProjScreenMatrixAndClipPlane(){
    
    // 投影矩阵一般没变化
    Mat4::createPerspective(fovy,aspect_ratio,near,far,&mper);
    
    // 视口矩阵一般也没变化
    float scr[16] = {
        (viewport_w-1)/2.f,0,0,0,
        0,-(viewport_h-1)/2.f,0,0,
        0,0,1,0,
        viewport_w/2.f,viewport_h/2.f,0,1
    };
    mscr.set(scr);
    
    //计算裁减平面
    Vec3 dir3 = -n;
    
    // near
    near_clip_plane.p0 = pos + near * dir3;
    near_clip_plane.n = dir3;
    
    // far
    far_clip_plane.p0 = pos + far * dir3;
    far_clip_plane.n = n;
    
    float rad = MATH_DEG_TO_RAD(fovy/2.0);
    float half_h = tanf(rad) * near;
    float half_w = aspect_ratio * half_h;
    
    // near left bottom
    Point3 left_bottom = near_clip_plane.p0 - half_h * v - half_w * u;
    Point3 left_top = left_bottom + 2*v*half_h;
    Point3 right_bottom = left_bottom + 2 * u * half_w;
    Point3 right_top = left_top + 2 * u * half_w;
    Vec3 tmp_v1 = left_bottom - pos;
    Vec3 tmp_v2 = left_top - pos;
 
    // left,画图计算
    left_clip_plane.p0 = pos;
    Vec3::cross(tmp_v1,tmp_v2,&left_clip_plane.n);
    left_clip_plane.n.normalize();
    
    // right
    right_clip_plane.p0 = pos;
    Vec3 tmp_v3 = right_top - pos;
    Vec3 tmp_v4 = right_bottom - pos;
    Vec3::cross(tmp_v3,tmp_v4,&right_clip_plane.n);
    right_clip_plane.n.normalize();
    
    //top
    top_clip_plane.p0 = pos;
    Vec3::cross(tmp_v2,tmp_v3,&top_clip_plane.n);
    top_clip_plane.n.normalize();
    
    //bottom
    bottom_clip_plane.p0 = pos;
    Vec3::cross(tmp_v4,tmp_v1,&bottom_clip_plane.n);
    bottom_clip_plane.n.normalize();
}
Exemplo n.º 18
0
void ShadowManager::updateLightDir() {
  if (mLightDirDegree < 0) {
    mLightDirDegree += 360;
  } else if (mLightDirDegree >= 360) {
    mLightDirDegree -= 360;
  }
  mLightDir = Vec2(1, 0);
  mLightDir.rotate(Vec2::ZERO, MATH_DEG_TO_RAD(-mLightDirDegree));
}
Exemplo n.º 19
0
bool Main::rotateRight(Node* node)
{
    //Draw the sprite if it exists
    Sprite* sprite = node->getSprite();
    if(sprite)
    {
        node->rotateZ(MATH_DEG_TO_RAD(-1.0f));
    }
    return true;
}
Exemplo n.º 20
0
void Light::writeText(FILE* file)
{
    fprintElementStart(file);
    fprintfElement(file, "lightType", _lightType);
    fprintfElement(file, "color", _color, COLOR_SIZE);

    if (_lightType == SpotLight)
    {
        fprintfElement(file, "range", _range);
        fprintfElement(file, "innerAngle", MATH_DEG_TO_RAD(_innerAngle));
        fprintfElement(file, "outerAngle", MATH_DEG_TO_RAD(_outerAngle));
    }
    else if (_lightType == PointLight)
    {
        fprintfElement(file, "range", _range);
    }

    fprintElementEnd(file);
}
Exemplo n.º 21
0
void CubeTest::update(float elapsedTime)
{
    // Rotate model
    _scene->findNode("box")->rotateZ(MATH_DEG_TO_RAD((float)elapsedTime / 3000.0f * 180.0f));
    float dscale = 1.0f + .25f*sinf(MATH_DEG_TO_RAD((float)getGameTime() / 200.0f * 180.0f));
    _scene->findNode("box")->setScale(dscale);
    
    Node * camNode = _camera->getNode();
    if( _wDown )
        camNode->translateForward(.2f);
    if( _sDown )
        camNode->translateForward(-.2f);
    
    if( _aDown ) {
        if( _ctrlDown )
            camNode->rotateY(.02f);
        else
            camNode->translateLeft(.2f);
    }
    
    if( _dDown ) {
        if( _ctrlDown )
            camNode->rotateY(-.02f);
        else
            camNode->translateLeft(-.2f);
    }
    if( _rDown ) {
        if( _ctrlDown )
            camNode->rotateX(.02f);
        else
            camNode->translateUp(.2f);
    }
    if( _fDown ) {
        if( _ctrlDown )
            camNode->rotateX(-.02f);
        else
            camNode->translateUp(-.2f);
    }
}
Exemplo n.º 22
0
void SceneViewer::initialize()
{
   // Load game scene from file
   _scene = Scene::load("res/scene.gpb");

   _shift_key = false;
   _control_key = false;
   _rotate_active = true;
   _pan_active = false;
   _zoom_active = false;
   _touch_x = 0;
   _touch_y = 0;
   _grid_on = 1;


   Camera * cam = _scene->getActiveCamera();
   if (cam) {
      // Set the aspect ratio for the scene's camera to match the current resolution
      cam->setAspectRatio(getAspectRatio());
      cam->getNode()->rotateY(MATH_DEG_TO_RAD(-90));
   }

   // Try to use any significant light source for the scene light vector.
   // This is just a temporary hack until I manage to tap into the
   // material file from the python addon.
   Node * light = _scene->findNode("Spot") ? _scene->findNode("Spot") :
                                             _scene->findNode("Area") ? _scene->findNode("Area") :
                                                                        _scene->findNode("Sun") ? _scene->findNode("Sun") : 0;
   if (light) _directionalLightVector = light->getForwardVector();

   // Setup the form and callbacks
   _form = Form::create("res/editor.form");
   _sliderLightVectorX = (Slider *)_form->getControl("lvx");
   _sliderLightVectorY = (Slider *)_form->getControl("lvy");
   _sliderLightVectorZ = (Slider *)_form->getControl("lvz");
   _sliderClearColorRed = (Slider *)_form->getControl("ccRed");
   _sliderClearColorGreen = (Slider *)_form->getControl("ccGreen");
   _sliderClearColorBlue = (Slider *)_form->getControl("ccBlue");
   _bPlayAll = (Button *)_form->getControl("playAll");
   _bPlaySelected = (Button *)_form->getControl("playSelected");
   _bPlaySelected->setEnabled(false);

   _gridCheckBox = static_cast<CheckBox*>(_form->getControl("gridCheckBox"));



   Slider * sliders[] = { _sliderLightVectorX, _sliderLightVectorY, _sliderLightVectorZ,
                        _sliderClearColorRed, _sliderClearColorGreen, _sliderClearColorBlue }, *s;
   FOREACH(s, sliders) {
      s->addListener(this, Listener::VALUE_CHANGED);
   }
Exemplo n.º 23
0
int gamehsp::makeNewLgt( int id, int lgtopt, float range, float inner, float outer )
{
	gpobj *obj;
	Node *node;
	Light *light;

	if ( id < 0 ) {
		int newid = makeNullNode();
		obj = getObj( newid );
	} else {
		obj = getObj( id );
	}
	if ( obj == NULL ) return -1;

	node = obj->_node;
	if ( node == NULL ) return -1;

	if ( obj->_light ) {
		node->setLight( NULL );
		SAFE_RELEASE( obj->_light );
	}

	light = NULL;

	switch( lgtopt ) {
	case GPLGT_OPT_POINT:
		light = Light::createPoint( 1.0f, 1.0f, 1.0f, range );
		break;
	case GPLGT_OPT_SPOT:
		light = Light::createSpot( 1.0f, 1.0f, 1.0f, range, inner, outer );
		break;
	default:
		light = Light::createDirectional( 1.0f, 1.0f, 1.0f );
		break;
	}

	if ( light ) {

		//light->setColor( 1.0f, 1.0f, 1.0f );
		node->setLight( light );
		if ( id < 0 ) {
			node->rotateX(MATH_DEG_TO_RAD(-45.0f));
		}
		obj->_light = light;
	}

	obj->_vec[GPOBJ_USERVEC_COLOR].set( 1.0f, 1.0f, 1.0f, 1.0f );
	obj->_vec[GPOBJ_USERVEC_WORK].set( 0.25f, 0.25f, 0.25f, 1.0f );

	return obj->_id;
}
Exemplo n.º 24
0
void Block::addToGame(Node* node, Texture* tex, Scene* _scene)
{
//	if (nodeI.compare("normal") == 0){
//		if (Block::node && Block::node->getModel()->getMaterial())
//			applyNormalMap(Block::node->getModel()->getMaterial(), tex);
//		else
//			Block::node = nodeToScene(node, tex, _scene, TEXTURED_NORMAL);
//	}
//	else
		Block::node = nodeToScene(node, tex, _scene, TEXTURED, true);
		dynamic_cast<Model*>(Block::node->getDrawable())->getMaterial()->getStateBlock()->setDepthTest(true);
	Block::node->rotateZ(MATH_DEG_TO_RAD(-90));
	SetPosition(position.x, position.y);
}
Exemplo n.º 25
0
void CharacterGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
{

    switch (evt)
    {
    case Touch::TOUCH_PRESS:
        {
            _rotateX = x;
            switch (_animationState)
            {
                case 0:
                    _animation->stop("head");
                    _animation->play("right_arm");
                    break;
                case 1:
                    _animation->stop("right_arm");
                    _animation->play("left_arm");
                    break;
                case 2:
                    _animation->stop("left_arm");
                    _animation->play("right_leg");
                    break;
                case 3:
                    _animation->stop("right_leg");
                    _animation->play("left_leg");
                    break;
                case 4:
                    _animation->stop("left_leg");
                    _animation->play("head");
                    break;
            }
            _animationState = (_animationState + 1) % 5;
        }
        break;
    case Touch::TOUCH_RELEASE:
        {
            _rotateX = 0;
        }
        break;
    case Touch::TOUCH_MOVE:
        {
            int deltaX = x - _rotateX;
            _rotateX = x;
            _modelNode->rotateY(MATH_DEG_TO_RAD(deltaX * 0.5f));
        }
        break;
    default:
        break;
    };
}
Exemplo n.º 26
0
void PostProcessSample::update(float elapsedTime)
{
    _modelNode->rotateY(elapsedTime * MATH_DEG_TO_RAD(0.25f));

    // Only the last sample will check live updating of material parameters
    if (_compositorIndex == _compositors.size() - 1)
    {
        Compositor* compositor = _compositors[_compositorIndex];
        MaterialParameter* elapsedParam  = compositor->getMaterial()->getParameter("u_elapsedTime");
        if (elapsedParam)
            elapsedParam->setValue(elapsedTime);
        MaterialParameter* randomParam = compositor->getMaterial()->getParameter("u_random");
        if (randomParam)
            randomParam->setValue(MATH_RANDOM_0_1());
    }
}
Exemplo n.º 27
0
void EvilQueenBlade::Fire(Vec2 tarPos){
    look = Normalize(this->getPosition() - tarPos);
    look.rotate(Vec2::ZERO, MATH_DEG_TO_RAD(30));
    ccBezierConfig config;
    
    config.controlPoint_1 = this->getPosition() + look*100.0f;
    config.controlPoint_2 = this->getPosition() + look*500.0f;
    config.endPosition = tarPos;
    
    auto act1 = BezierTo::create(1.0f, config);
    auto act2 = EaseIn::create(act1, 1.5f);
    
    this->runAction(Sequence::create(act2, CallFunc::create(CC_CALLBACK_0(EvilQueenBlade::Arrive, this, false)), DelayTime::create(3.0f), RemoveSelf::create(), NULL));
    
    oldPos = this->getPosition();
    
    this->scheduleUpdate();
}
Exemplo n.º 28
0
bool Properties::parseAxisAngle(const char* str, Quaternion* out)
{
    if (str)
    {
        float x, y, z, theta;
        if (sscanf(str, "%f,%f,%f,%f", &x, &y, &z, &theta) == 4)
        {
            if (out)
                out->set(Vec3(x, y, z), MATH_DEG_TO_RAD(theta));
            return true;
        }
        else
        {
            CCLOGWARN("Error attempting to parse property as an axis-angle rotation: %s", str);
        }
    }

    if (out)
        out->set(0.0f, 0.0f, 0.0f, 1.0f);
    return false;
}
Exemplo n.º 29
0
void BillboardSample::loadGround()
{
	// Just a basic plane for this sample
	Mesh* mesh = Mesh::createQuad(-(GROUND_WIDTH / 2.0f), -(GROUND_HEIGHT / 2.0f), GROUND_WIDTH, GROUND_HEIGHT);
	Node* node = Node::create();
	_ground = Model::create(mesh);
	SAFE_RELEASE(mesh);
	node->setDrawable(_ground);
    _scene->addNode(node);
	node->rotateX(MATH_DEG_TO_RAD(90));
	Effect* effect = Effect::createFromFile("res/shaders/textured.vert", "res/shaders/textured.frag", "TEXTURE_REPEAT");    
	Material* material = Material::create(effect); 
	material->getStateBlock()->setDepthTest(true);
	material->getStateBlock()->setBlend(false);
	Texture::Sampler* sampler = material->getParameter("u_diffuseTexture")->setValue("res/png/dirt.png", true);
	sampler->setFilterMode(Texture::LINEAR_MIPMAP_LINEAR, Texture::LINEAR);
	material->getParameter("u_textureRepeat")->setValue(Vector2(GROUND_REPEAT_TEXTURE, GROUND_REPEAT_TEXTURE));
	material->setParameterAutoBinding("u_worldViewProjectionMatrix", RenderState::WORLD_VIEW_PROJECTION_MATRIX);
	_ground->setMaterial(material);
	SAFE_RELEASE(material);
	SAFE_RELEASE(effect)
    SAFE_RELEASE(node);
}
Exemplo n.º 30
0
void CubeTest::initialize()
{
    _scene = Scene::load( "res/world.scene" );
    if( !_scene ) {
        printf("Couldn't load scene!");
        Game::getInstance()->exit();
    }

    // Set the aspect ratio for the scene's camera to match the current resolution
    _camera = _scene->getActiveCamera();
    _camera->setAspectRatio(getAspectRatio());
    
    Node * sun = _scene->findNode("sun");
    Node * box = _scene->findNode("box");
    Node * monkey = _scene->findNode("X");
    Node * spot = _scene->findNode("spot");
    
    _camera->getNode()->rotateY( MATH_DEG_TO_RAD(270.0f) );
    
    Node * camNode = _camera->getNode();
    //camNode->setTranslation(0, 0, 0);
    //camNode->setRotation(1, 0, 0, 0);
    
    //camNode->translate(0, -10, 10);
    //camNode->rotateX( MATH_DEG_TO_RAD(225.0f) );
    //camNode->rotateX( MATH_DEG_TO_RAD(-10.0f));
    Vector3 f = camNode->getForwardVector();
    
    
    bindSpotLight( box->getModel()->getMaterial(0), spot );
    bindDirectionalLight( box->getModel()->getMaterial(0), sun );
    bindDirectionalLight( monkey->getModel()->getMaterial(0), sun );
    
    
    //printf("<%.3f, %.3f, %.3f>\n", f.x, f.y, f.z );
    //dumpModel( box );
}