Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


stankar

Member Since 26 Sep 2012
Offline Last Active Nov 21 2012 07:13 AM

Topics I've Started

Need physx simple vehicle sample code

14 November 2012 - 07:00 AM

Hi there, I read PhysX Guide for Vehicles, but there is only "theory + data" not "step by step tut" and with this I can't wrote simple car on plane in physx (I'm noob).
If anyone has some samples, please post it here, thanks a lot.

[PhysX] how to use it for obj model ?

15 October 2012 - 12:27 PM

Hi there, I'm new in OGL and especially in PhysX and I need to know, how I can apply PhysX on models. I'm using PhysX 3.1.2 and for PhysX 3 and above there aren't good simple tutorials for beginners (except official PhysX guide).
For now I know how to create scene and actors and some shape, but I have some models (car and map) which I want to use in PhysX.

So questions are:
How I can apply map as plane (height map as ground) in PhysX ?
How I can apply car as object on map/ground in PhysX ?
Thanks for any help :)

Now I have car and map in OpenGL and basic create physx scene:
Posted Image

Resize function for 3D and 2D

12 October 2012 - 03:08 PM

Hi, I posted here my code for switching fullscreen/window, but main problem I have is Resize function, which I haven't, because I'm using 3D and 2D objects and I don't know how can I resize both (3d is OK, but both is complicated for me).

Dispaly function:
// Display Function
void Display(void) {
glClearColor(0.3f, 0.5f, 0.9f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set 3D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (int)width, (int)height);
gluPerspective(30, width/height, 0.1, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set camera
gluLookAt(cam1,27,130, 5,11,0, 0,1,0);
glutPostRedisplay();
// Light and Z-buffer
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
// Draw Map and Car
glPushMatrix();
// load map obj
  glPushMatrix();
   glTranslatef(x,y,z);
   glRotatef(-180, 0.0, 1.0, 0.0);
   glmDraw(map, GLM_SMOOTH | GLM_MATERIAL);
  glPopMatrix();
  // load car obj
  glPushMatrix();
   glTranslatef(x+carx, y+cary, z+carz);
   glRotatef(-180, 0.0, 1.0, 0.0);
   glmDraw(car, GLM_SMOOTH | GLM_MATERIAL);
  glPopMatrix();
glPopMatrix();
glPopAttrib();
glFlush();
// Set 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width,height,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// Draw text
glPushMatrix();
glColor3f(1, 1, 1);
  renderBitmapString(10,20,(void *)font2,"Press 'H' for show/hide help");
glEnd();
glPopMatrix();
// Show help menu
if(h1==true) {
  glTranslatef((float)((width-500)/2),(float)(500+((height-500)/2)),0);
  glPushMatrix();
  glColor3f(1, 1, 1);
  glBegin(GL_QUADS);
   glVertex3f(0.0f, -500.0f, 0.0f); // The bottom left corner
   glVertex3f(0.0f, 0.0f, 0.0f);  // The top left corner
   glVertex3f(500.0f, 0.0f, 0.0f);  // The top right corner
   glVertex3f(500.0f, -500.0f, 0.0f); // The bottom right corner
  glEnd();
  glPopMatrix();
  glPushMatrix();
  glColor3f(0, 0, 0);
   renderBitmapString(130,-440,(void *)font1,"P H Y S X   C A R   S I M U L A T O R");
   renderBitmapString(190,-410,(void *)font2,"HELP MENU:");
   renderBitmapString(60,-350,(void *)font2,"'K'   = change to left-side camera");
   renderBitmapString(60,-320,(void *)font2,"'L'   = change to right-side camera");
   renderBitmapString(60,-290,(void *)font2,"'ESC' = exit program");
   renderBitmapString(60,-50,(void *)font1,"Author: Son Nguyen (NGU0013)												  Version: 1.0 , 2012");
  glEnd();
  glPopMatrix();
}

I want Resize function that Set 2D and Set 3D block will be in it. Thanks

Switching from Fullscreen to Window

12 October 2012 - 01:43 PM

Hi guys,
I'm new in OGL, I found how to Enter and Leave Fullscreen in two different solutions:
1. glutFullScreen() and glutLeaveFullScreen() (doesn't work ... maybe old dll)
2. glutEnterGameMode and glutLeaveGameMode
Now I have maybe badly constructed code, but works for me without fullscreen, if I want Fullscreen, I must change variables "width" and "height" and then run glutFullSreen method.
I want fullscreen on key F when I draw ogl window with menu (simply switch fullscreen/window on key "F").

Now I have:
// MAIN.cpp - MAIN PROGRAM
#include "main.h"
// Variables
float cam1=5;	    // Camera position
float x=4250,y=-30,z=-7390;	 // Map position
float carx=-4220,cary=0,carz=7210;   // Car position
float width=800.0, height=600.0;   // Window size
bool h1=false,k1=false,l1=false,f1=false; // F key for Help menu
// Font settings
const int font1=(int)GLUT_BITMAP_HELVETICA_12;
const int font2=(int)GLUT_BITMAP_HELVETICA_18;
// Light settings
GLfloat lightAmb[3] = {0.1f, 0.1f, 0.1f};
GLfloat lightDiff[3] = {1.0f, 1.0f, 1.0f};
GLfloat lightPos[4]={0.0f, 0.0f, 0.0f, 1.0f};
// Models variables
GLMmodel* car = NULL;
GLMmodel* map = NULL;
// Keyboard Function
void Keyboard(unsigned char key, int xx, int yy) {
glutPostRedisplay();
switch(key) {
case 'h':    // Show/hide help menu
  if(h1==false) h1=true;
  else h1=false;
  break;
case 'k':    // Left-side camera
  k1=true;
  cam1=-103;
  x=4400;
  break;
case 'l':    // Right-side camera
  l1=true;
  cam1=113;
  x=4100;
  break;
case 'f' :    // Fullscreen ON/OFF
  if(f1==false) {
   f1=true;
  }
  else {
   f1=false;
  }
  break;
case 27  :    // Stop program
  exit(0);
}
}
// Keyboard UP Function
void KeyboardUp(unsigned char key, int xx, int yy) {
switch(key) {
case 'k':  // K key up
  k1=false;
  cam1=5;
  x=4250;
  break;
case 'l':  // L key up
  l1=false;
  cam1=5;
  x=4250;
  break;
}
}
// Keyboard HOLD DOWN Function
void myIdleFunc(void) {
glutPostRedisplay();
if(k1) { // K key pressed
  cam1=-103;
  x=4400;
}
if(l1) { // L key pressed
  cam1=113;
  x=4100;
}
}
// Initializing models
void initModels(void) {
// Set car model
car = glmReadOBJ("Models/audi-tt.obj");
if (!car) exit(0);
glmFacetNormals(car);
glmVertexNormals(car, 90.0);
// Set map model
map = glmReadOBJ("Models/map.obj");
if (!map) exit(0);
glmFacetNormals(map);
glmVertexNormals(map, 90.0);
}
// Text Function
void renderBitmapString(float x, float y, void *font,string str) {
const char *c;
glRasterPos2f(x, y); // Text position
for (c=str.c_str(); *c != '\0'; c++) glutBitmapCharacter(font, *c);
}
// Display Function
void Display(void) {
glClearColor(0.3f, 0.5f, 0.9f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set 3D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, (int)width, (int)height);
gluPerspective(30, width/height, 0.1, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set camera
gluLookAt(cam1,27,130, 5,11,0, 0,1,0);
glutPostRedisplay();
// Light and Z-buffer
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff);
// Draw Map and Car
glPushMatrix();
// load map obj
  glPushMatrix();
   glTranslatef(x,y,z);
   glRotatef(-180, 0.0, 1.0, 0.0);
   glmDraw(map, GLM_SMOOTH | GLM_MATERIAL);
  glPopMatrix();
  // load car obj
  glPushMatrix();
   glTranslatef(x+carx, y+cary, z+carz);
   glRotatef(-180, 0.0, 1.0, 0.0);
   glmDraw(car, GLM_SMOOTH | GLM_MATERIAL);
  glPopMatrix();
glPopMatrix();
glPopAttrib();
glFlush();
// Set 2D
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width,height,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
// Draw text
glPushMatrix();
glColor3f(1, 1, 1);
  renderBitmapString(10,20,(void *)font2,"Press 'H' for show/hide help");
glEnd();
glPopMatrix();
// Show help menu
if(h1==true) {
  glTranslatef((float)((width-500)/2),(float)(500+((height-500)/2)),0);
  glPushMatrix();
  glColor3f(1, 1, 1);
  glBegin(GL_QUADS);
   glVertex3f(0.0f, -500.0f, 0.0f); // The bottom left corner 
   glVertex3f(0.0f, 0.0f, 0.0f);  // The top left corner 
   glVertex3f(500.0f, 0.0f, 0.0f);  // The top right corner 
   glVertex3f(500.0f, -500.0f, 0.0f); // The bottom right corner 
  glEnd();
  glPopMatrix();
  glPushMatrix();
  glColor3f(0, 0, 0);
   renderBitmapString(130,-440,(void *)font1,"P H Y S X   C A R   S I M U L A T O R");
   renderBitmapString(190,-410,(void *)font2,"HELP MENU:");
   renderBitmapString(60,-350,(void *)font2,"'K'   = change to left-side camera");
   renderBitmapString(60,-320,(void *)font2,"'L'   = change to right-side camera");
   renderBitmapString(60,-290,(void *)font2,"'ESC' = exit program");
   renderBitmapString(60,-50,(void *)font1,"Author: Son Nguyen (NGU0013)						  Version: 1.0 , 2012");
  glEnd();
  glPopMatrix();
}
glutSwapBuffers();
}
// Main Function
int main(int argc, char **argv) {
cout << "Loading models ... ";
initModels();
cout << "DONE" << endl;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize((int)width, (int)height);
glutInitWindowPosition(0, 0);
glutCreateWindow("PhysX Car Simulator");
glutFullScreen();
initPhysX();
glutDisplayFunc(Display);
glutKeyboardFunc(Keyboard);
glutKeyboardUpFunc(KeyboardUp);
glutIdleFunc(myIdleFunc);
glutMainLoop();
deinitPhysX();
return 0;
}

Thanks for help.

render obj file with bad shapes

26 September 2012 - 07:32 AM

Hi, I'm trying to make easy obj loader (loading car and map - two cars so far) and code looks good, but if I run it, cars looks bad:
Posted Image

I don't know what's wrong. Can be some mistake in the code ? Please help, thanks

[source lang="cpp"]// MAIN.cpp - MAIN PROGRAM#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sstream>#include <iostream>#include "Lib\GL\headers\glut.h"#include "Lib\GL\glm\glm.h"using namespace std;// Variablesfloat x=-26, y=-26, z=-500, deg_z=0, deg_y=0;int displayList=0;static int w=800,h=600;GLfloat lightPos[4] = {50.0, 30.0 ,0.0, 0.0};GLfloat lightAmb[3] = {0.1, 0.1, 0.1};GLfloat lightDiff[3] = {1.0, 1.0, 1.0};GLMmodel* car = NULL;GLMmodel* car2 = NULL;void initmodel(void) { car = glmReadOBJ("Models/audi-tt.obj"); if (!car) exit(0); glmFacetNormals(car); glmVertexNormals(car, 90.0); car2 = glmReadOBJ("Models/audi-tt.obj"); if (!car2) exit(0); glmFacetNormals(car2); glmVertexNormals(car2, 90.0);}void setCamera() { if(h == 0) h = 1; float ratio = 1.0 * w / h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); gluPerspective(30, ratio, 0.1, 10000); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}void display(void) { setCamera(); glClearColor(0.3f, 0.5f, 0.9f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, lightPos); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff); //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPushMatrix(); // load first obj glPushMatrix(); glTranslatef(x,y,z); glRotatef(deg_z, 1.0, 0.0, 0.0); glRotatef(deg_y, 0.0, 1.0, 0.0); glmDraw(car, GLM_SMOOTH | GLM_MATERIAL); glPopMatrix(); // load second obj glPushMatrix(); glTranslatef(x+200,y,z); glRotatef(deg_z, 1.0, 0.0, 0.0); glRotatef(deg_y, 0.0, 1.0, 0.0); glmDraw(car2, GLM_SMOOTH | GLM_MATERIAL); glPopMatrix(); glPopMatrix(); glPopAttrib(); glFlush(); glutSwapBuffers();}void Keyboard(unsigned char key, int xx, int yy) { glutPostRedisplay(); switch(key) { case 'a' : x-=2; break; // Move left for X pos case 'd' : x+=2; break; // Move right for X pos case 's' : z+=2; break; // Move down for Z pos case 'w' : z-=2; break; // Move up for Z pos case '.' : y-=2; break; // Move up for Y pos case ',' : y+=2; break; // Move down for Y pos case 'k' : deg_z-=2.0; break; // Rotate up case 'i' : deg_z+=2.0; break; // Rotate down case 'j' : deg_y+=2.0; break; // Rotate left case 'l' : deg_y-=2.0; break; // Rotate right case 27 : exit(0); // Stop program }}void Resize(int w, int h) { if(h == 0) h = 1; float ratio = 1.0 * w / h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); gluPerspective(30, ratio, 0.1, 1000); glMatrixMode(GL_MODELVIEW);}int main(int argc, char **argv) { initmodel(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(800,600); glutCreateWindow(argv[0]); glutKeyboardFunc(Keyboard); glutDisplayFunc(display); glutMainLoop(); return 0;}[/source]

PARTNERS