Jump to content

  • Log In with Google      Sign In   
  • Create Account

GameGeezer

Member Since 07 Feb 2010
Offline Last Active Yesterday, 01:44 PM

Topics I've Started

Help with matrix rotation

15 May 2014 - 05:44 PM

Hey, I'm currently working on a project that requires me to create a bunch of objects, rotate them locally, then revolve them all around a point.

 

I have a parent Node that contains all the objects I create so my idea was to create each object, rotate it to my desired orientation, translate it, add it to the parent node, and then rotate the parent node and have it recursively rotate the children.

 

My problem is that with multiple rotations everything starts to go haywire. I've spent a couple of days on this and haven't made much progress so if someone could point me in the right direction that would be wonderful! 

 

I have a Matrix for the model and a Vector3 to keep track of the translation

	protected Matrix4f model = new Matrix4f();
	protected Vector3 translation = new Vector3();

This is the code I'm using to rotate the objects.

public SceneNode rotate(float rot, float rx, float ry, float rz) {
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).rotate(rot, rx, ry, rz);
		}
		model.rotate(rot, rx, ry, rz);
		return this;
	}
	
	public SceneNode rotateLocal(float rot, float rx, float ry, float rz) {
		
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).rotateLocal(rot, rx, ry, rz);
		}
		float x = getX();
		float y = getY();
		float z = getZ();
		
		model.translate(-x, -y, -z);
		model.rotate(rot, rx, ry, rz);
		model.translate(x, y, z);
		return this;
	}

this is the code I'm using to translate the objects

	public SceneNode translate(float x, float y, float z) {
		for (Node<SceneNode> node : this.getSubnodes()) {
			((SceneNode) node).translate(x, y, z);
		}
		model.translate(x, y, z);
		translation.set(x, y, z);
		return this;
	}
This is the code where I'm creating the child node(bondObject)and attaching it to the parent(parentNode)
bondObject.rotateLocal(angle, x, y, z);
bondObject.setTranslation(x, y, z);
        		        		
parentNode.attach(bondObject);

And I want to rotate it every frame like this

parentNode.rotateLocal(1, 1, 1, 0);

how to use static variables properly in c++

24 February 2013 - 09:51 AM

Hey, I've been getting an error "Undefined reference to  Game:: window." I was wondering how I would go about declaring a static variable, initializing it, and accessing it properly. Thanks for your time.

 

cc file:

sf::RenderWindow* const Game::getWindow(void){
        return Game::window;
    }

 

h file:

public:
 static sf::RenderWindow* const getWindow(void);
private:
static sf::RenderWindow* window;

Ray Sphere intersection

20 November 2012 - 12:48 PM

Using this tutorial:http://wiki.cgsociety.org/index.php/Ray_Sphere_Intersection. I wrote a method to test ray,sphere intersections:
However I'm unsure as to what the direction vector will consist of. It's apparent that the direction vector isn't angles so I'm assuming it's the slope of the line in each direction?

float RaySphere::intersects(Ray* ray){
Vector3f dist = this->position.x_sub(&(ray->startpos));

float a = ray->angle.dotProd(&(ray->angle));
float b = 2 * ray->angle.dotProd(&(ray->startpos));
float c = ray->startpos.dotProd(&(ray->startpos)) - this->radius_squared;

float disk = b * b - 4 * a * c;

//no roots
if(disk <0)
  return -1;

float distsqrt = sqrt(disk);
float q;

if(b < 0)
  q = (-b-distsqrt)/2.0;
else
  q = (-b+distsqrt)/2.0;

float t0 = q / a;
float t1 = c / q;

//if t0 > t1 then swap them.
if(t0 > t1)
{
  float temp = t0;
  t0 = t1;
  t1 = temp;
}
//the ray missed the sphere
if(t1 < 0)
  return -1;
//if t0<0 intersection is at t1
if(t0<0)
  return t1;
//else its at t0
return t0;
}

Linux development

18 October 2012 - 06:27 PM

I'm trying to set up a development environment on linux but I've run into an error where my ide recognizes the libraries and event goes to finish my line when I type in "glGenTextures," but throws a bunch of errors like these:

/home/william/programming/workspaces/cplusplus/Test2/main.cpp|49|error: undefined reference to 'glGenTextures'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|50|error: undefined reference to 'glBindTexture'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|58|error: undefined reference to 'glTexImage2D'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|63|error: undefined reference to 'glEnable'|
/home/william/programming/workspaces/cplusplus/Test2/main.cpp|64|error: undefined reference to 'glEnable'|

I set up Opengl using this guy's tutorial(which was very comprehensive, I don't see anywhere I could have missed a step)
http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/video.php

my usr/include/GL contains all the files show in the video.

I've tried compiling this in Code: blocks and with this guy's make file.

I assume its a problem with linking, but I'm having trouble resolve exactly what to do.

Verts and indices correct?

08 October 2012 - 10:30 AM

I'm writing a marching cubes extractor for my game and I'm running into an error where there are vertices and indiec, but no polygons are being drawn.
Could anyone take a quick look at how i'm adding my vertices and indices? This is using JME3.

here is where I create my triangles

[source lang="java"] /* Create the triangle */ ArrayList<Triangle> t = new ArrayList<Triangle>(); for (i = 0; MCData.triTable[cubeindex][i] != -1; i += 3) { Triangle tri = new Triangle(vertlist[MCData.triTable[cubeindex][i]], vertlist[MCData.triTable[cubeindex][i+1]], vertlist[MCData.triTable[cubeindex][i+2]]); t.add(tri); }[/source]

Here is where I add my trianges to the mesh
[source lang="java"] //Node n = new Node("Node " + loc[0] + i + "," + loc[1] + j + "," + loc[2] + k); for (int triCt = 0; triCt < output.size(); triCt++) { mesh.getIndices().add(MCData.indexes[0] + mesh.getVertices().size()); mesh.getIndices().add(MCData.indexes[1] + mesh.getVertices().size()); mesh.getIndices().add(MCData.indexes[2] + mesh.getVertices().size()); mesh.getVertices().add(output.get(triCt).get1()); mesh.getVertices().add(output.get(triCt).get2()); mesh.getVertices().add(output.get(triCt).get3()); mesh.addNormals(MCData.normals); mesh.addTexCoords(MCData.texCoords); }[/source]
Do the VErts and indices appear to be added correctly? thanks.

PARTNERS