Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

Draw Using Polygon Meshes in OPEN GL

Hi Friends,

Can you anybody tell me how do i design a bath, shower, hand basin, mirror and a door and window using polygon meshes.I have no idea on how to create it.Is there any software were i can do it.

And how i add shadow effectes to the objects to it.Please help me to solve this problem.As i am very very new to opengl.Please guide me on how to start doing it.


Thanks
0
srihari1986
Asked:
srihari1986
1 Solution
 
puranik_pCommented:
0
 
Andrew BeersCommented:
Ok... for one you are wanting to get into some very very advanced topics for being very new with openGL.  Mirrors are one of the harder elements to understand conceptually and to program...

So lets start there:

OpenGL works off of a giant display matrix, to get the undistorted reflection you can pull that display matrix and throw it into an array and then reuse it as a texture to paste on the panel that you create.  There are some very complicated algorithms for calculating angles and refraction rates for lighting and the reflection itself based on what view angle the camera is located.  

You are going to want to look into minimaps and nurbs <mainly nurbs> for creating your actual geometry (Polygon meshing).  

Realistic shadowing is another complicated subject especially with mutliple light sources in an area such as a bathroom, this once again does some pretty cool but wicked combinations and calculations on the display matrix, (If you use double buffering for real time animation which I assume you will be this keeps the image from getting too horridly distorted while rerendering the object, and for as many things as you can you want to use display lists to speed up your animation.

Ok... I think I gave you enough keywords to search on and look for when you are looking for information.  *Winks*  This is a very broad topic which would required a LOT of learning.

There is software out there, namely maya 6.0 that would let you create these objects but uless you can drop >$1k for a piece of commercial grade software this task you wish to undertake is far from easy.

Some light reading for you:
nehe.gamedev.net

is an excellent starting point for you to begin reading.  I have a book at home that is another excellent book / resource for beginning openGL programmers which I will post the ISBN for when I get home.

Feel free to continue expanding on your questions and hopefully limiting the answer sizes to specific questions instead of as broad as your current.  If you can give me specific things to explain I would be more than happy to.  I'll keep an eye out.

~Aqua
0
 
_corey_Commented:
I might suggest checking out Maya.  However, an actual product you can use will depend on the budget you have and use.

http://www.alias.com/eng/products-services/maya/maya_ple/index.shtml ["Maya Personal Learning Edition"]

corey
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
srihari1986Author Commented:
Hi Aqua,

I am going through the nehe.gamedev.net.Seems to be a very good website for begineers.

tHANKS
0
 
Andrew BeersCommented:
*Nods*  Nehe is a great consortium for all aspiring graphical animation artists.  *Winks*

The book I was talking about is:
OpenGL Game Programming
By:
Kevin Hawkins
and
Dave Astle
ISBN:  0-7615-3330-3

If you have any other questions on your topic you'd like to ask here feel free... There has been a lack of decent questions in game dev to devote any time to answering.

~Aqua
0
 
srihari1986Author Commented:
Hi Aqua,

Thanks for the info on the book.Anyway i have read through the gamedev website and statred the project at last.And now i have started by doing the walls of the rooms using grid polgon and succeddully finished it.Now i need to move around the room using the arrow key.How do i do that.I have gone through so many articles but could not find any good one.Can you gruide me on how to start doing that.And i should nt be able to go out of the room via the walls.The user should stop there.

Thanks
0
 
Andrew BeersCommented:
Heh.. I can give you full code to do it with the number pad.. I happen to have one sitting in my reserves... *winks*

Hmmm... tho I can't attach files here but I can post my code.  ;-)

(Note this code is very old and hasn't been reviewed in a while so please no criticism from the peanut gallery *ahem* davebytes)

CAMERA FILE:


#include <glut.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
//#include "Points.h"

//using namespace std;

class Camera{
   private:
            
            float currentLook;
            float currentPitch;

            static const float moveBy = 1.;
            static const float lookRadius = .5;
            static const float cameraHeight = 1.5;
            static const float PI = 3.1416;
            static const float yawn = PI / 32.0;
            static const float turnVal = PI / 32.0;
            static const float pitchMax = PI / 4.0;
            static const float pitchMin = -1.0 * PI / 4.0;

      public:
           static Point pubAt;
           static Point pubLook;
        Point atLoc;
            Point looking;

            //Default class constructor sets the camera position at
            //      0, cameraHeight, 0
            //      Sets the looking position to
            //      0 PI along the distance lookRadius
            Camera()
            {
                  float x, y, z;
                  currentLook = 0.0;
                  currentPitch = 0.0;

                  Point tLoc(0.0, cameraHeight, 0.0);
                  atLoc.copy(tLoc);
                  x = atLoc.getX() + cos(currentLook) * lookRadius;
                  y = atLoc.getY();
                  z = atLoc.getZ() + sin(currentLook) * lookRadius;
                  
                  Point tLook(x, y, z);
                  looking.copy(tLook);
            }

            //Class constructor takes in tempAt for camera location
            //      and the looking angle.
            //      +X Axis is 0 PI
            //      +Z Axis is 1/2 PI
            //      -X Axis is PI
            //      -Z Axis is 3/2 PI
            Camera(Point tempAt, float angle)
            {
                  float x, y, z;
                  currentLook = angle;
                  currentPitch = 0.0;

                  atLoc.copy(tempAt);
                  x = atLoc.getX() + cos(currentLook) * lookRadius;
                  y = atLoc.getY();
                  z = atLoc.getZ() + sin(currentLook) * lookRadius;
                  
                  Point tLook(x, y, z);
                  looking.copy(tLook);
            }

            //Copy Constructor
            //      Takes in a camera and assigns a new camera
            //      to be an identical copy of the camera passed in
            Camera(Camera &a)
            {
                  currentLook = a.currentLook;
                  currentPitch = a.currentPitch;
                  
                  atLoc.copy(a.atLoc);
                  looking.copy(a.looking);      
            }

            //Takes in a direction:
            //      1 - Increases the angle (aka CCW)
            //      -1 - Decreases the angle (aka CW)
            //      value of change is turn
            void turn(int dir){
                  float x, y, z;
                  if(dir == 1){
                        currentLook += turnVal;
                  }
                  else{
                        currentLook -= turnVal;
                  }

                  x = atLoc.getX() + sin(currentLook) * lookRadius;
                  y = looking.getY();
                  z = atLoc.getZ() + cos(currentLook) * lookRadius;
                  
                  Point tLook(x, y, z);
                  looking.copy(tLook);
            }

            //Takes in a direction:
            //      1 - Increases the angle - Y Axis (aka Up)
            //      -1 - Decreases the angle (aka down)
            //      value of change is pitch
            //      Constraints:      pitchMin <= currentPitch <= pitchMax
            void pitch(int dir){
                  float x, y, z;
                  if(dir == 1){
                        if(currentPitch <= pitchMax){
                              currentPitch += yawn;
                        }
                  }
                  else{
                        if(currentPitch >= pitchMin){
                              currentPitch -= yawn;
                        }
                  }
                  
                  y = atLoc.getY() + sin(currentPitch) * lookRadius;
                  looking.setY(y);
            }

            //Sets glu Camera with values stored in this instantiation
            void updateCamera()
            {
                  gluLookAt(atLoc.getX(), atLoc.getY(), atLoc.getZ(),
                        looking.getX(), looking.getY(), looking.getZ(),
                        0.0, 1.0, 0.0);

                  if(currentLook >= (2.0 * PI) ){
                        currentLook -= (2.0 * PI);
                  }
            }

            //Takes in a direction:
            //      1 is left
            //      -1 is right
            //      Moves by moveBy units
            void strafe(int dir){
                  Point strafeDir;
                  float x, y, z;
                  float dist;
                  if(dir == 1){
                  //Strafe left
                        x = atLoc.getX() + sin(currentLook + (PI / 2.0) ) * lookRadius;
                        z = atLoc.getZ() + cos(currentLook + (PI / 2.0) ) * lookRadius;
                        dist = moveBy;
                  }
                  else{
                  //Strafe right
                        x = atLoc.getX() + sin(currentLook + (PI / -2.0) ) * lookRadius;
                        z = atLoc.getZ() + cos(currentLook + (PI / -2.0) ) * lookRadius;
                        dist = moveBy;
                  }
                  Point sDir(x, y, z);
                  strafeDir.copy(sDir);
                  atLoc.setX(atLoc.getX() + dist * (strafeDir.getX() - atLoc.getX()) );
                  atLoc.setZ(atLoc.getZ() + dist * (strafeDir.getZ() - atLoc.getZ()) );

                  x = atLoc.getX() + sin(currentLook) * lookRadius;
                  y = looking.getY();
                  z = atLoc.getZ() + cos(currentLook) * lookRadius;

                  Point tLook(x, y, z);
                  looking.copy(tLook);
            }

            void altitude(int dir){
                  if(dir == 1){
                        looking.setY(looking.getY() + 1.0);
                        atLoc.setY(atLoc.getY() +1.0);
                  }
                  else{
                        looking.setY(looking.getY() - 1.0);
                        atLoc.setY(atLoc.getY() - 1.0);
                  }
            }      

      
            //Takes in a direction:
            //      1 is forward
            //      -1 is reverse
            //      Moves by moveBy units
            void walk(int dir){
                  float x, y, z;
                  float dist;
                  if(dir == 1){
                        dist = moveBy * 1.0;
                  }
                  else{
                        dist = moveBy * -1.0;
                  }

                  atLoc.setX(atLoc.getX() + dist * (looking.getX() - atLoc.getX()) );
                  atLoc.setZ(atLoc.getZ() + dist * (looking.getZ() - atLoc.getZ()) );

                  x = atLoc.getX() + sin(currentLook) * lookRadius;
                  y = looking.getY();
                  z = atLoc.getZ() + cos(currentLook) * lookRadius;

                  Point tLook(x, y, z);
                  looking.copy(tLook);
            }

            //Accessor for At Location
            //Stored in a Point class
            Point getAt(){ return atLoc; }

            //Accessor for Looking Location
            //Stored in a Point class
            Point getLooking() { return looking; }

            float getLookAngle() {return currentLook; }

            void setLook(Point a)
            {
                  looking.copy(a);
            }
            void setAt(Point a)
            {
                  atLoc.copy(a);
            }
            void upd(Camera a, Point b, bool x1){
                  currentLook = a.currentLook;
                  currentPitch = a.currentPitch;
                  
                  atLoc.copy(a.atLoc);
                  looking.setX(atLoc.getX() + sin(currentLook) * lookRadius);
                  looking.setY(atLoc.getY() + sin(currentPitch) * lookRadius);
                  looking.setZ(atLoc.getZ() + cos(currentLook) * lookRadius);
                  //float y;
            //looking.copy(a.looking);
            /*if(x1) {
              cout << "UPdating Y" << endl;
              atLoc.setY(b.getY());
              y = atLoc.getY() + sin(currentPitch) * lookRadius;
                    looking.setY(y);
              }*/
            //looking.setY(b.getY());
            }
            void setStatic()
            {
             pubAt.copy(atLoc);
             pubLook.copy(looking);
        }
            

};

Point Camera::pubAt = Point(.0, 0., 0.);
Point Camera::pubLook = Point(0., 0., 0.);



PLAYER CLASS




#include <glut.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include "Camera.h"
#include "SoundX.h"
#include "Gun.cpp"


Gun gun(50);

class Player{
      private:

      public:
       
            Player(){}
            
            Camera view;
            void fireOne() {gun.fire(view.getLooking(), view.getAt());}

            void control(unsigned char key, int x, int y){
                  Camera temp(view);
                  Point a;
                  
                  //Point blah = temp.getLooking();
                  switch(key){
                        //Strafe Left
                        case '7':
                              temp.strafe(1);
                              a.copy(temp.getLooking());
                              
                              break;
                        //Strafe Right
                        case '9':
                              temp.strafe(-1);
                              a.copy(temp.getLooking());
                              
                              break;
                        //Look up
                        case '8':
                              temp.pitch(1);
                              a.copy(temp.getLooking());                  
                              break;
                        //Look down
                        case '5':
                              temp.pitch(-1);
                              a.copy(temp.getLooking());
                              break;
                        //Turn left
                        case '4':
                              temp.turn(1);
                              a.copy(temp.getLooking());
                              break;
                        //Turn right
                        case '6':
                              temp.turn(-1);
                              a.copy(temp.getLooking());
                              break;
                        //Move foreward
                        case '0':
                              temp.walk(1);
                              a.copy(temp.getLooking());
                              break;
                        //Move backward
                        case '1':
                              temp.walk(-1);
                              a.copy(temp.getLooking());
                              break;
                        case 'q':
                              temp.altitude(1);
                              break;
                        case 'a':
                              temp.altitude(-1);
                              break;
                        default:
                              break;
               }

                        bool x1 = false;
                temp.atLoc.setY(Collision::checkScene(temp.getAt()));
                        view.upd(temp,a,x1);
                        view.setStatic();
               glutPostRedisplay();
            }

};




IN YOUR DISPLAY FUNCTION:

      a.view.updateCamera();

IN YOUR MAIN FUNCTION:

          glutKeyboardFunc(keyboard);

AND YOUR IDLE FUNC:

void keyboard(unsigned char key, int x, int y)
{
     a.control(key, x, y);
}


Might I add it isn't the most efficient it is a very quick and dirty way to do it... and easy to understand... flip through the code and you'll figure out what you can salvage.  Some friends and myself wrote this during our sophmore year in college.  So... it's cool..!

Any questions ask away.

~Aqua
0
 
srihari1986Author Commented:
Hi Aqua ,

whar is the Gun class u have mentioned above.
0
 
srihari1986Author Commented:
Hi Aqua,

I am getting a lot of error messages when i run ur Camera.h class.Errors are below.


Error E2139 Camera.h 8: Declaration missing ;
Error E2238 Camera.h 9: Multiple declaration for 'Camera::Point'
Error E2344 Camera.h 8: Earlier declaration of 'Camera::Point'
Error E2139 Camera.h 9: Declaration missing ;
Error E2303 Camera.h 10: Type name expected
Error E2238 Camera.h 10: Multiple declaration for 'Camera::Point'
Error E2344 Camera.h 9: Earlier declaration of 'Camera::Point'
Error E2139 Camera.h 10: Declaration missing ;
Error E2303 Camera.h 11: Type name expected
Error E2238 Camera.h 11: Multiple declaration for 'Camera::Point'
Error E2344 Camera.h 10: Earlier declaration of 'Camera::Point'
Error E2139 Camera.h 11: Declaration missing ;
Error E2233 Camera.h 18: Cannot initialize a class member here
Error E2233 Camera.h 19: Cannot initialize a class member here
Error E2233 Camera.h 20: Cannot initialize a class member here
Error E2233 Camera.h 21: Cannot initialize a class member here
Error E2233 Camera.h 22: Cannot initialize a class member here
Error E2233 Camera.h 23: Cannot initialize a class member here
Error E2233 Camera.h 24: Cannot initialize a class member here
Error E2233 Camera.h 25: Cannot initialize a class member here
Error E2293 Camera.h 53: ) expected
Error E2379 Camera.h 37: Statement missing ; in function Camera::Camera()
Error E2451 Camera.h 38: Undefined symbol 'atLoc' in function Camera::Camera()
Error E2451 Camera.h 38: Undefined symbol 'tLoc' in function Camera::Camera()
Error E2379 Camera.h 43: Statement missing ; in function Camera::Camera()
Error E2228 Camera.h 43: Too many error or warning messages in function Camera::
Camera()
*** 26 errors in Compile ***


Regards
Hari
0
 
Andrew BeersCommented:
Compiler use was Bloodshed's Dev C++.

Heh.. the code was to be modified and reused.. not directly copied.  *laughs*  Look at the functions, they are named so they explain what they do.. The gun class was for the 1st person shooter we designed ages ago.  

Inside the camera class there is pitch which controls the Y height of the look at point of the camera.
Walk moves the camera along a parametric equation at a distance of .5 per cycle of the idle function assuming 1 or 0 is held..  1 being reverse and 0 being forward.  Then you have turn which moves you around a unit cirlce, well a circle of radius .5, using the look at point of the OpenGL camera.  Then finally you have strafe that side steps the player left or right by .5 along a + or - 90 degrees from the current look at rotation angle.  Aka... it strafe's the camera.

If you actually want this modified for use with your application I need to know if you are using C++, (that is the only way I really write OpenGL.. Objects make life so much more simple), and I would suggest opening another question.  This question was totally explained and has begun moving on to another question.  If you do ask the other question feel free to look at my contact me page in my profile and notify me that you posted another question and I will gladly update the camera and player classes to be utilized in your program.  (I would need to see your display function, your idle function, and your gl keyboard function.)  Just pointers on what you need to show me so I can further help you in your next question.  I anxiously await the next thread.

~Aqua
0
 
wkokkeCommented:
I'm assuming you don't want to model your bathroom in notepad, or shelve out 1k$+ for a commercial modeller, so I suggest you have a look at blender ( www.blender.org )

HTH,
Willem
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now