Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 May 2011
Offline Last Active Oct 06 2011 06:02 AM

Posts I've Made

In Topic: Pseudo-instancing: help needed with some code parts

06 September 2011 - 12:02 PM

if you are using the fixed function pipeline (I assume you are because otherwise you would have the view matrix because you would have coded the matrix stack)
then you can use the following code

//To retrieve the current Modelview matrix:
GLfloat m[16];
glGetFloatv (GL_MODELVIEW_MATRIX, m);        [left]     [/left]
this comes from http://www.opengl.org/resources/faq/technical/transformations.htm so I would say it was the recommended way to deal with fixed-function (pre 3.1 openGL).

I'm trying to implement the glsl_pseudo_instancing nvidia example in my terrain engine project.

I've already setup the proper initialization routines (loading the shaders etc.) but I'd like to ask some explanations about the render() routine.
Here is the upper part of the original nVidia code:

void renderScene(void)
  assert(gCurrentMesh != NULL);
  int  	i;
  int  	count;
  matrix4f view;
  vec3f	light;
  vec3f	lightWorldSpace(0.0f, 100.0f, 0.0f);
  vec3f	lightPositionView;

  // Set state for rendering the mesh
  // Get the view transform from the mouse interactor
view = gMouseInteractor.get_transform();  // HERE IS WHERE I NEED HELP

  // Compute the light's position in view space
  view.mult_matrix_vec(lightWorldSpace, lightPositionView);
  lightPositionView = vec3f(0.0f, 0.0f, 0.0f);

  	// Download the view matrix
  	glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 4, view(0, 0), view(0, 1), view(0, 2), view(0, 3));
  	glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 5, view(1, 0), view(1, 1), view(1, 2), view(1, 3));
  	glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 6, view(2, 0), view(2, 1), view(2, 2), view(2, 3));
  	glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 7, view(3, 0), view(3, 1), view(3, 2), view(3, 3));
  // Download the light position
  	glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 11, lightPositionView[0], lightPositionView[1], lightPositionView[2], 1.0f); 

From what I understood, I need to retrieve the current view transform and pass the matrix parameters to the vertex program using the glProgramLocalParameter4fARB calls beow.
I have a very simple camera routine that just set pitch,yaw,roll and xyz positions.
How could I calculate the matrix4f view (the view transform matrix) using my camera information?

Thanks for any help!

In Topic: Cube-Cube collision detection

02 September 2011 - 09:38 AM

Hi, I'm sure if the compiler did not optimize code for us we would have to inline the code like that but can anyone confirm or deny that the compiler does this? I'm sure C++ is smart enough to do basic var stacking and loop unrolling where needed... Hopefully anyway :rolleyes:(this is my hopeful face)

Now, a small comment regarding your code... You could put all those checks in one line. Basically, something like:

return (valueInRange(A.x, B.x, B.x + B.width) || 
                        valueInRange(B.x, A.x, A.x + A.width)) &&
(valueInRange(A.y, B.y, B.y + B.height) || 
                        valueInRange(B.y, A.y, A.y + A.height)) &&
(valueInRange(A.z, B.z, B.z + B.depth) || 
   			valueInRange(B.z, A.z, A.z + A.depth));

It will be faster, since there will be lots of early outs, instead of having to create 3 bools, calculate all of them and then check them.
If you could, however, try using Lewis's version, it has less checks than the whole valueInRange thing.
And it could be done even faster by doing:

return (A.bbMin.x <= B.bbMax.x) && 
(A.bbMax.x >= B.bbMin.x) && 
(A.bbMin.y <= B.bbMax.y) && 
(A.bbMax.y >= B.bbMin.y) && 
(A.bbMin.z <= B.bbMax.z) && 
(A.bbMax.z >= B.bbMin.z);

I am also quite sure you need extra brackets and to change some of the && to || ala
return ((A.bbMin.x <= B.bbMax.x) || (A.bbMax.x >= B.bbMin.x)) && ((A.bbMin.y <= B.bbMax.y) || (A.bbMax.y >= B.bbMin.y)) && ((A.bbMin.z <= B.bbMax.z) || (A.bbMax.z >= B.bbMin.z));
voilla this now works as expected when I test it :P(oh the cheek of me)
by the way i'm not poking fun I'm just in a very good mood :D

In Topic: Would like help with GluLookAt and python code.

01 September 2011 - 08:51 AM

Did you guys even read his code? (I know you didn't!)
greentiger: You're doing the same thing no matter what the value of 'view'.
You probably wanted to do different things for different values of view... I guess moving the eye point.

To be fair I did read the code which is why I posted example code that I know works and is a rather nice example of gluLookAt to create a target camera. I quickly read his code i will admit but it absolutely does modify the values of axX and axZ which is what is passed to the camera... (sigh)

Edit: Also I have noticed that you may need to fix the indentation because gamedev ever so cleverly b@||@#%d it with their code formatter

In Topic: Would like help with GluLookAt and python code.

01 September 2011 - 06:49 AM

what exactly are you attempting to achieve with the gluLookAt?

here is a test 3rdPersonCamera that uses gluLookAt
#!/usr/bin/env python

import sys
import math
	from OpenGL.GLUT import *
	from OpenGL.GL import *
	from OpenGL.GLU import *

	print '''ERROR: PyOpenGL not installed properly.'''

class thirdPersonApp:
	def __init__(self):
    	#player coordinates
    	self.playerX = 27.0
    	self.playerY = 0.5
    	self.playerZ = 27.0

    	#camera coordinates
    	self.camX = 44.0
    	self.camY = 25.0
    	self.camZ = 44.0


    	self.playerRot = 225.0
    	self.cameraRot = 20.0

    	self.camDist = 50.0
    	#self.camHeight = 25.0

    	self.moveVel = 1.0
    	self.rotVel = 6.0


	def setupGL(self):
    	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
    	glutInitWindowSize (400, 400);
    	glutInitWindowPosition(100, 100)
    	glutCreateWindow("Third Person Test Application")



	def onIdle(self):
	def onDraw(self):
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)# Clear The Screen And The Depth Buffer
    	glLoadIdentity()# Reset The View
    	self.camX = self.playerX+self.camDist*math.sin(self.cameraRot*math.pi/180.0)
    	#self.CamY = self.playerY-self.camDist
    	self.CamZ = self.playerZ+self.camDist*math.cos(self.cameraRot*math.pi/180.0)



    	i = 0
    	while i < 10:
        	glVertex(-50,0,-50+i*10); glVertex(50,0,-50+i*10)
        	glVertex(-50+i*10,0,-50); glVertex(-50+i*10,0,50)
        	i = i+1

    	self.playerY = 0.5


    	glColor(1,1,1); glVertex( 0,0, 7)
    	glColor(1,0,0); glVertex(-5,0,-5)
    	glColor(1,0,0); glVertex(+5,0,-5)

    	glVertex(0,1,0); glVertex(5,1, 0) # X
    	glVertex(0,1,0); glVertex(0,5, 0) # Y
    	glVertex(0,1,0); glVertex(0,1, 5) # Z
	def glInit(self):
    	glClearColor(0.0, 0.0, 0.0, 0.0) # Black Background
    	glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
    	glClearDepth(1.0) # Depth Buffer Setup
    	glEnable(GL_DEPTH_TEST) # Enable Depth Buffer
    	glDepthFunc(GL_LESS) # The Type Of Depth Test To Do

    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) # Realy Nice perspective calculations

	def onResize(self,w,h):
    	gluPerspective(45.0, float(w)/float(h), 0.5, 1024.0)

	def onKeyPress(self,*args):
    	if args[0] == chr(27):#ESC Key
    	elif args[0] == "w":
        	self.playerX = self.playerX+self.moveVel*math.sin(self.playerRot*math.pi/180.0)
        	self.playerZ = self.playerZ+self.moveVel*math.cos(self.playerRot*math.pi/180.0)
    	elif args[0] == "s":
        	self.playerX = self.playerX-self.moveVel*math.sin(self.playerRot*math.pi/180.0)
        	self.playerZ = self.playerZ-self.moveVel*math.cos(self.playerRot*math.pi/180.0)
    	elif args[0] == "a":
        	self.playerRot = self.playerRot+self.rotVel
    	elif args[0] == "d":
        	self.playerRot = self.playerRot-self.rotVel
    	elif args[0] == "q":
        	self.camY = self.camY - 1.0
    	elif args[0] == "e":
        	self.camY = self.camY + 1.0

    	if self.camY <= 10.0:
        	self.camY = 10.0
    	if self.camY >= 180.0:
        	self.camY = 180.0
	def eXit(self):
    	#destroy glForm

if __name__ == "__main__":
it's a bit messy because it is so old and based off of a delphi application, but it should help you to better understand gluLookAt :cool:

In Topic: OpenGL 1,2,3,4 general question

01 September 2011 - 03:30 AM

OMG you like DX better than GL... Many people in the world of DX (including myself) complained endlessly over features simply removed from the spec without deprecating, consulting or providing support from 7 upwards. OpenGL does provide full easily readable specification, that deprecates and has a wide base of developers, who develop for multiple platforms. Also OpenGL is extremely OOP! Just consider that encapsulation, abstraction, modularity, polymorphism, messaging and inheritance (wikipedias definition of OOP is completely met by OpenGL! Just thought I should point that out

You're really risking a huge flame-war here by calling either "cleaner", "better" or anything similar :-)

Truth is that extensions get into OpenGL quicker (in fact you have to wait for Microsoft until they make up their minds to use anything the new cards support!!!).

Khronos don't change the whole API as much as Microsoft every time, fortunately. New features (functions) become available, some are deprecated, some finally removed. The whole concept persists. Same goes for OpenCL.

Start learning directly OpenGL 4. No mather what, do NOT look at OpenGL 1.x, ever :-) That, unfortunately, disqualifies most of the famous NeHe tutorials, for example, hehe. Start with desktops, learn basics and do not touch OpenGL ES (mobile) before that much, if you plan to.

:D nehe was the first i had a look at xD looked quite old to me too^^
what tutorial source would you suggest =) ? or are there any recommended books for opengl4 ?
i'd like to have an overview and basic techniques used in opengl beginning with
- viewports over
- view matrices for a camera,
- how to use a fbo,
- different techniques of drawing (read about displaylists, vertex arrays and vertexbuffers, different opinions in every spot i've read)
- usage and need of shaders in opengl4