Jump to content

  • Log In with Google      Sign In   
  • Create Account

D.Chhetri

Member Since 16 Oct 2009
Offline Last Active May 10 2014 06:46 PM

Topics I've Started

Someone explain if the following function is dangling pointer?

14 June 2013 - 09:39 AM

const char *foo1(){
  const char* a = "foo1";
  return a;
}
const char* foo2() {
 std::string myString = "foo2!";
 return myString.c_str();
}


int main(){
    foo1();
    foo2();
}

Html5 Canvas: Why in the following JSFiddle, the stroke rectangle full opacity value is...

03 May 2013 - 08:35 PM

Here is the http://jsfiddle.net/DV9Bw/558/ . I'm not sure why there is opacity less than 255. If you hover over the non-overlapping section, you can see that the opacity is 127/128. Can someone clear this up for me? Why isn't opacity full (255). Also more importantly, why in the overlapping section, the two rectangle pixels are combined, instead of the destination rectangle(blue one I believe) completely take over the pixel at that coordinate? Is this just how the strokeRectangle works? If I change the stroke to fill, as in fillRectangle, then everything works as expected. Any help is greatly appreciated!


Texturing a cube via glTexGen

13 November 2012 - 09:17 PM

void Building::_renderDefaultBuilding()const{
    glColor3f(1.0f,1.0f,1.0f);
    glTranslatef(m_position.x,m_position.y,m_position.z);
    Vector3f t = m_size / 2.0f;
    glTranslatef(t.x,t.y,-t.z); //translate so its bottom surface starts at (0,0,0)
    glScalef(m_size.x,m_size.y,m_size.z);
   
    if(!Resource::textureList.empty()){
	    glBindTexture(GL_TEXTURE_2D, Resource::textureList[Resource::NIGHT_BUILDING_TEXTURE]);
	    float s[] = {0.01f,0.0f,0.0f,0.0f};
	    float t[] = {0.0f,0.01f,0.0f,0.0f};
	    glTexGenfv(GL_S, GL_OBJECT_LINEAR, s);
	    glTexGenfv(GL_T, GL_OBJECT_LINEAR, t);
	    glEnable(GL_TEXTURE_GEN_S);		 // Auto Texture Generation
	    glEnable(GL_TEXTURE_GEN_T);
    }
    glutSolidCube(1.0f);
    glScalef(1.0f/m_size.x,1.0f/m_size.y,1.0f/m_size.z);
    glTranslatef(-t.x,-t.y,t.z);
    glTranslatef(-m_position.x, -m_position.y, -m_position.z);
}

so I have the above code, but I need help with auto generating the textures such that I can scale which part of the texture gets rendered. Any help on this?

Need help drawing a fractal tree

30 October 2012 - 12:33 AM

The current problem I'm having right now is drawing the next branch starting at the end point of its parents branch.
Not sure how to achieve the above using glRotate/glTranslate. Currently this is the drawing function
void _generateTreeBranches(const Point3f& newPosition,
						   float length,
						   float rotation,
						   const int depth)
{
	if(depth > MAX_DEPTH) return;
	cout << "at depth = " << depth << endl;
  
   //for debugging
	if(depth == 0){
		glColor3f(1.0f,1.0f,1.0f);
	}else if(depth == 1){
		glColor3f(1.0f,0.0f,0.0f);
	}else{
		glColor3f(0.0f,1.0f,0.0f);
	}
  
	glTranslatef(newPosition.x,newPosition.y,newPosition.z);
	glRotatef(rotation, 0.0f, 0.0f, 1.0f);
	drawLine(length); //draws centered at origin
	glRotatef(-rotation, 0.0f, 0.0f, 1.0f);
	glTranslatef(-newPosition.x,-newPosition.y,-newPosition.z);
  
  
	const float newLength = length * BRANCH_LENGTH_DECREASE_FACTOR;
	int nextDepth = depth + 1;
	Point3f nextPosition = {newPosition.x+length, newPosition.y, newPosition.z};
  
	float leftRotation = rotation + CHILD_BRANCH_ANGLE * nextDepth;
	_generateTreeBranches(nextPosition,newLength,leftRotation,nextDepth);
  
	float rightRotation = rotation - CHILD_BRANCH_ANGLE * nextDepth;
	_generateTreeBranches(nextPosition,newLength,rightRotation,nextDepth);
  
  
}

Not sure, I'm guessing my next step would be to calculate the 'nextPosition' based on the current rotation, which should be the endPoint of the current line. Any advice on how to properly setup the positioning so that the line is generated starting at the endpoint of its parent's line. I really want to avoid manually calculating the position end based on angle of rotation and just let opengl do that via glTranslate/glRotate, but for this maybe there is no way out.

Trying to rotate around a point

29 October 2012 - 09:42 PM

I think im doing it correctly but the end result is not what I want, here is the code :


void _generateTreeBranches(const Point3f& startPoint,
						   const Point3f& endPoint,
						   float rotation,
						   const int depth)
{
	if(depth > MAX_DEPTH) return;
	cout << "at depth = " << depth << endl;
	if(depth == 0)glColor3f(0.0f,1.0f,0.0f);
	else glColor3f(1.0f,1.0f,1.0f);
  
	float distanceOfPoint = pointDistance(startPoint, endPoint);
  
	glRotatef(rotation, 0.0f, 0.0f, 1.0f);
	glTranslatef(-startPoint.x, 0.0f, 0.0f);
		drawLine(startPoint, endPoint);
	glTranslatef(startPoint.x, 0.0f, 0.0f);
	glRotatef(-rotation, 0.0f, 0.0f, 1.0f);
  
	const float nextLength = distanceOfPoint;
	Point3f nextBranchStart = endPoint;
	Point3f nextBranchEnd = {endPoint.x + nextLength,endPoint.y,endPoint.z};
	_generateTreeBranches(nextBranchStart, nextBranchEnd,45.0f,depth+1);
  
}


It draws something like


/____

instead of the desired
_____/

any advice?


Also I've noticed that I can either manipulate glTranslate to position my object at position X or I can simply set its coordinates to be draw at position X. Which one is more preferable ?

PARTNERS