Show Posts
|
|
Pages: [1] 2 3
|
|
1
|
Java Game APIs & Engines / Xith3D Forums / Xith view TransformGroup Position
|
on: 2006-06-18 00:01:09
|
|
Hi,
when terrain following with view - using JCD's FPS camera when I get the view.getTransform().get( Vector3f ) - the z/x position of the view appears to be 200-300 units ahead or off , of the actual camera. or in other words - when terrain following - The camera dips and rises as if it were following another transformGroup - thus giving a false Y height
is this correct? is there a way of getting the actual camera's Transform position vector3f?
|
|
|
|
|
3
|
Java Game APIs & Engines / Xith3D Forums / Re: XithTerrainTest walkaround
|
on: 2006-06-16 21:04:58
|
the class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
| public class SceneCamera { private TransformGroup cameraGroup ; numberConstants cons = new numberConstants();
private Vector3f upVector = new Vector3f(0f, 0f, 1f), tempVector = new Vector3f(0f, 0f,.0f), viewVector = new Vector3f(0f, 1f,.5f), axisVector = new Vector3f(0f, 0f, 0f), strafeVector = new Vector3f(0f, 0f, 0f), positionVector = new Vector3f(0f, 0f,.0f); public Vector3f moveCameraVector = new Vector3f(0f, 0f, 0f);
private boolean keys[] = null, frameActive = false;
private Insets insets = null;
private Point mousePosition = null, componentPosition = null;
private Robot mouseRobot = null;
private float currentRotX = 0;
private int screenWidth = 0, screenHeight = 0, xOffSet = 0, yOffSet = 0; private OpusOne gameBoss; public float angleY = 0f,angleZ = 0f; public boolean mouseHasMoved =false;
public SceneCamera(OpusOne boss, boolean keys[], TransformGroup cameraGroup, javax.swing.JFrame parentFrame){
this.gameBoss=boss; insets = parentFrame.getInsets(); this.keys = keys; this.cameraGroup = cameraGroup; setComponentPosition(parentFrame.getLocation().x, parentFrame.getLocation().y);
Toolkit.getDefaultToolkit().addAWTEventListener( new EventListener(), AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); try{ mouseRobot = new Robot(); } catch(Exception e){} }
public void setScreenSize(int width, int height){ screenWidth = width; screenHeight = height; mousePosition = new Point(width>>1,height>>1); }
public void positionCamera(float xPosition, float yPosition, float zPosition, float xView , float yView , float zView , float xUpVector, float yUpVector, float zUpVector){ positionVector.set( xPosition, yPosition, zPosition); viewVector.set( xView , yView , zView ); upVector.set( xUpVector, yUpVector, zUpVector); }
public void moveCamera(float speed){ moveCameraVector.sub(viewVector, positionVector); moveCameraVector.normalize(); positionVector.scaleAdd(speed, moveCameraVector, positionVector); viewVector.scaleAdd( speed, moveCameraVector, viewVector ); }
public void setViewByMouse(){
int middleX = (screenWidth >> 1) , middleY = (screenHeight >> 1) ;
if((mousePosition.x == middleX) && (mousePosition.y == middleY) ) return;
angleY = (float)( (middleX - mousePosition.x) ) / 500.0f; angleZ = (float)( (middleY - mousePosition.y) ) / 500.0f;
if(frameActive) mouseRobot.mouseMove(componentPosition.x + middleX, componentPosition.y + middleY);
currentRotX -= angleZ;
if(currentRotX > 1.0f) currentRotX = 1.0f; else if(currentRotX < -1.0f) currentRotX = -1.0f; else{ axisVector.sub( viewVector, positionVector); axisVector.cross(axisVector, upVector ); axisVector.normalize(); rotateView(angleZ, axisVector.x, axisVector.y, axisVector.z); rotateView(angleY, 0, 1, 0); }
}
private void rotateView(float angle, float x, float y, float z){ tempVector.sub(viewVector, positionVector);
float cosTheta = FastTrig.cos(angle), sinTheta = FastTrig.sin(angle), oneMinusCosTheta = 1f - cosTheta;
viewVector.x = (cosTheta + oneMinusCosTheta * x * x) * tempVector.x; viewVector.x += (oneMinusCosTheta * x * y - z * sinTheta) * tempVector.y; viewVector.x += (oneMinusCosTheta * x * z + y * sinTheta) * tempVector.z;
viewVector.y = (oneMinusCosTheta * x * y + z * sinTheta) * tempVector.x; viewVector.y += (cosTheta + oneMinusCosTheta * y * y) * tempVector.y; viewVector.y += (oneMinusCosTheta * y * z - x * sinTheta) * tempVector.z;
viewVector.z = (oneMinusCosTheta * x * z - y * sinTheta) * tempVector.x; viewVector.z += (oneMinusCosTheta * y * z + x * sinTheta) * tempVector.y; viewVector.z += (cosTheta + oneMinusCosTheta * z * z) * tempVector.z;
viewVector.add(positionVector); }
private void strafeCamera(float speed){ positionVector.x += strafeVector.x * speed; positionVector.z += strafeVector.z * speed;
viewVector.x += strafeVector.x * speed; viewVector.z += strafeVector.z * speed; }
private void elevateCamera(float speed){ positionVector.y += upVector.y*speed; viewVector.y += upVector.y*speed; }
private void checkForMovement(float frameInterval){ float mspeed = cons.moveSpeed * frameInterval; float rspeed = cons.raiseSpeed * frameInterval; if(keys[KeyEvent.VK_UP ] || keys['W']) moveCamera( mspeed); if(keys[KeyEvent.VK_DOWN ] || keys['S']) moveCamera( -mspeed); if(keys[KeyEvent.VK_LEFT ] || keys['A']) strafeCamera( -mspeed); if(keys[KeyEvent.VK_RIGHT ] || keys['D']) strafeCamera( mspeed); if(keys[KeyEvent.VK_PAGE_UP ] || keys['E']) elevateCamera( rspeed); if(keys[KeyEvent.VK_PAGE_DOWN] || keys['Q']) elevateCamera(-rspeed); }
public void update(float frameInterval){ strafeVector.sub( viewVector , positionVector); strafeVector.cross(strafeVector, upVector); strafeVector.normalize();
setViewByMouse(); checkForMovement(frameInterval); cameraGroup.getTransform().lookAt(new Vector3f(positionVector), new Vector3f(viewVector ), new Vector3f(upVector )); }
public Vector3f getPositionVector() { return positionVector;} public Vector3f getStrafeVector() { return strafeVector ;} public Vector3f getViewVector() { return viewVector ;} public Vector3f getUpVector() { return upVector ;}
public boolean getFrameState(){ return frameActive; }
public void setComponentPosition(int x, int y){ if(componentPosition == null) componentPosition = new Point();
componentPosition.setLocation(x,y); }
public void setFrameState(boolean state){ frameActive = state; }
public void mouseMoved(MouseEvent me){ mouseHasMoved =true; mousePosition = me.getPoint(); mousePosition.x +=insets.left; mousePosition.y +=insets.top; }
public class EventListener implements AWTEventListener{
public void eventDispatched(AWTEvent event){ if(event instanceof MouseEvent){ MouseEvent e = (MouseEvent) event; switch(e.getID()){ case MouseEvent.MOUSE_MOVED: mouseMoved(e); break; case MouseEvent.MOUSE_DRAGGED: mouseMoved(e); break; case MouseEvent.MOUSE_PRESSED: gameBoss.fireBullet1(); gameBoss.fireBullet2();break; } } } }
} |
maybe i have this all wrong but I thought that if I changed the Y (in accordance with the Y value of the terrain ) of positionVector and viewVector the camera should maintain a constant view level and position would follow the terrain. But what happens is the camera gets stuck at the y view and will not follow the mouse up or down while terrain following . when the camera stops - then normal mouse movement come back.
|
|
|
|
|
4
|
Java Game APIs & Engines / Xith3D Forums / Re: XithTerrainTest walkaround
|
on: 2006-06-16 14:41:47
|
|
Thanks for your answer - but I meant the terrain following part.
the camera class has 3 vector3f - positionVector , viewVector and upVector (which conforms to our standard Xith View )
I have tried modifying the Y on the positionVector , viewVector - in accordance with terrain height
but I get some really wierd results -
I have also tried modifying tye Matrx4f - but again get same strange results
any help ?
|
|
|
|
|
8
|
Java Game APIs & Engines / Xith3D Forums / Re: Buffer Underflow when adding Child
|
on: 2006-02-02 14:09:59
|
its alot of code - so I have tried to be relevant here goes: this is my Loop : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Global BranchGroup : TOPGUESTTRANSFORM
run (){ try {
while (isthreadAlive) { startTime = System.currentTimeMillis(); currentTime = System.currentTimeMillis(); fps++; if (currentTime - lastTime >= 500) { framePerSec=fps << 1; if (!fullScreen) { parentFrame.setTitle("BreedaMorph Demo: FPS "+ String.valueOf(framePerSec)); lastTime = currentTime; fps = 0; } } processMessageQue(); processAnimations(); translateAnyMoves(); processKeyPostRequests(); doAvatarTerrainFollowing(); doCameraTerrainFollowing(); avController.update(view) doMove(new Vector3f(0, height, distance)); setCameraDistances() collisionFrames=doCollisionChecking(collisionFrames); doCameraCollisionChecking(); moveSea(0.0003f,new Vector3f(0.0f,0.00002f,0.0f)); doPingIfRequired(); view.renderOnce();
timeTaken = System.currentTimeMillis() - startTime; if (timeTaken < MILLIS_PER_TICK) { synchronized (this) { wait((int)MILLIS_PER_TICK - timeTaken);
} } else { currentThread.yield(); } } } catch (java.nio.BufferUnderflowException ioe){} } |
method processMessageQue() looks at a Queue of instructions and calls the necessary function so if there is a addNewPlayer() instruction - this function is run: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public void addNewPlayer(String name, String ipAddress,Vector3f positionVector) { MD2ModelInstance playerHead; MD2ModelInstance playerBody; MD2ModelInstance playerShell; TransformGroup t = new TransformGroup();
newMD2Object md22 = new newMD2Object(1.0f,t); md22.loadModel("characters/head.md2","characters/headtex.pcx"); playerHead=md22.getInstance(); newMD2Object md23 = new newMD2Object(1.0f,t); md23.loadModel("characters/shell.md2","characters/shelltex.pcx"); playerShell=md23.getInstance(); setPolygonAttributes(t,true,PolygonAttributes.POLYGON_FILL,PolygonAttributes.CULL_BACK); newMD2Object md21 = new newMD2Object(3.5f,t); md21.loadModel("characters/body.md2","characters/bodytex.pcx"); playerBody=md21.getInstance(); t.addChild(new Text2d(name)); t.getTransform().setTranslation(positionVector); playerObject p = new playerObject(t, ipAddress,name,playerHead,playerBody,playerShell); otherPlayers.addElement(p); TOPGUESTTRANSFORM.addChild(t); } |
now using the same instruction Queue - if there are any positional updates: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public void updatePlayerPositions(TransformGroup playerTransformGroup, String MatrixString) { java.util.List nodes = TOPGUESTTRANSFORM.getChildren(); Matrix4f p =new Matrix4f(); String[] MatrixArray = MatrixString.split(","); p.setRow(0,toFloat(MatrixArray[0]),toFloat(MatrixArray[1]),toFloat(MatrixArray[2]),toFloat(MatrixArray[3])); p.setRow(1,toFloat(MatrixArray[4]),toFloat(MatrixArray[5]),toFloat(MatrixArray[6]),toFloat(MatrixArray[7])); p.setRow(2,toFloat(MatrixArray[8]),toFloat(MatrixArray[9]),toFloat(MatrixArray[10]),toFloat(MatrixArray[11])); p.setRow(3,toFloat(MatrixArray[12]),toFloat(MatrixArray[13]),toFloat(MatrixArray[14]),toFloat(MatrixArray[15]));
for (int i = 0; i < nodes.size(); i++) { SceneGraphObject obj = (SceneGraphObject) nodes.get(i); if (obj instanceof TransformGroup) { String objName=((TransformGroup)obj).getName(); String playerName=playerTransformGroup.getName(); if(objName.equals(playerName)) { Transform3D j = new Transform3D(); j=((TransformGroup)obj).getTransform(); j.set(p);
((TransformGroup)obj).setTransform(j); break; } } } } |
aside from the sloppy code any ideas why i would still be getting Buffer Under Flow exception?
|
|
|
|
|
10
|
Java Game APIs & Engines / Xith3D Forums / Re: Buffer Underflow when adding Child
|
on: 2006-02-01 00:59:31
|
|
Sorry arne - but I don't understand what you mean by that. I thought My rendering loop i.e. the run method was the rendering thread.
My scene is contructed in the class constructor - and my run method renders and updates my scene
Do I pass my scene to the run method and add new transformgroups there or do I construct my scene with a global transformgroup and pass this to my run method - to add children to...
confused
Rmdire
|
|
|
|
|
11
|
Java Game APIs & Engines / Xith3D Forums / Re: Buffer Underflow when adding Child
|
on: 2006-01-31 23:49:33
|
|
HI
What is the best way to add a new TransformGroup to my scene at runtime?
Currently I have a Global Transformgroup that I added to my scene during construction. and when schedualed - I am using my rendering loop to add a new child to this Global Transformgroup as needed. However I somtimes get a Buffer Underflow exception when I try to update these childrens positioning.
anybody help? cheers
Rmdire
|
|
|
|
|
13
|
Java Game APIs & Engines / Xith3D Forums / Setting antialiasing in PolygonAttributes
|
on: 2006-01-24 14:52:14
|
|
HI, I just wondered if this was a bug or something I am not doing but:
I have a terrain with a river mesh object running thru it - the river is set to transparent. when I set the PolygonAttributes for my terrain with antialiasing enabled instead of being able to see the underneath terrain thru the river. the sky box underneath shows thru the terrain thru the river mesh.
any ideas?
rmdire
|
|
|
|
|
17
|
Java Game APIs & Engines / Xith3D Forums / Re: MD2 Lighting etc.
|
on: 2006-01-12 16:59:33
|
|
unfortuately - that wont work either - MD2Model has its own private Method getAppearance() but no setAppearance() - (Im using eclipse - so all native and inherited properties/methods show in the intelli-sense)
I don't think this gonna happen somehow.
|
|
|
|
|
19
|
Java Game APIs & Engines / Xith3D Forums / Re: MD2 Lighting etc.
|
on: 2006-01-11 14:58:03
|
|
Material mat2 = new Material(false); //mat2.setColorTarget(mat2.EMISSIVE); mat2.setEmissiveColor(new Color3f(2.3f, 0.3f, 0.3f)); //mat2.setColorTarget(mat2.SPECULAR); mat2.setSpecularColor(new Color3f(2.2f, 0.2f, 1.2f)); //mat2.setColorTarget(mat2.AMBIENT); mat2.setAmbientColor(new Color3f(2.7f, 0.7f, 0.7f)); //mat2.setColorTarget(mat2.DIFFUSE); mat2.setDiffuseColor(new Color3f(2.0f, 0.5f, 0.5f)); mat2.setShininess(0.9f); mat2.setLightingEnable(true);
model.getAppearance().setMaterial(mat2);
character = model.getInstance(); BranchGroup temp = new BranchGroup(); temp.addChild(character);
|
|
|
|
|
20
|
Java Game APIs & Engines / Xith3D Forums / Re: MD2 Lighting etc.
|
on: 2006-01-11 01:13:26
|
|
HI ,
Have tried several combinations - including setColorTarget for each setting as suggested - no joy
I have even tried to turn up the Red , Green and Blue individually to see if there is a singular colour effect - again no joy
arne - was setColorTarget a shot in the dark or have you had success already?
From the source code I see there is a MD2Model.getAppearance() Method - I have also tried using this to set appearance prior to getting the model instance again - no joy
any Ideas?
|
|
|
|
|
21
|
Java Game APIs & Engines / Xith3D Forums / MD2 Lighting etc.
|
on: 2006-01-10 17:41:42
|
|
Hi,
I hope someone can help - I am using an MD2 file which I load into my scene
I attached material like so :
Material mat2 = new Material(true); mat2.setEmissiveColor(0.0f, 0.0f, 1.0f); mat2.setSpecularColor(0.2f, 0.2f, 1.2f); mat2.setAmbientColor(0.7f, 0.7f, 0.7f); mat2.setDiffuseColor(0.1f, 0.1f, 1.1f); mat2.setAmbientColor(0.75f,0.75f,0.75f); mat2.setDiffuseColor(0.75f,0.75f,0.75f);
mat2.setLightingEnable(true);
//recusively add materials addMaterial(modelTransformGroup, mat2);
But the model appears very flat without any shadows - I used the same "mat2" on both .OBJ and .ASE and the result is fine.
does MD2 not respond to the above Material?
I followed the example from within the MD2 loader file - and thats much the same
what am I doing wrong?
Thanks
Rmdire
|
|
|
|
|
23
|
Java Game APIs & Engines / Xith3D Forums / Re: Rotating and Moving?
|
on: 2005-12-13 17:24:15
|
Hi , I'm a newbie too, but I think I can help you : This is the function I use for Moving forward : 1 2 3 4 5 6 7 8
| public void doMove(TransformGroup transformGroup, Vector3f theMove) { Transform3D transform3D = new Transform3D() transformGroup.getTransform(transform3D); Transform3D toMove = new Transform3D(); toMove.setTranslation(theMove); transform3D.mul(toMove); transformGroup.setTransform(transform3D); } |
and for a Rotation I use: 1 2 3 4 5 6 7 8 9
| public void doRotateY(TransformGroup transformGroup,float radians) { Transform3D transform3D = new Transform3D() transformGroup.getTransform(transform3D); Transform3D toMove = new Transform3D(); toMove.rotY(radians); transform3D.mul(toMove); transformGroup.setTransform(transform3D); } |
I hope this helps Cheers Rmdire
|
|
|
|
|
24
|
Java Game APIs & Engines / Xith3D Forums / Re: latest Xith not working with Radeon 9200 128mb - OGL 1.3.4
|
on: 2005-12-12 01:07:55
|
HI William, you mention in another post that: Re: How to detect no 3d hardware available « Reply #7 on: November 12, 2005, 08:37:48 pm »
-------------------------------------------------------------------------------- Actually I think you need OpenGL 1.3 or better now.
The crappy Microsoft one won't work for much at all (not just Xith3D).
ATI or nVidia are your best bets. Even their really old and crap cards still get driver updates and still work with Xith3D.
Will.

|
|
|
|
|
27
|
Java Game APIs & Engines / Xith3D Forums / Re: ASE Loading textures
|
on: 2005-12-09 11:53:49
|
HI Arne - Forgive my total ignorance - but I cant see how to access the ASELoader's TextureLoader in order to set the path. this is how I load in my ASE file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| AseFile af = new AseFile(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(path)); } catch (IOException e) { URL url = this.getClass().getClassLoader().getResource(path); try { br = new BufferedReader(new InputStreamReader(url.openStream())); } catch (IOException e1) { e1.printStackTrace(); } } AseReader r = new AseReader(br, af); af.parse(r); namedNodes = new HashMap (); TransformGroup rootTG = af.getTransformGroupTree(namedNodes); |
How should I access the ASELoader's TextureLoader in order to set the path. Cheers Rmdire
|
|
|
|
|
30
|
Java Game APIs & Engines / Xith3D Forums / Re: ASE Loading textures
|
on: 2005-12-08 10:46:35
|
|
Thanks arne,
Yep, I have been using these functions already - I got it from one of your previous posts.
But the model just shows up as white without any reflective feature,
This is why I was wondering if the ASE loading of textures is actually implemented.
actually what I've just done is move the textures out of the folder they should be in and tried to load the model in. and its loaded without any "cannot find resource errors" - so theres my answer - textures are not working for the ASE loader.
is this correct?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|