Noob Camera.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply

Noob ?

Poll ended at Mon Jun 30, 2008 11:06 am

Yes
1
8%
No
2
17%
ikenganai!
9
75%
 
Total votes: 12

NamVoDang
Posts: 2
Joined: Fri Jun 20, 2008 10:24 am

Noob Camera.

Post by NamVoDang »

I'm....my... ...English....is.....very bad.........bad....bad....bad......
Because I Am Noob.

Noob@FOSProject.vn

Code: Select all

/**
 * \RunOn: SGF(Simple Game Framework) - Irrlicht Engine
 * \Summary: Third Person Camera
 * \Filename: ThirdPersonCamera.cpp
 * \Encoding: UTF-8
 * \CreatedDate: 2:17:PM 2008/06/15
 * \CreatedBy: FOSP Team - NamVoDang(kiemkhachchilo)
 * \Copyright: Permission is granted to anyone to use this software/code
 * \ for any purpose, including commercial applications, and to alter it
 * \ and redistribute it freely
 **/

#include "ThirdPersonCamera.h"
using namespace irr;
using namespace scene;
using namespace core;
ThirdPersonCamera::ThirdPersonCamera(ISceneNode* targetNode)
{    
	    this->targetNode = targetNode;
		Zoom = 2;
		nRotationX = 0;
		nRotationY = 0;
		rotating = false;
		Mouse[0] = false;
		Mouse[1] = false;
		rotation = vector3df(0,15,-25);//Default rotation on level enter.
		mouseDelegate.addRef();
		mouseDelegate.bind(this,&ThirdPersonCamera::onMouse);
} 

void ThirdPersonCamera::onAdd()
{
		cursor = manager->getCore()->getGraphicDevice()->getCursorControl();
		ISceneManager* smgr = manager->getCore()->getGraphicDevice()->getSceneManager();
		camera = smgr->addCameraSceneNode();//add camera.
	 //terrain.
		terrain = manager->getCore()->globalVars["terrain"].getAs<irr::scene::ITerrainSceneNode*>();
		manager->getCore()->getInputManager()->getMouseEvent()->addDelegate(&mouseDelegate);
		manager->setActive(this,true);
}

void ThirdPersonCamera::update(float deltaTime)
{	
	if (Mouse[1])//Rotation process.
    {
		if (!rotating)
		{
	       mousePos = cursor->getPosition();
	       curMousePos = mousePos;
		   rotating = true;

		}
		else
		{
		   rotation = vector3df(0,15,-25);
		   mousePos = cursor->getPosition();
		   nRotationX += mousePos.X - curMousePos.X;
		   nRotationY += mousePos.Y - curMousePos.Y;
		   rotation.rotateYZBy((nRotationY)*0.25,vector3df(0,0,0));
		   rotation.rotateXZBy((nRotationX)*-0.25,vector3df(0,0,0));//The value (mousePos.X - curMousePos.X) determine camera rotation.
		   curMousePos = mousePos;
		}
    }
	    target = targetNode->getPosition();
     	camPos = rotation;
		camPos *= Zoom;//Zoom process.
		camPos += target;
	 //Invoid under terrain camera
        if (camPos.Y < terrain->getHeight(camPos.X,camPos.Z) + 5)
		{
			camPos.Y = terrain->getHeight(camPos.X,camPos.Z) + 5;
		}
		
	 //Update camera.
		camera->setTarget(target); 
		camera->setPosition(camPos); 
}

void ThirdPersonCamera::onRemove()
{
        manager->getCore()->getInputManager()->getMouseEvent()->removeDelegate(&mouseDelegate);//remove delegate
		camera->remove();//remove object
}

void ThirdPersonCamera::onMouse(SMouseEvent& args)
{
		if(args.mouseEvent==EMIE_MOUSE_WHEEL)//On Wheel Event.
		{
			Zoom = Zoom + args.wheel*0.25;//change zoom speed by  wheel value
			
			//Dont zoom in or out in max and min zoom value is reached
			if (Zoom < 0.5)
				Zoom = 0.5;
			if (Zoom > 3.5)
				Zoom = 3.5;
		}
		else if(args.mouseEvent==EMIE_RMOUSE_PRESSED_DOWN)
		{    
			 Mouse[1] = true;
		}
		else if(args.mouseEvent==EMIE_RMOUSE_LEFT_UP)
		{
			 Mouse[1] = false;
			 rotating = false;
		}
}

ICameraSceneNode* ThirdPersonCamera::getPointer() const
{
	return camera;
}

Code: Select all

/**
 * \RunOn: SGF(Simple Game Framework) - Irrlicht Engine
 * \Summary: Third Person Camera
 * \Filename: ThirdPersonCamera.h
 * \Encoding: UTF-8
 * \CreatedDate: 2:17:PM 2008/06/15
 * \CreatedBy: FOSP Team - NamVoDang(kiemkhachchilo)
 * \CreatedBy: FOSP Team - NamVoDang(kiemkhachchilo)
 * \Copyright: Permission is granted to anyone to use this software/code
 * \ for any purpose, including commercial applications, and to alter it
 * \ and redistribute it freely
 **/

#ifndef _THIRD_PERSON_CAMERA_H_
#define _THIRD_PERSON_CAMERA_H_

#include "SGF.h"
#include <functional>
#include <irrlicht.h>
using namespace irr;
using namespace scene;
using namespace core;
class ThirdPersonCamera: public sgfEntity 
{
public:
	ThirdPersonCamera(ISceneNode* targetNode);
	ICameraSceneNode* getPointer() const;
private:
	float Zoom;
    s32 Rotation,nRotationX,nRotationY;
	bool rotating;
	bool Mouse[1];//Left 0, Right 1.
	gui::ICursorControl* cursor;
	position2d<s32> mousePos;
	position2d<s32> curMousePos;
	vector3df camPos;//Camera position.
	vector3df target;//Look at.
	vector3df rotation;
	f32 RotateStartX, RotateStartY, curentRotateStartX, curentRotateStartY;
	ISceneNode* targetNode;//Character.
	ICameraSceneNode* camera;//Camera.
	ITerrainSceneNode* terrain;
	sgfMethodDelegate<ThirdPersonCamera,SMouseEvent> mouseDelegate;//Register mouse event.
	void onAdd();
	void update(float deltaTime);//Update.
	void onRemove();
	void onMouse(SMouseEvent& args);
};
#endif
__________________________________________________
- Kiếm trung đệ nhất môn -
Võ Đang
Last edited by NamVoDang on Wed Jun 25, 2008 5:43 am, edited 1 time in total.
Noob@FOSProject.vn

Thói đời, hễ ai kiến thức ít ỏi thì sẽ thấy lắm thứ đáng ngạc nhiên
-Bão Phác Tử-
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

iken ga nai...
japanese? xD

didn't try the code, but could you put out a screenshot or demo or something?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Thanks for sharing. A few problems:

1) You didn't share. This code is copyrighted and has no license, and also it relies on your proprietary files and classes. It's therefore useful only as a teaching aid.

2) Since you don't say what it's supposed to do, either explicitly or in comments (Klingon doesn't count), and it can't be compiled in order to try it, it's useless as a teaching aid.
Last edited by rogerborg on Fri Jun 20, 2008 2:14 pm, edited 1 time in total.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
bull
Posts: 36
Joined: Wed Sep 12, 2007 8:49 am
Location: s1Ng4p0R3

Post by bull »

Sigh...
It has unknown dependency.
Comments are in an unknown language(I can get pass that)
The behaviour is unknown.
No screenshot.

What am I supposed to do with it?
My name is bull, for we are many ...
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

is it klingon?
i see! i have a friend who knows klingonese xD
maybe i should ask him :P
mikademus
Posts: 7
Joined: Fri May 23, 2008 8:26 pm

Post by mikademus »

It is probably Thai or Vietnamese (though it is quite difficult to distinguish from Burmese or Laotian in writing with Western characters).
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Rogerborg's Unified Theory of Language: everything is either English, or a dialogue of Welsh.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
huydotnet
Posts: 81
Joined: Tue Sep 25, 2007 12:26 pm
Location: Danang, Vietnam

Post by huydotnet »

mikademus wrote:It is probably Thai or Vietnamese (though it is quite difficult to distinguish from Burmese or Laotian in writing with Western characters).
It's Vietnamese :)
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Post by doqkhanh »

B@z wrote:iken ga nai...
japanese? xD
You're right!

意見がない 

>>>>>>

There is no opinion
or
No comment v.v..
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

yeah, i know it xD i know japanese you know :P

but why did he write it? xD
NamVoDang
Posts: 2
Joined: Fri Jun 20, 2008 10:24 am

Post by NamVoDang »

Hi, sorry about using non-english language. I've fixed it. Anyways, thanks for your replies

To b@z: Just a joke. Sorry.
Noob@FOSProject.vn

Thói đời, hễ ai kiến thức ít ỏi thì sẽ thấy lắm thứ đáng ngạc nhiên
-Bão Phác Tử-
Post Reply