How does setCoordinateSystem work?

hi,
I want to know the affect of gsg.setCoordinate.It seemd that the model loaded from egg file would disappear only if I set camLens.setCoordinate().And camera.lookAt also no effect.What is the use of it?
BestRegards
p3dFan

would you post related codes of yours, to let us know more about the problem?

are you talking about setCoodinateSystem in gsg or in camera?

Hi,
My code as follow:

#! /usr/bin/env python
#coding=utf-8
from direct.directbase import DirectStart
from panda3d.core import Filename,InternalName
from panda3d.core import GeomVertexArrayFormat, GeomVertexFormat
from panda3d.core import Geom, GeomNode, GeomTrifans, GeomTristrips, GeomTriangles
from panda3d.core import GeomVertexReader, GeomVertexWriter
from panda3d.core import GeomVertexRewriter, GeomVertexData
from panda3d.core import Vec2,Vec3, Vec4, Point3,NodePath

import random, sys, os, math

def MakeCurveSurface():
	yxjiao = 60
	
def myNormalize(myVec):
	myVec.normalize()
	return myVec
'''
def MakeSequence(vseq[]):
	format=GeomVertexFormat.getV3n3cpt2()
	vdata=GeomVertexData('square', format, Geom.UHDynamic)
	
	vertex=GeomVertexWriter(vdata, 'vertex')
	color=GeomVertexWriter(vdata, 'color')
		
	for v in vseq
		${0}
''' 
def makeSquare(x1,y1,z1, x2,y2,z2):
	format=GeomVertexFormat.getV3n3cpt2()
	vdata=GeomVertexData('square', format, Geom.UHDynamic)

	vertex=GeomVertexWriter(vdata, 'vertex')
	#normal=GeomVertexWriter(vdata, 'normal')
	#color=GeomVertexWriter(vdata, 'color')
	texcoord=GeomVertexWriter(vdata, 'texcoord')
	
	#make sure we draw the sqaure in the right plane
	if x1!=x2:
		vertex.addData3f(x1, y1, z1)
		vertex.addData3f(x2, y1, z1)
		vertex.addData3f(x2, y2, z2)
		vertex.addData3f(x1, y2, z2)

		#print vertex.getVertexData()
		'''
		normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
		normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y2-1, 2*z2-1)))
		'''
	else:
		vertex.addData3f(x1, y1, z1)
		vertex.addData3f(x2, y2, z1)
		vertex.addData3f(x2, y2, z2)
		vertex.addData3f(x1, y1, z2)
		'''
		normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1)))
		normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z1-1)))
		normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1)))
		normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z2-1)))
		'''
	'''
	#adding different colors to the vertex for visibility
	color.addData4f(1.0,0.0,0.0,1.0)
	color.addData4f(0.0,1.0,0.0,1.0)
	color.addData4f(0.0,0.0,1.0,1.0)
	color.addData4f(1.0,0.0,1.0,1.0)
	
	'''
	texcoord.addData2f(0.0, 1.0)
	texcoord.addData2f(0.0, 0.0)
	texcoord.addData2f(1.0, 0.0)
	texcoord.addData2f(1.0, 1.0)
	
	#quads arent directly supported by the Geom interface
	#you might be interested in the CardMaker class if you are
	#interested in rectangle though
	tri1=GeomTriangles(Geom.UHDynamic)
	tri2=GeomTriangles(Geom.UHDynamic)

	tri1.addVertex(0)
	tri1.addVertex(1)
	tri1.addVertex(3)

	tri2.addConsecutiveVertices(1,3)

	tri1.closePrimitive()
	tri2.closePrimitive()

	square=Geom(vdata)
	square.addPrimitive(tri1)
	square.addPrimitive(tri2)
		
	return square

def onUpdate(task):
	detX = 0
	detY = 0
	if cmdInfo["cam-left"] == 1:
		detX = 0.1
	elif cmdInfo["cam-right"] == 1:
		detX = -0.1
		   
	if cmdInfo["cam-up"] == 1:
		detY = -0.1
	elif cmdInfo["cam-down"] == 1:
		detY = 0.1
		   
	npRot = camera
		   
	npRot.setH(npRot,detX)
	npRot.setP(npRot,detY)
	return task.cont

def setKey(key, value):
	   cmdInfo[key] = value

MAX_Cells = 256
class CSceneRoom():
	def makeQuad(self, vertexData, texcoordData, start, col = Vec4(1,1,1,1)):
		format = GeomVertexFormat.getV3n3cpt2()
		vdata = GeomVertexData('room', format, Geom.UHDynamic)
			
		vertex = GeomVertexWriter(vdata, 'vertex')
		texcoord = GeomVertexWriter(vdata, 'texcoord')
		
		vertex.addData3f(vertexData[start])
		texcoord.addData2f(texcoordData[start])
		
		vertex.addData3f(vertexData[start+1])
		texcoord.addData2f(texcoordData[start+1])
		
		vertex.addData3f(vertexData[start+2])
		texcoord.addData2f(texcoordData[start+2])
		
		vertex.addData3f(vertexData[start+3])
		texcoord.addData2f(texcoordData[start+3])
		
		color=GeomVertexWriter(vdata, 'color')
		color.addData4f(col)
		color.addData4f(col)
		color.addData4f(col)
		color.addData4f(col)
	
		quad1=GeomTristrips(Geom.UHDynamic)
		quad1.addVertex(0)
		quad1.addVertex(1)
		quad1.addVertex(3)
		quad1.addVertex(2)
		
		
		quad1.closePrimitive()
		
		gQuad = Geom(vdata)
		gQuad.addPrimitive(quad1)

		return gQuad

	def makeRoom(self):
		y = 40
		
		dataV = [Vec3(MAX_Cells, 0, MAX_Cells), Vec3(MAX_Cells, 0, 0),  
		Vec3(0, 0, 0), Vec3(0, 0, MAX_Cells),#floor
		Vec3(MAX_Cells, y , MAX_Cells), Vec3(MAX_Cells, y, 0), 
		Vec3(0, y, 0), Vec3(0, y, MAX_Cells),#ceiling
		Vec3(MAX_Cells, y, 0), Vec3(MAX_Cells, 0, 0),
		Vec3(0, 0, 0), Vec3(0, y, 0),#wallfront
		Vec3(MAX_Cells, y, MAX_Cells), Vec3(MAX_Cells, 0, MAX_Cells),
		Vec3(0, 0, MAX_Cells), Vec3(0, y, MAX_Cells),#wallback
		Vec3(0, y, MAX_Cells), Vec3(0, 0, MAX_Cells),
		Vec3(0, 0, 0), Vec3(0, y, 0),#wallleft
		Vec3(MAX_Cells, y, MAX_Cells), Vec3(MAX_Cells, 0, MAX_Cells),
		Vec3(MAX_Cells, 0, 0), Vec3(MAX_Cells, y, 0)]#wallright

		dataT = [Vec2(5, 5), Vec2(5, 0),
				 Vec2(0, 0), Vec2(0, 5),#floor
				 Vec2(5, 5), Vec2(5, 0),
				 Vec2(0, 0), Vec2(0, 5),#ceiling
				 Vec2(4, 1), Vec2(4, 0),
				 Vec2(0, 0), Vec2(0, 1),#wallfront
				 Vec2(4, 1), Vec2(4, 0),
				 Vec2(0, 0), Vec2(0, 1),#wallback
				 Vec2(4, 1), Vec2(4, 0),
				 Vec2(0, 0), Vec2(0, 1),#wallleft
				 Vec2(4, 1), Vec2(4, 0),
				 Vec2(0, 0), Vec2(0, 1)]#wallright
			
		npRoom = NodePath("Room")
		
		gFloor = self.makeQuad(dataV, dataT, 0)
		gCeiling = self.makeQuad(dataV, dataT, 4)
		gWallFront = self.makeQuad(dataV, dataT, 8,Vec4(1,0,0,0))
		gWallBack = self.makeQuad(dataV, dataT, 12,Vec4(0,1,0,0))
		gWallLeft = self.makeQuad(dataV, dataT, 16,Vec4(0,0,1,0))
		gWallRight = self.makeQuad(dataV, dataT, 20)
		
		gnFloor = GeomNode("floor")
		gnFloor.addGeom(gFloor)
		npFloor = npRoom.attachNewNode(gnFloor)
		tex = loader.loadTexture("texture/floor.bmp")
		npFloor.setTexture(tex)
		
		gnCeiling = GeomNode("ceiling")
		gnCeiling.addGeom(gCeiling)
		npCeiling = npRoom.attachNewNode(gnCeiling)
		tex = loader.loadTexture("texture/ceiling.bmp")
		npCeiling.setTexture(tex)
		
		
		gnWall = GeomNode("wall")
		gnWall.addGeom(gWallFront)
		gnWall.addGeom(gWallBack)
		gnWall.addGeom(gWallLeft)
		gnWall.addGeom(gWallRight)
		npWall = npRoom.attachNewNode(gnWall)
		tex = loader.loadTexture("texture/wall.bmp")
		npWall.setTexture(tex)
		#npWall.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd))
		
		npRoom.reparentTo(render)
		npRoom.setTwoSided(True)
		return npRoom
	def __init__(self):
		self.npRoom = self.makeRoom()
		#self.makeCrosshair()
		
   
	def drawScene(self):
		pass


base.disableMouse()
y = 0
square0=makeSquare(-1,y,-1, 1,y, 1)

snode=GeomNode('square')

snode.addGeom(square0)
nodepath = render.attachNewNode(snode)
nodepath.setTwoSided(True)

filename = "texture/crossLine.bmp"
tex = loader.loadTexture(filename)
nodepath.setTexture(tex)


cmdInfo = {"getCamHpr":0,"cam-up":0,"cam-down":0,
					   "cam-left":0,"cam-right":0}
camera.setPos ( 0, -10, 0)          
#camera.setHpr ( 0, 10, 0 )         
		
#base.setBackgroundColor(0, 0, 0)    

#base.toggleWireframe()

base.accept("arrow_up", setKey, ["cam-up", 1])
base.accept("arrow_up-up", setKey, ["cam-up", 0])
	  
base.accept("arrow_down", setKey, ["cam-down", 1])
base.accept("arrow_down-up", setKey, ["cam-down", 0])
	  
base.accept("arrow_left", setKey, ["cam-left", 1])
base.accept("arrow_left-up", setKey, ["cam-left", 0])
	  
base.accept("arrow_right", setKey, ["cam-right", 1])
base.accept("arrow_right-up", setKey, ["cam-right", 0])

base.accept("escape", sys.exit)

taskMgr.add(onUpdate, "myUpdate")

[color=darkred]#base.win.getGsg().setCoordinateSystem(2)
#base.camLens.setCoordinateSystem(2)

#base.camLens.setViewVector(0,0,-1,0,1,0)

print base.camLens.getViewVector()
print base.camLens.getUpVector()

sceneRoom = CSceneRoom()
sceneRoom.drawScene()

camera.setPos ( MAX_Cells/2,20,MAX_Cells/2)

run()

I couldn’t understand the state change when I use the red code.When I use gsg.setCoordinateSystem,the projection direction changed,When I use camLens.setCoordinateSystem,nothing happen.What is the right use of them?
BestRegards
wangzhi

if you want to rotate a camera, don’t set it in camlens. i also found camlens.setViewVector had no effect.

use base.camera or base.cam .
base.camera is not a camera, but a node that contains the actual camera - base.cam or other cameras, if base.camera is rotated, all cameras inside base.camera will be rotated.

base.camera.setHpr((h,p,r)) can work,
or
base.camera.lookAt((x,y,z))
or
base.camera.lookAt(another node which has position)

i guess setCoordinateSystem is not related to rotating a camera, but about the Z-up or Y-up system.