void Scene::render(Pixel* px, Vertex *eyePoint, double attenuation) { //create the zbuffer matrix int width = px->getWidth(); int height = px->getHeight(); Matrix* zbuffer = new Matrix(height, width); //rows come first //populate zbuffer with -1 for (int i = 1; i <= height; i++) { for (int j = 1; j <= width; j++) { zbuffer->setElement(i, j, -1.0); } } //loop over all the Instance instances in the Scene and render them ListIterator<TransformNode>* ioIter = transformNodes->iterator(); while (ioIter->hasNext()) { TransformNode* tn = ioIter->next(); tn->render(px, sceneTransform, zbuffer, ambientLight, pointLight, eyePoint, attenuation); } delete ioIter; delete zbuffer; }
Node *update(Node *old) { if (old) return old; vec2 s = size(); vec2 s3 = s / 3; // Root has origin in screen center TransformNode *root = TransformNode::create(); root->setMatrix(mat4::translate2D(s.x * 0.5, s.y * 0.5)); OpacityNode *opacityNode = OpacityNode::create(); // opacityNode->setOpacity(0.5); root->append(opacityNode); vec4 color(0.5, 0.5, 0.8, 1.0); *opacityNode << RectangleNode::create(rect2d::fromPosSize(-s3, s3), color) << RectangleNode::create(rect2d::fromPosSize(-s3/2, s3), color) << RectangleNode::create(rect2d::fromPosSize(vec2(), s3), color); AnimationClosure<OpacityNode> *anim = new AnimationClosure<OpacityNode>(opacityNode); anim->setDuration(3); anim->setDirection(Animation::Alternate); anim->setIterations(-1); anim->keyFrames.times() << 0 << 1; anim->keyFrames.addValues<double, OpacityNode_setOpacity>() << 0 << 1; animationManager()->startAnimation(anim); return root; }
Vector3 Bone::CalculateNodePositionInSkeletonSpace( const std::vector<int>& node_locator, uint& index, const Transform& parent_transform, const TransformNode& parent_transform_node ) const { if( (uint)node_locator.size() == index ) { return parent_transform * m_vOffset; } int bone_and_node_index = node_locator[index]; const int num_children = (int)m_vecChild.size(); if( num_children <= bone_and_node_index || parent_transform_node.GetNumChildren() <= bone_and_node_index ) { return Vector3(0,0,0); } index++; const TransformNode& child_transform_node = parent_transform_node.GetChildNode(bone_and_node_index); Transform offset_transform = Transform( Quaternion().FromRotationMatrix(Matrix33Identity()), m_vOffset ); Matrix34 transform; CalculateWorldTransform( transform, parent_transform.ToMatrix34(), child_transform_node ); return m_vecChild[bone_and_node_index].CalculateNodePositionInSkeletonSpace( node_locator, index, parent_transform * child_transform_node.GetLocalTransform() * offset_transform, child_transform_node ); }
SceneNode* ConstructWall(PresentationNode* material,PresentationNode* containedMaterial,SceneNode* contained){ SceneNode* wall = new TransformNode; wall->AddChild(material); wall->AddChild(containedMaterial); SceneNode* box = ConstructBox(200,6,25); TransformNode* t = new TransformNode; t->AddChild(box); t->Translate(0,14.6f,12.5f); material->AddChild(t); TransformNode* t2 = new TransformNode; t2->AddChild(box); t2->Translate(0,-14.6f,12.5f); material->AddChild(t2); TransformNode* inner = new TransformNode; inner->AddChild(ConstructBox(200,26.2,15)); inner->Translate(0,0,7.5f); material->AddChild(inner); TransformNode* top = new TransformNode; top->AddChild(contained); top->Translate(0,0,20); containedMaterial->AddChild(top); return wall; }
void RotateBehavior::update(SceneNode* node, InputHandler* input, double deltaTime) { TransformNode* transformNode = (TransformNode *)node->getParent(); glm::highp_mat4 trans = transformNode->getTransform(); //glm::highp_vec3 translation = glm::highp_vec3(trans[3][0], trans[3][1], trans[3][2]); glm::highp_vec3 translation = glm::highp_vec3(0, 0, -0.30); trans = glm::translate(trans, -translation); trans = glm::rotate(trans, -1., glm::highp_vec3(0, 1, 0)); trans = glm::translate(trans, translation); transformNode->setNewTransform(trans); }
TransformNode *SceneGraph::findTransformNode(char *name) { if (!name || strlen(name) <= 0) return NULL; for (TransformNode *node = findTransformNode(); node; node = node->nextTraversal()) { const char *nodeName = node->getName(); if (nodeName && strlen(nodeName)) { if (!strcmp(name, nodeName)) return node; } } return NULL; }
// Function to process the Group menu command. void groupSelectedObjects() { if (!onlySiblingsSelected()) return; if (lastSelected == sceneRoot) { sceneRoot = new TransformNode(NULL); sceneRoot->addChild(lastSelected); lastSelected->setParent(sceneRoot); } TransformNode* oldParent = lastSelected->getParent(); oldParent->groupObjects(selections); }
Scene::~Scene() { //clean up all of the basic object heap-allocated memory ListIterator<TransformNode>* ioIter = transformNodes->iterator(); while (ioIter->hasNext()) { TransformNode* tn = ioIter->next(); tn->removeRef(); } delete ioIter; delete transformNodes; delete sceneTransform; }
// Function to verify that no ancestor of the last selected node // is a member of the selection set. bool noParentAncestorSelections() { TransformNode* current = lastSelected->getParent(); while (current) { if (selections.find(current) != selections.end()) { cerr << "Operation not valid for selection set." << endl; cerr << "An ancestor of the last selected item is also selected." << endl; return false; } current = current->getParent(); } return true; }
// Change last selection to previous sibling. void lastSelectedLeft() { TransformNode* parent = lastSelected->getParent(); if (parent) { TransformNode* node = parent->previousChild(lastSelected); if (node) { lastSelected->deSelect(); selections.erase(lastSelected); lastSelected = node; lastSelected->select(); selections.insert(lastSelected); } } }
static void calcOrientation(TransformNode& node, const ofVec3f& orientation) { switch(node.getRotationOrder()) { case TransformNode::ROTATION_ORDER_XYZ: node.setOrientation(orientation.x,ofVec3f(1,0,0), orientation.y,ofVec3f(0,1,0), orientation.z,ofVec3f(0,0,1)); break; case TransformNode::ROTATION_ORDER_YZX: node.setOrientation(orientation.y,ofVec3f(0,1,0), orientation.z,ofVec3f(0,0,1), orientation.x,ofVec3f(1,0,0)); break; case TransformNode::ROTATION_ORDER_ZXY: node.setOrientation(orientation.z,ofVec3f(0,0,1), orientation.x,ofVec3f(1,0,0), orientation.y,ofVec3f(0,1,0)); break; case TransformNode::ROTATION_ORDER_XZY: node.setOrientation(orientation.x,ofVec3f(1,0,0), orientation.z,ofVec3f(0,0,1), orientation.y,ofVec3f(0,1,0)); break; case TransformNode::ROTATION_ORDER_YXZ: node.setOrientation(orientation.y,ofVec3f(0,1,0), orientation.x,ofVec3f(1,0,0), orientation.z,ofVec3f(0,0,1)); break; case TransformNode::ROTATION_ORDER_ZYX: node.setOrientation(orientation.z,ofVec3f(0,0,1), orientation.y,ofVec3f(0,1,0), orientation.x,ofVec3f(1,0,0)); break; } }
void Node::getTranslationMatrix(SFMatrix *mxOut) const { mxOut->init(); for (const Node *node=this; node; node=node->getParentNode()) { if (node->isTransformNode() || node->isBillboardNode()) { SFMatrix mxNode; if (node->isTransformNode()) { float translation[3]; TransformNode *transNode = (TransformNode *)node; transNode->getTranslation(translation); mxNode.setTranslation(translation); } mxNode.add(mxOut); mxOut->setValue(&mxNode); } } }
void Picture::render(Pixel* px) { Color *ambient = new Color(1, 1, 1); Vertex *eye = new Vertex(0,0,0); Light *light = new Light(); double attenuation = 0; //while(true) //{ char* fileName = "sphere.txt"; //cout<<"calling read object"<<endl; BasicObject* sphere = readObject(fileName); sphere->computeSandT(); //sphere->printFaces(); //cout<<"called it bitches"<<endl; //delete[] fileName; //mingw appears to delete this automatically fileName = "trs.txt"; InstanceObject* sphereInstance = buildInstanceObject(fileName, sphere); //delete[] fileName; //obtaining the window transform int widthPixels = px->getWidth(); //the dimensions of the panel on which the drawing will occur int heightPixels = px->getHeight(); getShaderInfo(eye, ambient, light, &attenuation); Scene* scene = new Scene(light, ambient); scene->buildTransform(getCameraTransform("camera.txt")); scene->buildTransform(getPerspectiveTransform("fov.txt", widthPixels, heightPixels)); scene->buildTransform(AffineTransforms::window(widthPixels, heightPixels)); TransformNode* tn = new TransformNode(); tn->addChild(sphereInstance); scene->addTransformNode(tn); //for(;;) //{ scene->render(px, eye, attenuation); //} delete scene; //} }
void Bone::CalculateWorldTransform( Matrix34& dest_transform, const Matrix34& parent_transform, const TransformNode& input_node ) const { if( g_htrans_rev == 3 ) { if( false/*m_TransformStyle & APPLY_LOCAL_ROTATION_TO_OFFSET*/ ) { const Matrix33 matLocalRot = input_node.GetLocalRotationQuaternion().ToRotationMatrix(); const Vector3 vLocalTrans = input_node.GetLocalTranslation() + m_vOffset; /* dest_transform.vPosition = parent_transform.matOrient * matLocalRot * vLocalTrans + parent_transform.vPosition; dest_transform.matOrient = parent_transform.matOrient * matLocalRot; */ dest_transform = parent_transform * Matrix34( input_node.GetLocalTranslation(), matLocalRot ); // * Matrix34( -m_vOffset, Matrix33Transpose(m_matOrient) ); // * Matrix34( m_vOffset, m_matOrient ).GetInverseROT(); // * Matrix34( Vector3(0,0,0), m_matOrient ); } else { Matrix33 matRotation = input_node.GetLocalRotationQuaternion().ToRotationMatrix() * m_matOrient; dest_transform = parent_transform // * Matrix34( input_node.GetLocalTranslation(), input_node.GetLocalRotationQuaternion().ToRotationMatrix() ) // * Matrix34( m_vOffset, Matrix33Identity() ); /// * Matrix34( input_node.GetLocalTranslation() + m_vOffset, input_node.GetLocalRotationQuaternion().ToRotationMatrix() ); /// * Matrix34( input_node.GetLocalTranslation() + m_vOffset, matRotation ); /// * Matrix34( Vector3(0,0,0), matRotation ) * Matrix34( input_node.GetLocalTranslation() + m_vOffset, Matrix33Identity() ); /// * Matrix34( Vector3(0,0,0), m_matOrient ) * Matrix34( input_node.GetLocalTranslation() + m_vOffset, input_node.GetLocalRotationQuaternion().ToRotationMatrix() ); // * Matrix34( input_node.GetLocalTranslation(), input_node.GetLocalRotationQuaternion().ToRotationMatrix() ) * Matrix34( m_vOffset, m_matOrient ); // * Matrix34( input_node.GetLocalTranslation(), input_node.GetLocalRotationQuaternion().ToRotationMatrix() ) * Matrix34( Vector3(0,0,0), m_matOrient ) * Matrix34( m_vOffset, Matrix33Identity() ); // Transforms for arms are not correctly calculated. // The root and other nodes are not correctly transformed for run motion. * Matrix34( m_vOffset, m_matOrient ) * Matrix34( input_node.GetLocalTranslation(), input_node.GetLocalRotationQuaternion().ToRotationMatrix() ); } } else // if( sg_rev == 2 ) { // } }
// Function to verify that selection set includes no two nodes, one of // which is an ancestor of the other. bool noAncestorDescendantSelections() { for (set<TransformNode*>::const_iterator iter = selections.begin(); iter != selections.end(); ++iter) { TransformNode* current = (*iter)->getParent(); while (current) { if (selections.find(current) != selections.end()) { cerr << "Operation not valid for selection set." << endl; cerr << "An ancestor of a selected item is also selected." << endl; return false; } current = current->getParent(); } } return true; }
void Scene::render(Pixel* px) { //Create zbuffer Matrix *zBuffer = new Matrix(px->getHeight(), px->getWidth()); for(int i=0 ; i<px->getHeight() ; i++) { for(int j=0 ; j<px->getWidth() ; j++) { zBuffer->setElement(i, j, -1); } } //loop over all the Instance instances in the Scene and render them ListIterator<TransformNode>* ioIter = transformNodes->iterator(); while (ioIter->hasNext()) { TransformNode* tn = ioIter->next(); tn->render(px, sceneTransform, zBuffer); } delete ioIter; }
// Function to process the Delete menu command. void deleteSelectedObjects() { if (lastSelected == NULL) return; if (!noAncestorDescendantSelections()) return; for (set<TransformNode*>::const_iterator iter = selections.begin(); iter != selections.end(); ++iter) { TransformNode* target = *iter; if (target == sceneRoot) { sceneRoot = new TransformNode(NULL); sceneRoot->addChild(target); target->setParent(sceneRoot); } target->getParent()->removeChild(target); delete target; } selections.clear(); glutPostRedisplay(); }
void TransformNode::SetInterpolatedTransform_r( float frac, const TransformNode& node0, const TransformNode& node1, const TransformNode& node2, const TransformNode& node3 ) { // SetInterpolatedTransform_r( frac, node1, node2 ); // return; Transform local_transform = InterpolateWithTCBSpline( frac, Transform( node0.GetLocalTransform() ), Transform( node1.GetLocalTransform() ), Transform( node2.GetLocalTransform() ), Transform( node3.GetLocalTransform() ) ); SetTransform( local_transform ); const Matrix33 mat = m_Rotation.ToRotationMatrix(); // check the rotation for debugging const size_t num_children = node0.m_vecChildNode.size(); if( m_vecChildNode.size() != num_children ) { m_vecChildNode.resize( num_children ); } for( size_t i=0; i<num_children; i++ ) { m_vecChildNode[i].SetInterpolatedTransform_r( frac, node0.m_vecChildNode[i], node1.m_vecChildNode[i], node2.m_vecChildNode[i], node3.m_vecChildNode[i] ); } }
// Function to process the Copy menu command. void copySelectedObjects() { if (!noAncestorDescendantSelections()) return; for (set<TransformNode*>::const_iterator iter = selections.begin(); iter != selections.end(); ++iter) { TransformNode* target = *iter; if (target == sceneRoot) { sceneRoot = new TransformNode(NULL); sceneRoot->addChild(target); target->setParent(sceneRoot); } TransformNode* parent = target->getParent(); TransformNode* newThing = target->clone(); parent->addChild(newThing); newThing->setParent(parent); target->translate(COPY_OFF_X, COPY_OFF_Y); } glutPostRedisplay(); }
void Scenegraph::animate(float time) { TransformNode * rideTransform = (TransformNode *) root->getNode("car-transform"); TransformNode * seatTransform = (TransformNode *) root->getNode("seat-transform"); if(rideTransform!=NULL) rideTransform->setAnimationTransform(glm::translate(glm::mat4(1.0),glm::vec3(sin(time*10)*100,0,0)) );//* glm::rotate(glm::mat4(1.0),time*10,glm::vec3(0,1,0))); if(seatTransform!=NULL) seatTransform->setAnimationTransform(glm::rotate(glm::mat4(1.0),time*10,glm::vec3(0,1,0))); if(root->getNode("chair") != NULL){ TransformNode *ch1 = NULL; TransformNode *ch2 = NULL; TransformNode *ch3 = NULL; TransformNode *ch4 = NULL; TransformNode *ride = NULL; glm::mat4 temp = glm::mat4(1.0); glm::mat4 temp2 = glm::mat4(1.0); glm::mat4 temp3 = glm::mat4(1.0); glm::mat4 temp4 = glm::mat4(1.0); glm::mat4 temp5 = glm::mat4(1.0); temp = glm::translate(glm::mat4(1),glm::vec3(0,abs(cos(time*3))*12,0)); temp2 = glm::translate(glm::mat4(1),glm::vec3(0,0,abs(cos(time*3))*12)); temp3 = glm::translate(glm::mat4(1),glm::vec3(0,0,-1*abs(cos(time*3))*12)); temp4 = glm::translate(glm::mat4(1),glm::vec3(0,-1*abs(cos(time*3))*12,0)); temp5 *= glm::rotate(glm::mat4(1.0),glm::radians(time*50),glm::vec3(0,1,0)); temp5 *= glm::rotate(glm::mat4(1.0),glm::radians(sin(time*5.0f)*30),glm::vec3(0,0,1)); temp5 *= glm::rotate(glm::mat4(1.0),glm::radians(cos(time*5.0f)*30),glm::vec3(1,0,0)); //temp5 *= glm::rotate(glm::mat4(1.0),glm::radians(40.0f),glm::vec3(1,0,0)); temp *= glm::rotate(glm::mat4(1.0),glm::radians(time*500),glm::vec3(1,0,0)); temp2 *= glm::rotate(glm::mat4(1.0),glm::radians(time*500),glm::vec3(1,0,0)); temp3 *= glm::rotate(glm::mat4(1.0),glm::radians(time*500),glm::vec3(1,0,0)); temp4 *= glm::rotate(glm::mat4(1.0),glm::radians(time*500),glm::vec3(1,0,0)); ch1 = static_cast<TransformNode*> (root->getNode("chair")); ch2 = static_cast<TransformNode*>(root->getNode("chair2")); ch3 = static_cast<TransformNode*>(root->getNode("chair3")); ch4 =static_cast<TransformNode*>( root->getNode("chair4")); ride = static_cast<TransformNode*>( root->getNode("ride")); ch1->setAnimationTransform(temp); ch2->setAnimationTransform(temp2); ch3->setAnimationTransform(temp3); ch4->setAnimationTransform(temp4); ride->setAnimationTransform(temp5); } }
SceneNode* ConstructHouse(float x, float z) { SceneNode* house = new SceneNode; SceneNode* topBottom = ConstructBox(x,x,1); SceneNode* windowWall = new SceneNode; SceneNode* partialWall = new SceneNode; TransformNode* wallBottom = new TransformNode; TransformNode* wallTop = new TransformNode; float panelSize = .2f*x; wallBottom->Translate(0,0,-(z*.25f)); wallTop->Translate(0,0,.4f*z); wallBottom->AddChild(ConstructBox(panelSize,1,z*.5f)); wallTop->AddChild(ConstructBox(panelSize,1,z*.2f)); partialWall->AddChild(wallBottom); partialWall->AddChild(wallTop); SceneNode* fullWall = ConstructBox(panelSize,1,z); for(int i=0;i<5;i++){ TransformNode* wall = new TransformNode; wall->AddChild(i%2 ? partialWall : fullWall); wall->Translate((float)i*panelSize-.4*x,0,0); windowWall->AddChild(wall); } for(int i=0;i<3;i++){ TransformNode* wall = new TransformNode; wall->AddChild(windowWall); wall->Rotate(90*i,0,0,1); wall->Translate(0,.5f*x,.5f*z); house->AddChild(wall); } TransformNode* doorWall = new TransformNode; doorWall->Rotate(-90,0,0,1); doorWall->Translate(0,.5f*x,.5f*z); house->AddChild(doorWall); for(int i=-1;i<2;i+=2){ TransformNode* wall = new TransformNode; wall->Translate(i*.4f*x,0,0); wall->AddChild(fullWall); doorWall->AddChild(wall); } TransformNode* floor = new TransformNode; floor->AddChild(topBottom); TransformNode* ceiling = new TransformNode; ceiling->Translate(0,0,z); ceiling->AddChild(topBottom); house->AddChild(floor); house->AddChild(ceiling); return house; }
/** * Construct a box with the given dimensions. */ SceneNode* ConstructBox(float x, float y, float z) { UnitSquareFlatSurface* xySurf = new UnitSquareFlatSurface(x,y,true,Vector2(),.05f); UnitSquareFlatSurface* xzSurf = new UnitSquareFlatSurface(x,z,true,Vector2(),.05f); UnitSquareFlatSurface* yzSurf = new UnitSquareFlatSurface(z,y,true,Vector2(),.05f); x *= .5; y *= .5; z *= .5; // Contruct transform nodes for the sides of the box. // Perform rotations so the sides face outwards // Bottom is rotated 180 degrees so it faces outwards TransformNode* bottomTransform = new TransformNode; bottomTransform->Translate(0.0f, 0.0f, -z); bottomTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f); // Back is rotated -90 degrees about x: (z -> y) TransformNode* backTransform = new TransformNode; backTransform->Translate(0.0f, y, 0.0f); backTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f); // Front wall is rotated 90 degrees about x: (y -> z) TransformNode* frontTransform = new TransformNode; frontTransform->Translate(0.0f, -y, 0.0f); frontTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f); // Left wall is rotated -90 about y: (z -> -x) TransformNode* leftTransform = new TransformNode; leftTransform->Translate(-x, 0.0f, 00.0f); leftTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f); // Right wall is rotated 90 degrees about y: (z -> x) TransformNode* rightTransform = new TransformNode; rightTransform->Translate(x, 0.0f, 0.0f); rightTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f); // Top TransformNode* topTransform = new TransformNode; topTransform->Translate(0.0f, 0.0f, z); // Create a SceneNode and add the 6 sides of the box. SceneNode* box = new SceneNode; box->AddChild(backTransform); backTransform->AddChild(xzSurf); box->AddChild(leftTransform); leftTransform->AddChild(yzSurf); box->AddChild(rightTransform); rightTransform->AddChild(yzSurf); box->AddChild(frontTransform); frontTransform->AddChild(xzSurf); box->AddChild(bottomTransform); bottomTransform->AddChild(xySurf); box->AddChild(topTransform); topTransform->AddChild(xySurf); return box; }
void Picture::render(int w, int h) { //picture will not look exactly like in class programs //normals used are those from the text file GLuint* tex_num = new GLuint[2]; //obtain two unique integers that have not been used as texture id before glGenTextures(2, tex_num); const char* fileName = "sphere_texture.txt"; BasicObject* sphere = new BasicObject(fileName); //sphere 1 with moon color texture InstanceObject* sphere1 = new InstanceObject(sphere); Color* d1 = new Color(0.3, 0.3, 0.9); sphere1->setDiffuseMaterial(d1); const char* texture = "MoonColor.raw"; Texture* moon_color = new Texture(texture, 512, 256); sphere1->setColorTexture(moon_color, tex_num[0]); //sphere 2 with moon normal map texture InstanceObject* sphere2 = new InstanceObject(sphere); Color* d2 = new Color(1.0, 0.0, 0.0); sphere2->setDiffuseMaterial(d2); const char* normal = "MoonNormal.raw"; Texture* moon_normal = new Texture(normal, 512, 256); sphere2->setColorTexture(moon_normal, tex_num[1]); Scene* scene = new Scene(); TransformNode* tn = new TransformNode(); tn->buildTransform(AffineTransforms::scale(.9, .3, .3)); tn->buildTransform(AffineTransforms::rotateX(90)); tn->buildTransform(AffineTransforms::rotateY(290)); tn->buildTransform(AffineTransforms::translate(0, 0, 0)); tn->addChild(sphere1); scene->addTransformNode(tn); tn = new TransformNode(); tn->buildTransform(AffineTransforms::scale(.7, 1.3, .7)); tn->buildTransform(AffineTransforms::rotateX(90)); tn->buildTransform(AffineTransforms::rotateZ(290)); tn->buildTransform(AffineTransforms::translate(-.75, .75, 0)); tn->addChild(sphere2); scene->addTransformNode(tn); scene->render(w, h); delete scene; }
void Picture::render(Pixel* pix) { Matrix* T; Matrix* R; Matrix* S; Matrix* T2; Matrix* T3; // Get BasicObjects BasicObject* cube = readObject( "cube.txt" ); BasicObject* cyli = readObject( "cylinder.txt" ); // BasicObject* sphere = readObject( "sphere.txt" ); //WA Matrix* wnd_trns = AffineTransforms::windowingTransform(pix->getWidth(), pix->getHeight()); Matrix* aspct_ratio = AffineTransforms::aspectRatio(pix->getWidth(), pix->getHeight()); // Matrix for aspect ratio. // Concatenate wnd_trns and aspct_ratio. Matrix* wa = wnd_trns->multiply( aspct_ratio ); delete wnd_trns; delete aspct_ratio; Scene* scene = new Scene(wa); // Robot 1 Arm Matrix* robot1; S = AffineTransforms::scale( 0.2, 0.2, 0.2 ); T = AffineTransforms::translate(0.0, 0.0, -3.0); robot1 = T->multiply(S); delete S; delete T; // Robot 2 Arm Matrix* robot2; T = AffineTransforms::translate(-3.0,0.5,0.0); S = AffineTransforms::scale( 0.2, 0.2, 0.2 ); R = AffineTransforms::rotateX(45.0); robot2 = S->multiply(T->multiply(R->multiply(S))); delete T; delete S; delete R; // Create Base InstanceObject* base = buildInstanceObject( "base.txt", cyli ); T = AffineTransforms::translate( 0.0, -2.0, 0.0 ); R = AffineTransforms::rotateY( 30.0 ); TransformNode* baseT = new TransformNode(T->multiply( R )); delete T; delete R; // Create Lower Arm InstanceObject* lower_arm = buildInstanceObject( "lower_arm.txt", cube ); T = AffineTransforms::translate( 0.0, 3.0, 0.0 ); T2 = AffineTransforms::translate( 0.0, -2.0, 0.0 ); R = AffineTransforms::rotateZ( -20.0 ); T3 = AffineTransforms::translate( 0.0, 2.0, 0.0 ); TransformNode* lowerT = new TransformNode(T->multiply(T2->multiply( R->multiply(T3)))); delete T; delete T2; delete T3; delete R; // Create Upper Arm InstanceObject* upper_arm = buildInstanceObject( "upper_arm.txt", cube ); T = AffineTransforms::translate( 0.0,3.0, 0.0 ); T2 = AffineTransforms::translate( 0, -1.0, 0 ); R = AffineTransforms::rotateZ( 90 ); T3 = AffineTransforms::translate( 0.0, 1.0, 0.0 ); TransformNode* upperT = new TransformNode(T->multiply(T2->multiply( R->multiply(T3)))); delete T; delete T2; delete T3; delete R; // Create sphere /*InstanceObject* ball = buildInstanceObject( "sphere_trs.txt", sphere ); InstanceObject* clamp = buildInstanceObject( "clamp1.txt", cube ); InstanceObject* clamp2 = buildInstanceObject( "clamp2.txt", cube );*/ // Connect the pieces. baseT->addNode( base ); lowerT->addNode( lower_arm ); lowerT->addNode( upperT ); upperT->addNode( upper_arm ); /* upperT->addNode( clamp ); upperT->addNode( clamp2 ); upperT->addNode( ball );*/ baseT->addNode( lowerT ); // Create Robot Arm 1 TransformNode* tn1 = new TransformNode( robot1 ); tn1->addNode( baseT ); TransformNode* tn2 = new TransformNode( robot2 ); tn2->addNode( baseT ); // Scene creation scene->addNode( tn1 ); scene->addNode( tn2 ); //while(1){ scene->render( pix ); //} delete scene; }
bool CManipRot::UIEventHandler( const ui::Event& EV ) { int ex = EV.miX; int ey = EV.miY; CVector2 posubp = EV.GetUnitCoordBP(); CCamera *pcam = mManager.GetActiveCamera(); bool brval = false; bool isshift = false; //CSystem::IsKeyDepressed(VK_SHIFT ); bool isctrl = false; //CSystem::IsKeyDepressed(VK_CONTROL ); switch( EV.miEventCode ) { case ui::UIEV_PUSH: { mManager.mManipHandler.Init(posubp, pcam->mCameraData.GetIVPMatrix(), pcam->QuatC ); mBaseTransform = mManager.mCurTransform; SelectBestPlane(posubp); brval = true; } break; case ui::UIEV_RELEASE: { mManager.DisableManip(); brval = true; } break; case ui::UIEV_DRAG: { IntersectWithPlanes( posubp ); if ( CheckIntersect() ) { /////////////////////////////////////////// // calc normalvectors from base:origin to point on activeintersection plane (in world space) const CVector3 & Origin = mBaseTransform.GetTransform().GetPosition(); CVector3 D1 = (Origin-mActiveIntersection->mIntersectionPoint).Normal(); CVector3 D0 = (Origin-mActiveIntersection->mBaseIntersectionPoint).Normal(); /////////////////////////////////////////// // calc matrix to put worldspace vector into plane local space CMatrix4 MatWldToObj = mBaseTransform.GetTransform().GetMatrix(); //GetRotation(); MatWldToObj.Inverse(); CVector4 bAxisAngle = mLocalRotationAxis; CQuaternion brq; brq.FromAxisAngle(bAxisAngle); CMatrix4 MatObjToPln = brq.ToMatrix(); MatObjToPln.Inverse(); CMatrix4 MatWldToPln = MatObjToPln*MatWldToObj; //CMatrix4 MatInvRot = InvQuat.ToMatrix(); /////////////////////////////////////////// // calc plane local rotation CVector4 AxisAngle = mLocalRotationAxis; CVector4 D0I = CVector4(D0,CReal(0.0f)).Transform(MatWldToPln); CVector4 D1I = CVector4(D1,CReal(0.0f)).Transform(MatWldToPln); //orkprintf( "D0 <%f %f %f>\n", float(D0.GetX()), float(D0.GetY()), float(D0.GetZ()) ); //orkprintf( "D1 <%f %f %f>\n", float(D1.GetX()), float(D1.GetY()), float(D1.GetZ()) ); //orkprintf( "D0I <%f %f %f>\n", float(D0I.GetX()), float(D0I.GetY()), float(D0I.GetZ()) ); //orkprintf( "D1I <%f %f %f>\n", float(D1I.GetX()), float(D1I.GetY()), float(D1I.GetZ()) ); AxisAngle.SetW( CalcAngle(D0I,D1I) ); CQuaternion RotQ; RotQ.FromAxisAngle( AxisAngle ); /////////////////// // Rot Snap if( isshift ) { CReal SnapAngleVal( PI2/16.0f ); CVector4 NewAxisAngle = RotQ.ToAxisAngle(); CReal Angle = NewAxisAngle.GetW(); Angle = SnapReal( Angle, SnapAngleVal ); NewAxisAngle.SetW( Angle ); RotQ.FromAxisAngle( NewAxisAngle ); } /////////////////// // accum rotation CQuaternion oq = mBaseTransform.GetTransform().GetRotation(); CQuaternion NewQ = RotQ.Multiply(oq); /////////////////// // Rot Reset To Identity if( isctrl && isshift ) { NewQ.FromAxisAngle( CVector4( CReal(0.0f), CReal(1.0f), CReal(0.0f), CReal(0.0f) ) ); } /////////////////// TransformNode mset = mManager.mCurTransform; mset.GetTransform().SetRotation( NewQ ); mManager.ApplyTransform( mset ); /////////////////// } brval = true; } break; default: break; } return brval; }
/** * Construct a unit box. * @param unitSquare Geometry node to use */ SceneNode* ConstructUnitBox(UnitSquareSurface* unitSquare) { // Contruct transform nodes for the sides of the box. // Perform rotations so the sides face outwards // Bottom is rotated 180 degrees so it faces outwards TransformNode* bottomTransform = new TransformNode; bottomTransform->Translate(0.0f, 0.0f, -0.5f); bottomTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f); // Back is rotated -90 degrees about x: (z -> y) TransformNode* backTransform = new TransformNode; backTransform->Translate(0.0f, 0.5f, 0.0f); backTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f); // Front wall is rotated 90 degrees about x: (y -> z) TransformNode* frontTransform = new TransformNode; frontTransform->Translate(0.0f, -0.5f, 0.0f); frontTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f); // Left wall is rotated -90 about y: (z -> -x) TransformNode* leftTransform = new TransformNode; leftTransform->Translate(-0.5f, 0.0f, 00.0f); leftTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f); // Right wall is rotated 90 degrees about y: (z -> x) TransformNode* rightTransform = new TransformNode; rightTransform->Translate(0.5f, 0.0f, 0.0f); rightTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f); // Top TransformNode* topTransform = new TransformNode; topTransform->Translate(0.0f, 0.0f, 0.50f); // Create a SceneNode and add the 6 sides of the box. SceneNode* box = new SceneNode; box->AddChild(backTransform); backTransform->AddChild(unitSquare); box->AddChild(leftTransform); leftTransform->AddChild(unitSquare); box->AddChild(rightTransform); rightTransform->AddChild(unitSquare); box->AddChild(frontTransform); frontTransform->AddChild(unitSquare); box->AddChild(bottomTransform); bottomTransform->AddChild(unitSquare); box->AddChild(topTransform); topTransform->AddChild(unitSquare); return box; }
/** * Construct room as a child of the specified node * @param parent Parent node * @param unitSquare Geometry node to use */ void ConstructRoom(SceneNode* parent, UnitSquareSurface* unitSquare) { // Contruct transform nodes for the walls. Perform rotations so the // walls face inwards TransformNode* floorTransform = new TransformNode; floorTransform->Scale(200.0f, 200.0f, 1.0f); // Back wall is rotated +90 degrees about x: (y -> z) TransformNode* backWallTransform = new TransformNode; backWallTransform->Translate(0.0f, 100.0f, 40.0f); backWallTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f); backWallTransform->Scale(200.0f, 80.0f, 1.0f); // Front wall is rotated -90 degrees about x: (z -> y) TransformNode* frontWallTransform = new TransformNode; frontWallTransform->Translate(0.0f, -100.0f, 40.0f); frontWallTransform->Rotate(-90.0f, 1.0f, 0.0f, 0.0f); frontWallTransform->Scale(200.0f, 80.0f, 1.0f); // Left wall is rotated 90 degrees about y: (z -> x) TransformNode* leftWallTransform = new TransformNode; leftWallTransform->Translate(-100.0f, 0.0f, 40.0f); leftWallTransform->Rotate(90.0f, 0.0f, 1.0f, 0.0f); leftWallTransform->Scale(80.0f, 200.0f, 1.0f); // Right wall is rotated -90 about y: (z -> -x) TransformNode* rightWallTransform = new TransformNode; rightWallTransform->Translate(100.0f, 0.0f, 40.0f); rightWallTransform->Rotate(-90.0f, 0.0f, 1.0f, 0.0f); rightWallTransform->Scale(80.0f, 200.0f, 1.0f); // Ceiling is rotated 180 about x so it faces inwards TransformNode* ceilingTransform = new TransformNode; ceilingTransform->Translate(0.0f, 0.0f, 80.0f); ceilingTransform->Rotate(180.0f, 1.0f, 0.0f, 0.0f); ceilingTransform->Scale(200.0f, 200.0f, 1.0f); // Floor should be tan, mostly dull PresentationNode* floorMaterial = new PresentationNode; floorMaterial->SetMaterialAmbientAndDiffuse(Color4(0.3f, 0.45f, 0.1f)); floorMaterial->SetMaterialSpecular(Color4(0.1f, 0.1f, 0.1f)); floorMaterial->SetMaterialShininess(2.0f); // Make the walls reddish, slightly shiny PresentationNode* wallMaterial = new PresentationNode; wallMaterial->SetMaterialAmbientAndDiffuse(Color4(0.7f, 0.55f, 0.55f)); wallMaterial->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f)); wallMaterial->SetMaterialShininess(16.0f); // Ceiling should be white, moderately shiny PresentationNode* ceilingMaterial = new PresentationNode; ceilingMaterial->SetMaterialAmbientAndDiffuse(Color4(1.0f, 1.0f, 1.0f)); ceilingMaterial->SetMaterialSpecular(Color4(0.9f, 0.9f, 0.9f)); ceilingMaterial->SetMaterialShininess(64.0f); // Add floor and ceiling to the parent. Use convenience method to add material, // then presentation, then geometry. AddSubTree(parent, floorMaterial, floorTransform, unitSquare); AddSubTree(parent, ceilingMaterial, ceilingTransform, unitSquare); // Walls. We can group these all under a single presentation node. parent->AddChild(wallMaterial); wallMaterial->AddChild(backWallTransform); backWallTransform->AddChild(unitSquare); wallMaterial->AddChild(leftWallTransform); leftWallTransform->AddChild(unitSquare); wallMaterial->AddChild(rightWallTransform); rightWallTransform->AddChild(unitSquare); wallMaterial->AddChild(frontWallTransform); frontWallTransform->AddChild(unitSquare); }
/** * Construct table * @param unitSquare Geometry node to use for table top * @param legs Geometry node to use for legs * @return Returns a scene node representing the table */ SceneNode* ConstructTable(SceneNode* box, ConicSurface* leg) { // Table legs (relative to center of table) TransformNode* lfLegTransform = new TransformNode; lfLegTransform->Translate(-20.0f, -10.0f, 10.0f); lfLegTransform->Scale(3.0f, 3.0f, 20.0f); TransformNode* lrLegTransform = new TransformNode; lrLegTransform->Translate(-20.0f, 10.0f, 10.0f); lrLegTransform->Scale(3.0f, 3.0f, 20.0f); TransformNode* rfLegTransform = new TransformNode; rfLegTransform->Translate(20.0f, -10.0f, 10.0f); rfLegTransform->Scale(3.0f, 3.0f, 20.0f); TransformNode* rrLegTransform = new TransformNode; rrLegTransform->Translate(20.0f, 10.0f, 10.0f); rrLegTransform->Scale(3.0f, 3.0f, 20.0f); // Construct dimensions for the table top TransformNode* topTransform = new TransformNode; topTransform->Translate(0.0f, 0.0f, 23.0f); topTransform->Scale(60.0f, 30.0f, 6.0f); // Create the tree SceneNode* table = new SceneNode; table->AddChild(topTransform); topTransform->AddChild(box); table->AddChild(lfLegTransform); lfLegTransform->AddChild(leg); table->AddChild(rfLegTransform); rfLegTransform->AddChild(leg); table->AddChild(lrLegTransform); lrLegTransform->AddChild(leg); table->AddChild(rrLegTransform); rrLegTransform->AddChild(leg); return table; }
/** * Construct the scene */ void ConstructScene() { // -------------------- Geometry -------------------- // movingSquare = new UnitSquareFlatSurface(200,32.2f*.814f,true,Vector2(-.01f,0),.03f); SceneNode* house = ConstructHouse(70,90); // Construct a unit cylinder surface WasherSurface* cylinder = new WasherSurface(.9f, 1.0f, 18); //Wheel WasherSurface* washer = new WasherSurface(10,20,14); std::vector<LightNode*> lights; lights.push_back(new LightNode(GL_LIGHT3)); lights.push_back(new LightNode(GL_LIGHT4)); wheel = new WheelNode(10,20,washer,ConstructBox(9,19.5f,1),8,4,lights); waterfall = new ParticleNode(25); //-------------------- Materials ------------------------- // // Wood PresentationNode* wood = new PresentationNode; wood->SetMaterialAmbientAndDiffuse(Color4(0.5f, 0.5f, 0.5f)); wood->SetMaterialSpecular(Color4(0.3f, 0.3f, 0.3f)); wood->SetMaterialShininess(32.0f); wood->setTexture(LoadTextureBMP("images/wood.bin",true,128)); // Stone PresentationNode* stone = new PresentationNode; stone->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f)); stone->SetMaterialDiffuse(Color4(0.50754f, 0.50754f, 0.50754f)); stone->SetMaterialSpecular(Color4(0.508273f, 0.508273f, 0.508273f)); stone->SetMaterialShininess(10.2f); stone->setTexture(LoadTextureBMP("images/stone.bin",true,128)); PresentationNode* steel = new PresentationNode; steel->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f)); steel->SetMaterialDiffuse(Color4(0.7f, 0.7f, 0.7f)); steel->SetMaterialSpecular(Color4(0.7f, 0.7f, 0.7f)); steel->SetMaterialShininess(90.2f); // Water PresentationNode* water = new PresentationNode; water->SetMaterialAmbient(Color4(0.01f, 0.01f, 0.1f)); water->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f)); water->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f)); water->SetMaterialShininess(10); water->setTexture(LoadTextureBMP("images/water.bin",true,128)); PresentationNode* blue = new PresentationNode; blue->SetMaterialAmbient(Color4(0.01f, 0.01f, 0.1f)); blue->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f)); blue->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f)); blue->SetMaterialShininess(10); // ------------------ Transformations ------------------- // TransformNode* wheelTransform = new TransformNode; wheelTransform->Translate(-80.0f, 35.0f, 40.0f); wheelTransform->Rotate(90.0f, 1.0f, 0.0f, 0.0f); TransformNode* houseTransform = new TransformNode; houseTransform->Translate(-100,35,0); TransformNode* house2Transform = new TransformNode; house2Transform->Rotate(180,0,0,1); house2Transform->Translate(-100,-35,0); TransformNode* wallTransform = new TransformNode; wallTransform->Translate(0,35,0); TransformNode* waterfallTransform = new TransformNode; waterfallTransform->Translate(-128.0f,35,15.0f); TransformNode* pipeTransform = new TransformNode; pipeTransform->Rotate(-90,0,1,0); pipeTransform->Translate(76.5f,35,125); pipeTransform->Scale(5,5,20); // -------------------- Lighting --------------------------/ // Light 0 - point light source in back right corner LightNode* light0 = new LightNode(GL_LIGHT0); light0->SetDiffuse(Color4(0.5f, 0.5f, 0.5f, 1.0f)); light0->SetSpecular(Color4(0.5f, 0.5f, 0.5f, 1.0f)); light0->SetPosition(HPoint3(90.0f, 90.0f, 30.f, 1.0f)); light0->Enable(); // Light1 - directional light from the ceiling LightNode* light1 = new LightNode(GL_LIGHT1); light1->SetDiffuse(Color4(0.7f, 0.7f, 0.7f, 1.0f )); light1->SetSpecular(Color4(0.7f, 0.7f, 0.7f, 1.0f)); light1->SetPosition(HPoint3(0.0f, 0.0f, 1.0f, 0.0f)); light1->Enable(); // Light2 - spotlight - we will place at the camera location // shining along -VPN LightNode* light2 = new LightNode(GL_LIGHT2); light2->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f )); light2->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f)); light2->SetPosition(HPoint3(0.0f, 0.0f, 0.0f, 1.0f)); light2->SetSpotlight(Vector3(0.0f, 0.0f, -1.0f), 32.0f, 30.0f); light2->Enable(); lights[0]->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f)); lights[0]->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f)); lights[0]->SetPosition(HPoint3(-100.0f,35.0f,90.0f,1.0f)); lights[0]->SetSpotlightDirection(Vector3(0,0,-1)); lights[0]->SetSpotlight(Vector3(0,0,-1),1,90); lights[0]->Disable(); lights[1]->SetDiffuse(Color4(0.8f, 0.8f, 0.8f, 1.0f)); lights[1]->SetSpecular(Color4(0.8f, 0.8f, 0.8f, 1.0f)); lights[1]->SetPosition(HPoint3(100.0f,35.0f,90.0f,1.0f)); lights[1]->SetSpotlightDirection(Vector3(0,0,-1)); lights[1]->SetSpotlight(Vector3(0,0,-1),1,90); lights[1]->Disable(); // --------------------------- Camera ----------------------- // MyCamera = new CameraNode; MyCamera->SetPosition(Point3(100.0f, -100.0f, 50.0f)); MyCamera->SetLookAtPt(Point3(0.0f, 0.0f, 50.0f)); MyCamera->SetViewUp(Vector3(0.0, 0.0, 1.0)); MyCamera->SetPerspective(50.0, 1.0, 1.0, 2400); // --------------------- Scene construction ----------------- // // Construct the scene root node SceneRoot = new SceneNode; // Create a scene node to hold all scene objects (other than camera // and lights) SceneNode* myScene = new SceneNode; // Add the spotlight as the first child of the root node. Since this is // accessed before the camera it will position the light relative to the // camera SceneRoot->AddChild(light2); // Set the camera SceneRoot->AddChild(MyCamera); MyCamera->AddChild(light0); MyCamera->AddChild(light1); MyCamera->AddChild(lights[0]); MyCamera->AddChild(lights[1]); MyCamera->AddChild(myScene); // Construct the room (walls, floor, ceiling) SceneNode* skybox = ConstructRoom(); wallTransform->AddChild(ConstructWall(stone,water,movingSquare)); myScene->AddChild(wallTransform); // Construct the wheel AddSubTree(myScene,wood,wheelTransform,wheel); // Place 2 Houses wood->AddChild(houseTransform); houseTransform->AddChild(house); wood->AddChild(house2Transform); house2Transform->AddChild(house); myScene->AddChild(skybox); AddSubTree(myScene,steel,pipeTransform,cylinder); AddSubTree(myScene,blue,waterfallTransform,waterfall); }
/** * Construct the scene */ void ConstructScene() { // Construct the lighting shader node LightingShaderNode* lightingShader = new LightingShaderNode(); if (!lightingShader->Create("phong.vert", "phong.frag") || !lightingShader->GetLocations()) exit(-1); int positionLoc = lightingShader->GetPositionLoc(); int normalLoc = lightingShader->GetNormalLoc(); // -------------------- Geometry -------------------- // // Construct a unit square - use less subdivisions to see how // phong shading improves the lighting UnitSquareSurface* unitSquare = new UnitSquareSurface(2, positionLoc, normalLoc); // Construct a unit box SceneNode* box = ConstructUnitBox(unitSquare); // Construct a unit cylinder surface ConicSurface* cylinder = new ConicSurface(1.0f, 1.0f, 18, 4, positionLoc, normalLoc); // Construct a torus TorusSurface* torus = new TorusSurface(20.0f, 5.0f, 18, 18, positionLoc, normalLoc); // Teapot MeshTeapot* teapot = new MeshTeapot(3, positionLoc, normalLoc); // Sphere SphereSection* sphere = new SphereSection(-90.0f, 90.0f, 18, -180.0f, 180.0f, 36, 1.0f, positionLoc, normalLoc); //-------------------- Materials ------------------------- // // Wood PresentationNode* wood = new PresentationNode; wood->SetMaterialAmbientAndDiffuse(Color4(0.55f, 0.45f, 0.15f)); wood->SetMaterialSpecular(Color4(0.3f, 0.3f, 0.3f)); wood->SetMaterialShininess(64.0f); // Silver PresentationNode* silver = new PresentationNode; silver->SetMaterialAmbient(Color4(0.19225f, 0.19225f, 0.19225f)); silver->SetMaterialDiffuse(Color4(0.50754f, 0.50754f, 0.50754f)); silver->SetMaterialSpecular(Color4(0.508273f, 0.508273f, 0.508273f)); silver->SetMaterialShininess(51.2f); // Black, shiny PresentationNode* shinyBlack = new PresentationNode; shinyBlack->SetMaterialAmbient(Color4(0.0f, 0.0f, 0.0f)); shinyBlack->SetMaterialDiffuse(Color4(0.01f, 0.01f, 0.01f)); shinyBlack->SetMaterialSpecular(Color4(0.5f, 0.5f, 0.5f)); shinyBlack->SetMaterialShininess(32.0f); // Shiny blue PresentationNode* shinyBlue = new PresentationNode; shinyBlue->SetMaterialAmbient(Color4(0.05f, 0.05f, 0.2f)); shinyBlue->SetMaterialDiffuse(Color4(0.2f, 0.2f, 0.6f)); shinyBlue->SetMaterialSpecular(Color4(0.75f, 0.75, 0.75f)); shinyBlue->SetMaterialShininess(76.8f); // ------------------ Transformations ------------------- // // Position the table in the room TransformNode* tableTransform = new TransformNode; tableTransform->Translate(-50.0f, 50.0f, 0.0f); tableTransform->Rotate(30.0f, 0.0f, 0.0f, 1.0f); // Teapot transform TransformNode* teapotTransform = new TransformNode; teapotTransform->Translate(0.0f, 0.0f, 26.0f); teapotTransform->Scale(2.5f, 2.5f, 2.5f); // Torus TransformNode* torusTransform = new TransformNode; torusTransform->Translate(0.0f, 90.0f, 20.0f); torusTransform->Rotate(60.0f, 1.0f, 0.0f, 0.0f); // Sphere TransformNode* sphereTransform = new TransformNode; sphereTransform->Translate(80.0f, 20.0f, 10.0f); sphereTransform->Scale(10.0f, 10.0f, 10.0f); // --------------------------- Camera ----------------------- // MyCamera = new CameraNode; MyCamera->SetPosition(Point3(0.0f, -100.0f, 20.0f)); MyCamera->SetLookAtPt(Point3(0.0f, 0.0f, 20.0f)); MyCamera->SetViewUp(Vector3(0.0, 0.0, 1.0)); MyCamera->SetPerspective(50.0, 1.0, 1.0, 300.0); // -------------------- Lighting --------------------------/ // Set the global light ambient Color4 globalAmbient(0.4f, 0.4f, 0.4f, 1.0f); lightingShader->SetGlobalAmbient(globalAmbient); // Light 0 - point light source in back right corner LightNode* light0 = new LightNode(0); light0->SetDiffuse(Color4(0.5f, 0.5f, 0.5f, 1.0f)); light0->SetSpecular(Color4(0.5f, 0.5f, 0.5f, 1.0f)); light0->SetPosition(HPoint3(90.0f, 90.0f, 30.f, 1.0f)); light0->Enable(); // Light1 - directional light from the ceiling LightNode* light1 = new LightNode(1); light1->SetDiffuse(Color4(0.7f, 0.7f, 0.7f, 1.0f )); light1->SetSpecular(Color4(0.7f, 0.7f, 0.7f, 1.0f)); light1->SetPosition(HPoint3(0.0f, 0.0f, 1.0f, 0.0f)); light1->Enable(); // Spotlight - reddish spotlight - we will place at the camera location // shining along -VPN Spotlight = new LightNode(2); Spotlight->SetDiffuse(Color4(0.5f, 0.1f, 0.1f, 1.0f )); Spotlight->SetSpecular(Color4(0.5f, 0.1f, 0.1f, 1.0f)); Point3 pos = MyCamera->GetPosition(); Spotlight->SetPosition(HPoint3(pos.x, pos.y, pos.z, 1.0f)); Vector3 dir = MyCamera->GetViewPlaneNormal() * -1.0f; Spotlight->SetSpotlight(dir, 32.0f, 30.0f); Spotlight->Enable(); // --------------------- Scene construction ----------------- // // Construct the scene root node SceneRoot = new SceneNode; SceneRoot->AddChild(lightingShader); lightingShader->AddChild(MyCamera); // Add the lights as the children of the camera MyCamera->AddChild(light0); light0->AddChild(light1); light1->AddChild(Spotlight); // Create a scene node to hold all scene objects (other than camera // and lights) SceneNode* myScene = new SceneNode; // Add the scene under the last light Spotlight->AddChild(myScene); // Construct the room (walls, floor, ceiling) ConstructRoom(myScene, unitSquare); // Construct the table SceneNode* table = ConstructTable(box, cylinder); myScene->AddChild(wood); wood->AddChild(tableTransform); tableTransform->AddChild(table); // Place a teapot on the table tableTransform->AddChild(teapotTransform); teapotTransform->AddChild(silver); silver->AddChild(teapot); // Place a torus myScene->AddChild(shinyBlack); shinyBlack->AddChild(torusTransform); torusTransform->AddChild(torus); // Place a sphere myScene->AddChild(shinyBlue); shinyBlue->AddChild(sphereTransform); sphereTransform->AddChild(sphere); }