Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lewis_1986

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

#4856309 Would like help with GluLookAt and python code.

Posted by Lewis_1986 on 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


#4856269 Would like help with GluLookAt and python code.

Posted by Lewis_1986 on 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
try:
	from OpenGL.GLUT import *
	from OpenGL.GL import *
	from OpenGL.GLU import *

except:
	print '''ERROR: PyOpenGL not installed properly.'''
	sys.exit()

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

    	self.setupGL()

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

    	self.glInit()

    	glutIdleFunc(self.onIdle)
    	glutDisplayFunc(self.onDraw)
    	glutReshapeFunc(self.onResize)
    	glutKeyboardFunc(self.onKeyPress)
    	glutMainLoop()

	def onIdle(self):
    	self.onDraw()
    	
	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)

    	gluLookAt(self.camX,self.camY,self.camZ,self.playerX,self.playerY,self.playerZ,0,1,0)

    	glColor(0.5,0.5,0.5)
    	glBegin(GL_LINES)

    	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
    	glEnd()

    	#z-fight
    	self.playerY = 0.5

    	glTranslatef(self.playerX,self.playerY,self.playerZ)
    	glRotatef(self.playerRot,0,1,0)

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

    	glColor(1,1,1)
    	glBegin(GL_LINES)
    	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
    	glEnd()
    	glutSwapBuffers()
	
	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):
    	glViewport(0,0,w,h)
    	glMatrixMode(GL_PROJECTION)
    	glLoadIdentity()
    	gluPerspective(45.0, float(w)/float(h), 0.5, 1024.0)
    	glMatrixMode(GL_MODELVIEW)

	def onKeyPress(self,*args):
    	if args[0] == chr(27):#ESC Key
        	self.eXit()
    	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
    	glutPostRedisplay()
	
	def eXit(self):
    	#destroy glForm
    	sys.exit()

if __name__ == "__main__":
	thirdPersonApp()
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:


#4856210 OpenGL 1,2,3,4 general question

Posted by Lewis_1986 on 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




#4856163 Confusion about Law of Demeter

Posted by Lewis_1986 on 01 September 2011 - 12:31 AM

http://en.wikipedia..../Law_of_Demeter, I have never heard of it before (although I have heard about encapsulation and abstraction) and I did know that it is naughty (not wrong) to assume a class has a class that has a function, but basically I think laws like this stifle common sense, it may not be very OOP to occasionally ignore this rule, but I can imagine significant code bloat and mind-boggling if it were universally applied to every single project or class. Having said this the engine->torque example was absolutely exemplorary.

As a side note, in environments such as ECMA, could a person not chain evaluations to nullify the negative effects of such assumptions so:

eval("car57").eval("getEngine()").eval("getTorque()")

As I understand it ECMA script provisions for all objects having internal evaluation and returning NULL (which is an object in ECMA I think) so does this destroy the need for demeters law

Update: Just checked and I was wrong about ECMA, it cannot solve this problem but a solution would be some sort of managed code


#4856149 Why am I only told what not to do

Posted by Lewis_1986 on 31 August 2011 - 11:54 PM

So basically the article suggests using a bool sometype::init() instead of the constructor object for allocating resources as init can fail gracefully and constructors will just create massive mem leaks. I actually agree 100% with the article on this issue and would like to suggest http://www.scs.stanford.edu/~dm/home/papers/c++-new.html as a good read on the subject of constructors


#4855969 Image with text fields? (is this easy programming)?

Posted by Lewis_1986 on 31 August 2011 - 11:07 AM

right personally I don't care what anyone's opinion is because I work on many different hardware platforms and get paid for what I do, if pixels are set then it is an image FULL STOP! You can abstract an issue as much as you like, and encapsulate it in various classes and give it fancy names but as long as you set pixels, your drawing an image. Drawing a font is an image action where the images width and height are relative to the resolution of the font, this is called raster text, it works with windowing toolkits, hardware accelerated libraries such as opengl and the result can be translated to devices like lcd's and braille output devices.

Secondly, to the OP, I apologise for all this noise and that is the only thing I can describe it as but there is not a name for the system, although the process of combining images is called compositing. Are you looking for a framework that allows you to simplify this process or are you just asking how it would work because it can be simple or complex depending upon what you want to get out of it. drawing ascii characters for example is much easier than drawing wide characters 255 values vs 65535 values assuming in both cases loose one possible value to signify invalid data.

You can PM me if you like or try to be more specific, no matter how trivial all details are needed for giving a fuller answer

Edit:
Just seen your screenie, are you looking to implement this for the web or in a traditional application, because if it is for the web use input text boxes like below (note please do not copy and paste because this is not optimal code)
<div style=" background: url('./bg-img.jpg'); width: 100%; height: 100%; ">
<div style="position: absolute; left: 50%; top: 50%; margin-top: -100px; margin-left: -150px; width:200px; height: 200px;">
some visible uneditable-text<br/>
<input type="text" name="whatever_name" id="whatever_name" size="20" />
</div>
<div style="position: absolute; left: 50%; top: 50%; margin-top:  -100px; margin-left: 50px; width: 200px; height: 200px;">
some visible uneditable-text2<br/>
<input type="text" name="whatever_name" id="whatever_name" size="20" />
</div>
</div>

If it is application code then it will be more complicated because you would need to program the classes such as input, also if you were drawing with opengl you could use glScissor command to only re-draw the textbox

Edit2:
by the way to only show the box of text is called clipping and using glScissor is one way of doing this, another way is to draw the text from right to left until the pixel position is less than the textboxes x component, but this is only for an application


#4855818 Facts about John Carmack

Posted by Lewis_1986 on 31 August 2011 - 04:33 AM

John Carmack is GOD and he regularly influences history to display his greatness. He created the agents in the film "The Matrix" because NEO was going to overload his matrix stack implementation, and at the end of the film you see the real John Carmack who pilots the John Carmack, we see's automaton body


#4855815 Image with text fields? (is this easy programming)?

Posted by Lewis_1986 on 31 August 2011 - 04:20 AM

Are you talking about a web page? A custom program? A magical parchment?

"Images" generally implies static visual content. Overlaying a text field on top of an image is pretty easy (in most design toolkits). Is that what you mean?



What are you trying to make this game in? web-based?


@ApochPiQ, seriously the old addage "if you cannot say anything helpful, be silent!" springs to mind because mocking someone and then telling them what they want to do is trivial helps no-one


To me it comes across as "Trying to understand the question more fully", rather than mocking. Good questions get better answers, ApochPiQ seems to be trying to get a better question.


Seriously I hope I'm wrong but I cannot see why someone would take that mode of reply as a probe for more information? If it was a genuine probe I do apologise, but as an educator I see alot of people quitting very early on, simply because they do not understand a concept and when they ask a question the response stifles their interest.

Also I do not see that it matters how the system of compositing would be implemented. Unless there is a system out there that uses elliptical co-ordinates, the basis is the same... html, xhtml, flash, c++ (winforms, sdl etc) all use rectangular co-ordinate systems for describing objects positions and bounds.

I do hope that the original poster has a greater understanding of a way to draw text and images together and that if they do not, that they continue to seek answers and probe further.


#4855801 Image with text fields? (is this easy programming)?

Posted by Lewis_1986 on 31 August 2011 - 03:19 AM

well the simplest way is to treat the text as an image, create a larger image representing the entire area that the text and images exist on and draw each object. Of course this all sounds very simple to an experienced programmer but I recognize some people may have trouble so i'll try to break it down a bit more for you

1) a glyph is the description of a character so it would have an x and y origin and an x and y extent (xorigin+width and yorigin+height)
2) the glyph would also contain a series of points with their position within the glyph (again x and y) and intensity, because if all points had the same intensity it could only represent a solid block or empty block, which would result in aliasing (blocky text)
3) once you have these points and have created a texture that is the size of the glyph, you can set each pixel to the value of the color you wish it to be with alpha multiplied by the intensity from the point (this will create anti-aliased text that is transparent and most computers now support rgba colours)
4) work out how large each entire piece of text is and draw each glyph in the text
5) draw the text and images onto the larger image

N.B. every object will have a display rectangle, so text, images, characters (which make up text) and the drawing area can all be described and should use a rectangle to descirbe their position and extent

@ApochPiQ, seriously the old addage "if you cannot say anything helpful, be silent!" springs to mind because mocking someone and then telling them what they want to do is trivial helps no-one


#4855779 OpenGL questions

Posted by Lewis_1986 on 31 August 2011 - 12:52 AM

just as a note Ectara is 1000% right and for those finding it hard to get into openGL without fixed function read http://developer.android.com/guide/topics/graphics/opengl.html, it is talking about android but their openGL es2.0 example was exactly what I was looking for when I created this post!


PARTNERS