Exemplo n.º 1
0
WorldManager::WorldManager()
{
	scene = shared_ptr<PhysicsScene2D>(new PhysicsScene2D(0.1, 60));

	ScenePrimitive *shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 1.0,0.05);
	shape->setColor(0.0,0.0,0.1,1.0);
	shape->setPosition(0, -0.3);
	scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, true);	
	
	ScenePrimitive *shape2 = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.05, 1.0);
	shape2->setColor(0.0,0.0,0.1,1.0);
	shape2->setPosition(-0.3, -0.4);
	shape2->setRoll(45);
	scene->addPhysicsChild(shape2, PhysicsScene2DEntity::ENTITY_RECT, true);	
	
	ScenePrimitive *shape3 = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.05, 1.0);
	shape3->setColor(0.0,0.0,0.1,1.0);
	shape3->setPosition(0.3, -0.4);
	shape3->setRoll(-45);
	scene->addPhysicsChild(shape3, PhysicsScene2DEntity::ENTITY_RECT, true);	
	
	// for(int i=0; i < 1000; i++) {
	// 	shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.02,0.02);
	// 	shape->setRoll(rand() % 360);
 //        shape->setColor(RANDOM_NUMBER, RANDOM_NUMBER, RANDOM_NUMBER, 1.0);
	// 	shape->setPosition(-0.3 + (RANDOM_NUMBER*0.6), RANDOM_NUMBER);
	// 	scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
	// }
}
Exemplo n.º 2
0
void WorldManager::update()
{
	count++;

	if(count % 10 == 0) 
	{
		ScenePrimitive *shape;
		shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.02,0.02);
		shape->setRoll(rand() % 360);
        shape->setColor(RANDOM_NUMBER, RANDOM_NUMBER, RANDOM_NUMBER, 1.0);
		shape->setPosition(-0.3 + (RANDOM_NUMBER*0.6), RANDOM_NUMBER);
		scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
	}
}
Exemplo n.º 3
0
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {

	core = new POLYCODE_CORE(view, 640,480,false,true,0,0,90, 0, true);

	PhysicsScene2D *scene = new PhysicsScene2D(0.1, 50);

	ScenePrimitive *ceiling = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 2.0, 0.1);
	ceiling->setColor(0.0, 0.0, 0.0, 1.0);
	ceiling->setPosition(0, 0.5);
	scene->addPhysicsChild(ceiling, PhysicsScene2DEntity::ENTITY_RECT, true);
	
	// Revolute Joint	
	ScenePrimitive *shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.03, 0.2);
    shape->setAnchorPoint(0.0, 1.0, 0.0);
	shape->setPosition(-0.3, 0.48);
	scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
	scene->createRevoluteJoint(shape, ceiling, 0.0, 0.01);
	scene->applyImpulse(shape, 10, 0);
	
	// Distance Joint	
	shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.1, 0.02);
	shape->setPosition(0.0, 0.2);
	scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
	scene->createDistanceJoint(shape, ceiling, false);
	scene->applyImpulse(shape, 2, 0);
	
	SceneLine *line = new SceneLine(shape, ceiling);
	line->setColor(1.0, 0.0, 0.0, 1.0);
	scene->addChild(line);

	// Prismatic Joint	
	shape = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.05, 0.1);
	shape->setPosition(0.3, 0.3);
	scene->addPhysicsChild(shape, PhysicsScene2DEntity::ENTITY_RECT, false);
	scene->createPrismaticJoint(ceiling, shape, Vector2(0,1), 0,0, false, -0.3, 0, true);

	SceneEntity *lineAnchor = new SceneEntity();
	lineAnchor->setPosition(0.3,0.5);
	line = new SceneLine(shape, lineAnchor);
	line->setColor(0.0, 1.0, 0.0, 1.0);
	scene->addChild(line);
}
Exemplo n.º 4
0
TransformGizmo::TransformGizmo(Scene *targetScene, Camera *targetCamera) : Entity() {
	processInputEvents = true;
    orientation = ORIENTATION_GLOBAL;
    centerMode = CENTER_MODE_MEDIAN;
    enableGizmo = true;
    firstMove = true;
    
    snapEnabled = false;
    snapSize = 1.0;
    
	this->targetScene = targetScene;
	this->targetCamera = targetCamera;
	
	ScenePrimitive *centerCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 0.3, 0.3, 16);
	centerCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	centerCircle->setColor(0.7, 0.7, 0.7, 1.0);
	centerCircle->depthTest = false;
	centerCircle->billboardMode = true;
	addChild(centerCircle);
    centerCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
		  
	trasnformDecorators = new Entity();
	addChild(trasnformDecorators);
	
	scaleDecorators = new Entity();
	addChild(scaleDecorators);
		
	transformAndScaleLines = new Entity();
	addChild(transformAndScaleLines);    
		
	rotateDectorators = new Entity();
	addChild(rotateDectorators);
    
	yLine = new SceneMesh(Mesh::LINE_MESH);
	yLine->getMesh()->addVertex(0.0, 0.0, 0.0);
	yLine->getMesh()->addVertex(0.0, 1.0, 0.0);
	yLine->getMesh()->dirtyArrays();
	yLine->depthTest = false;
	yLine->setColor(0.0, 1.0, 0.0, 1.0);
    yLine->setLocalBoundingBox(yLine->getMesh()->calculateBBox());
    yLine->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX() * 2.0);
	transformAndScaleLines->addChild(yLine);

	xLine = new SceneMesh(Mesh::LINE_MESH);
	xLine->getMesh()->addVertex(0.0, 0.0, 0.0);
	xLine->getMesh()->addVertex(1.0, 0.0, 0.0);
	xLine->getMesh()->dirtyArrays();
	xLine->depthTest = false;
	xLine->setColor(1.0, 0.0, 0.0, 1.0);
    xLine->setLocalBoundingBox(xLine->getMesh()->calculateBBox());
    xLine->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX() * 2.0);
	transformAndScaleLines->addChild(xLine);

	zLine = new SceneMesh(Mesh::LINE_MESH);
	zLine->getMesh()->addVertex(0.0, 0.0, 0.0);
	zLine->getMesh()->addVertex(0.0, 0.0, 1.0);
	zLine->getMesh()->dirtyArrays();
	zLine->depthTest = false;
	zLine->setColor(0.0, 0.0, 1.0, 1.0);
    zLine->setLocalBoundingBox(zLine->getMesh()->calculateBBox());
    zLine->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX() * 2.0);
	transformAndScaleLines->addChild(zLine);
	
	// MOVE
	
	yArrow = new ScenePrimitive(ScenePrimitive::TYPE_CONE, 0.2, 0.05, 12);
	yArrow->setColor(0.0, 1.0, 0.0, 1.0);
	yArrow->setPosition(0.0, 1.0, 0.0);
	yArrow->depthTest = false;
	trasnformDecorators->addChild(yArrow);
	
	xArrow = new ScenePrimitive(ScenePrimitive::TYPE_CONE, 0.2, 0.05, 12);
	xArrow->setColor(1.0, 0.0, 0.0, 1.0);
	xArrow->setPosition(1.0, 0.0, 0.0);
	xArrow->Roll(-90);
	xArrow->depthTest = false;
	trasnformDecorators->addChild(xArrow);

	zArrow = new ScenePrimitive(ScenePrimitive::TYPE_CONE, 0.2, 0.05, 12);
	zArrow->setColor(0.0, 0.0, 1.0, 1.0);
	zArrow->setPosition(0.0, 0.0, 1.0);
	zArrow->Pitch(90);
	zArrow->depthTest = false;	
	trasnformDecorators->addChild(zArrow);

	// SCALE

	yBox = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.1, 0.1, 0.1);
	yBox->setColor(0.0, 1.0, 0.0, 1.0);
	yBox->setPosition(0.0, 1.0, 0.0);
	yBox->depthTest = false;
	scaleDecorators->addChild(yBox);
	
	xBox = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.1, 0.1, 0.1);
	xBox->setColor(1.0, 0.0, 0.0, 1.0);
	xBox->setPosition(1.0, 0.0, 0.0);
	xBox->Roll(-90);
	xBox->depthTest = false;
	scaleDecorators->addChild(xBox);

	zBox = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.1, 0.1, 0.1);
	zBox->setColor(0.0, 0.0, 1.0, 1.0);
	zBox->setPosition(0.0, 0.0, 1.0);
	zBox->Pitch(90);
	zBox->depthTest = false;	
	scaleDecorators->addChild(zBox);

	// ROTATE

	bgCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 2.6, 2.6, 32);
	bgCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	bgCircle->setColor(0.0, 0.0, 0.0, 1.0);
	bgCircle->depthTest = false;
	bgCircle->billboardMode = true;
	rotateDectorators->addChild(bgCircle);
    bgCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());

	outerCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 3.0, 3.0, 32);
	outerCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	outerCircle->setColor(1.0, 1.0, 1.0, 1.0);
	outerCircle->depthTest = false;
	outerCircle->billboardMode = true;
	rotateDectorators->addChild(outerCircle);
    outerCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX() * 2.0);
    
	pitchCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 2.55, 2.55, 32);
	pitchCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	pitchCircle->setColor(1.0, 0.0, 0.0, 1.0);
	pitchCircle->depthTest = false;
	pitchCircle->Yaw(90);	
	rotateDectorators->addChild(pitchCircle);
	pitchCircle->setMaterialByName("OneSidedLine");
    pitchCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX() * 2.0);
    
	yawCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 2.65, 2.65, 32);
	yawCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	yawCircle->setColor(0.0, 1.0, 0.0, 1.0);
	yawCircle->depthTest = false;
	yawCircle->Pitch(90);
	rotateDectorators->addChild(yawCircle);
	yawCircle->setMaterialByName("OneSidedLine");
    yawCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX()* 2.0);
    
	rollCircle = new ScenePrimitive(ScenePrimitive::TYPE_LINE_CIRCLE, 2.6, 2.6, 32);
	rollCircle->getMesh()->setMeshType(Mesh::LINE_LOOP_MESH);
	rollCircle->setColor(0.0, 0.0, 1.0, 1.0);
	rollCircle->depthTest = false;
	rotateDectorators->addChild(rollCircle);
	rollCircle->setMaterialByName("OneSidedLine");
    rollCircle->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX()* 2.0);
    
	
	rotateDectorators->processInputEvents = true;
	
	//pitchGrip = new ScenePrimitive(ScenePrimitive::TYPE_TORUS, 1.55 * 0.5, 0.05, 16, 3);
    pitchGrip = new ScenePrimitive(ScenePrimitive::TYPE_UNCAPPED_CYLINDER, 0.15, 2.55 * 0.5, 16);
	pitchGrip->setColor(1.0, 0.0, 0.0, 0.2);
	pitchGrip->depthTest = false;
	pitchGrip->Pitch(90);	
	pitchGrip->Yaw(90);		
	rotateDectorators->addChild(pitchGrip);
	pitchGrip->processInputEvents = true;
	pitchGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	pitchGrip->useGeometryHitDetection = true;
	pitchGrip->blockMouseInput = true;

    rollGrip = new ScenePrimitive(ScenePrimitive::TYPE_UNCAPPED_CYLINDER, 0.15, 2.6 * 0.5, 16);
	rollGrip->setColor(0.0, 0.0, 1.0, 0.2);
	rollGrip->depthTest = false;
	rollGrip->Pitch(90);		
	rotateDectorators->addChild(rollGrip);
	rollGrip->processInputEvents = true;
	rollGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	rollGrip->useGeometryHitDetection = true;
	rollGrip->blockMouseInput = true;
	
	yawGrip= new ScenePrimitive(ScenePrimitive::TYPE_UNCAPPED_CYLINDER, 0.15, 2.65 * 0.5, 16);
	yawGrip->setColor(0.0, 1.0, 0.0, 0.2);
	yawGrip->depthTest = false;
	yawGrip->Yaw(90);		
	rotateDectorators->addChild(yawGrip);
	yawGrip->processInputEvents = true;
	yawGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	yawGrip->useGeometryHitDetection = true;
	yawGrip->blockMouseInput = true;
	
    viewportRotateGripBase = new Entity();
    viewportRotateGripBase->processInputEvents = true;
	rotateDectorators->addChild(viewportRotateGripBase);
    
	viewportRotateGrip = new ScenePrimitive(ScenePrimitive::TYPE_TORUS, 3.0 * 0.5, 0.08, 16, 3);
    viewportRotateGrip->Pitch(90);
	viewportRotateGrip->setColor(0.0, 1.0, 0.0, 0.2);
	viewportRotateGrip->depthTest = false;
	viewportRotateGripBase->addChild(viewportRotateGrip);
	viewportRotateGrip->processInputEvents = true;
	viewportRotateGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	viewportRotateGrip->useGeometryHitDetection = true;
	viewportRotateGrip->blockMouseInput = true;

    pitchGrip->visible = false;
	yawGrip->visible = false;
	rollGrip->visible = false;
    viewportRotateGrip->visible = false;

	xTransformGrip = new Entity();
	xTransformGrip->setLocalBoundingBox(1.3, 0.1, 0.1);
    xTransformGrip->depthTest = false;
    xTransformGrip->setColor(1.0, 0.0, 0.0, 1.0);
	addChild(xTransformGrip);
	xTransformGrip->setAnchorPoint(Vector3(-1.0, 0.0, 0.0));
	xTransformGrip->processInputEvents = true;
	xTransformGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);

	yTransformGrip = new Entity();
	yTransformGrip->setLocalBoundingBox(0.1, 1.3, 0.1);
	addChild(yTransformGrip);
	yTransformGrip->setAnchorPoint(Vector3(0.0, -1.0, 0.0));
	yTransformGrip->processInputEvents = true;
	yTransformGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);

	zTransformGrip = new Entity();
	zTransformGrip->setLocalBoundingBox(0.1, 0.1, 1.3);
	addChild(zTransformGrip);
	zTransformGrip->setAnchorPoint(Vector3(0.0, 0.0, -1.0));
	zTransformGrip->processInputEvents = true;
	zTransformGrip->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
		
	transforming = false;
	mode = TRANSFORM_MOVE;
    	
	visible = false;
	enabled = false;
	
	coreInput = CoreServices::getInstance()->getCore()->getInput();
	coreInput->addEventListener(this, InputEvent::EVENT_MOUSEMOVE);
	coreInput->addEventListener(this, InputEvent::EVENT_MOUSEUP);
	coreInput->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
	coreInput->addEventListener(this, InputEvent::EVENT_KEYDOWN);
    
	gizmoMode = GIZMO_MODE_3D;
	setTransformMode(TRANSFORM_MOVE);
}
Exemplo n.º 5
0
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {

    core = new POLYCODE_CORE(view, 640,480,false,false,0,0,90);

    CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
    CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);

    Screen *hud = new Screen();

    onGroundLabel = new ScreenLabel("Arrow keys to control, spacebar to brake, press R to reset car", 16);
    hud->addChild(onGroundLabel);

    scene = new PhysicsScene();

    ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 30, 30);
    ground->loadTexture("Resources/green_texture.png");
    scene->addPhysicsChild(ground, PhysicsSceneEntity::SHAPE_PLANE, 0.0);

    // Some obstacles
    ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 4,4,6);
    box->setPitch(25.0);
    box->setPosition(7,-1.05, 0.0);
    box->setColor(0.5,0.5,1.0,1.0);
    box->loadTexture("Resources/green_texture.png");
    scene->addPhysicsChild(box, PhysicsSceneEntity::SHAPE_BOX, 0.0);

    box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 4,4,6);
    box->setPitch(25.0);
    box->setPosition(-7,-1.05, 0.0);
    box->setColor(0.5,0.5,1.0,1.0);
    box->loadTexture("Resources/green_texture.png");
    scene->addPhysicsChild(box, PhysicsSceneEntity::SHAPE_BOX, 0.0);

    box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 20,2,5);
    box->setPosition(0.0,1.0, -4.3);
    box->setColor(0.5,0.5,1.0,1.0);
    box->loadTexture("Resources/green_texture.png");
    scene->addPhysicsChild(box, PhysicsSceneEntity::SHAPE_BOX, 0.0);

    for(int i=0; i < 10; i++) {
        ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 0.7,0.7,0.7);
        box->loadTexture("Resources/pink_texture.png");
        box->Roll(-45 + (rand() % 90));
        box->Pitch(-45 + (rand() % 90));
        box->setPosition(-3 + (rand() % 6), 2 + i*0.5, -5 + (rand() % 3));
        scene->addPhysicsChild(box, PhysicsSceneEntity::SHAPE_BOX, 1.0);
    }

    // The vehicle
    vehicle = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1.0,0.5,2.0);
    vehicle->loadTexture("Resources/pink_texture.png");
    vehicle->setColor(1.0, 1.0, 0.0, 1.0);
    vehicle->setPosition(6,1,5);
    vehicleController = scene->addVehicleChild(vehicle, 5.0, 1.0);

    ScenePrimitive *wheel = new ScenePrimitive(ScenePrimitive::TYPE_SPHERE, 0.3, 10, 10);
    wheel->loadTexture("Resources/pink_texture.png");
    wheel->setColor(0.0, 1.0, 0.0, 1.0);
    vehicleController->addWheel(wheel, Vector3(0.6,0,-0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2,  0.3, true);
    scene->addEntity(wheel);

    wheel = new ScenePrimitive(ScenePrimitive::TYPE_SPHERE, 0.3, 10, 10);
    wheel->loadTexture("Resources/pink_texture.png");
    wheel->setColor(0.0, 1.0, 0.0, 1.0);
    vehicleController->addWheel(wheel, Vector3(-0.6,0,-0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2,  0.3, true);
    scene->addEntity(wheel);

    wheel = new ScenePrimitive(ScenePrimitive::TYPE_SPHERE, 0.3, 10, 10);
    wheel->loadTexture("Resources/pink_texture.png");
    wheel->setColor(0.0, 1.0, 0.0, 1.0);
    vehicleController->addWheel(wheel, Vector3(0.6,0,0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2,  0.3, false);
    scene->addEntity(wheel);

    wheel = new ScenePrimitive(ScenePrimitive::TYPE_SPHERE, 0.3, 10, 10);
    wheel->loadTexture("Resources/pink_texture.png");
    wheel->setColor(0.0, 1.0, 0.0, 1.0);
    vehicleController->addWheel(wheel, Vector3(-0.6,0,0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2,  0.3, false);
    scene->addEntity(wheel);

    steeringValue = 0;
    engineForce = 0;
    breaking = false;

    testBox = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 4, 4, 4);
    testBox->loadTexture("Resources/pink_texture.png");
    testBox->setColor(0.3,0.5, 1.0,0.4);
    testBox->setPosition(-5,2,7);
    scene->addCollisionChild(testBox, PhysicsSceneEntity::SHAPE_BOX);


    scene->getDefaultCamera()->setPosition(16,16,16);
    scene->getDefaultCamera()->lookAt(Vector3(0,0,0));

    core->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
    core->getInput()->addEventListener(this, InputEvent::EVENT_KEYUP);
}