We have two points A and B in 3D. The problem is to find the way to draw a line that the started point is A and the later is B. We also want to have a little arrow at B.
One guy posted the guide in gamedev.net
Say: A = [x1, y1, z1] (start)
and B = [x2, y2, z2] (end)
and C = [x3, y3, z3] (arrow tip at one side)
and D = [x4, y4, z4] (tip at the other side)
if((z1-z2) != 0) {
first we make a normal vector:
x3 = 1
y3 = 1
z3 = (-(x1-x2)-(y1-y2))/(z1-z2)
adjusting the distance from the arrow axis to one fourth of the arrows lenght:
adj = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)) / (4 * sqrt((x3^2)+(y3^2)+(z3^2)));
x3 *= adj
y3 *= adj
z3 *= adj
setting the other side:
x4 = -x3
y4 = -y3
z4 = -z3
gettin the point:
x3 = x1 + (3/4)*(x1-x2) + x3
y3 = y1 + (3/4)*(y1-y2) + y3
z3 = z1 + (3/4)*(z1-z2) + z3
x4 = x1 + (3/4)*(x1-x2) + x4
y4 = y1 + (3/4)*(y1-y2) + y4
z4 = z1 + (3/4)*(z1-z2) + z4
}
OK, I didn't double check this, but the clue is the "first we make a normal vector:" -section, the rest is fairly straight out. Oh and if you use float or double values, they rarely become zero, but if (z1-z2) should happen to be zero, then find the normal setting z3 = 1, y3 = 1, and x3 = (-(y1-y2)-(z1-z2))/(x1-x2), that should work work as well, and if (x1-x2) also is zero, just base it on y the same way.
Well, as I said, I didn't double check this, but I know it works, there might be simpler ways also, be sure to tell me if I made some stupid mistakes here.
I appreciate this explanation.
Programming, Researching, Engineering, Employing and Analyzing of Troubleshootings. In addition, we study Usability - HCI - GUI - OpenGL - Project Management.
Thursday, October 8, 2009
Wednesday, October 7, 2009
Programming with SDL and OpenGL
Introduction and how to compile an simple program in SDL-OpenGL
Mouse coordinates SDL using UnProject and Project (glu). More detailed information here.
Mouse coordinates SDL using UnProject and Project (glu). More detailed information here.
Saturday, October 3, 2009
Installing PHP5, MySQL and Apache on Ubuntu
Để lập trình web sử dụng PHP và MySQL trên Ubuntu, chúng ta nên sử dụng XAMPP. Xem trên trang này, chúng ta sẽ biết cách cài đặt. Khá đơn giản vì chúng ta chỉ cần cài gói XAMPP dành cho Linux nên việc cấu hình còn lại chỉ là sử dụng xampp như thế nào cho đúng.
Tuy nhiên, ngoài những bước kiểm tra như trong các trang cài đặt, chúng ta cần kiểm tra thêm một vài thứ như sau:
Rõ ràng, nếu chúng ta đã cài đặt XAMPP thì không cần thiết phải cài đặt riêng từng gói như PHP, MySQL hay Apache... Vì thế, từ bất kỳ vị trí nào ngoài /opt/lampp/bin, chúng ta gõ mysql -u root -p (sau đó yêu cầu password) thì có nghĩa là trên máy bạn đã có mysql.
Có vấn đề tôi gặp phải là:
Giải quyết tình huống 3:
Nếu đã giải quyết tình huống 2 xong thì 3 ok. Hướng dẫn đầy đủ nhất xem trên trang này.
+================================================================+
SAU ĐÂY LÀ CÁC LỆNH ĐẦU TIÊN DÙNG TRÊN MYSQL
1. Tạo database:
a. Dùng: mysqladmin create Tên_CSDL
b. Đăng nhập vào mysql: mysql -u root (hoặc user khác có quyền tạo database) -p --> enter, sau đó nhập mật khẩu.
mysql>create database tasks;
Query OK, 1 row affected (0.00 sec)
2. Sửa mật khẩu user: xem trang này đầy đủ hơn.
===================================================================
Tham khảo:
Tuy nhiên, ngoài những bước kiểm tra như trong các trang cài đặt, chúng ta cần kiểm tra thêm một vài thứ như sau:
Rõ ràng, nếu chúng ta đã cài đặt XAMPP thì không cần thiết phải cài đặt riêng từng gói như PHP, MySQL hay Apache... Vì thế, từ bất kỳ vị trí nào ngoài /opt/lampp/bin, chúng ta gõ mysql -u root -p (sau đó yêu cầu password) thì có nghĩa là trên máy bạn đã có mysql.
Có vấn đề tôi gặp phải là:
- Tôi cài và dùng MySQL Query Browser và MySQL Administrator, mỗi khi khởi đội một trong hai chương trình này đều yêu cầu cung cấp Username và Password.
- Cấu hình phpmyadmin: mỗi lần đăng nhập hay hỏi mật khẩu. Lỗi cũng giống như trường hợp 3.
- Chạy mysql từ console, không cho root đăng nhập. Lỗi: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Các tình huống lỗi hay gặp:
Lỗi 01:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
Xem cách giải quyết tình huống 1
Lỗi 02:
honey@honey:~$ mysqladmin create test
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘honey’@'localhost’ (using password: NO)’
Giải quyết tình huống 1:
Lỗi 01:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
Xem cách giải quyết tình huống 1
Lỗi 02:
honey@honey:~$ mysqladmin create test
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘honey’@'localhost’ (using password: NO)’
Xem cách giải quyết tình huống 2,3
Giải quyết tình huống 1:
Hay báo lỗi là không khởi động được file mysqld.sock. Thế thì:
- Tạo thư mục mysqld: sudo mkdir /var/run/mysqld
- Chuyển đến thư mục trên: cd /var/run/mysqld
- Tạo một shortcut: sudo ln -s /opt/lampp/var/mysql/mysql.sock mysqld.sock
Giải quyết tình huống 2:
Cứ theo hướng dẫn và chỉnh sửa như sau:
This is What I did, assuming mysql server is already running
and setup ok.
edited the file /etc/my.cnf
at the [mysqld] section
added this line:
skip-grant-tables
and restarted the server ....
That worked great!!!
Nếu đã giải quyết tình huống 2 xong thì 3 ok. Hướng dẫn đầy đủ nhất xem trên trang này.
+================================================================+
SAU ĐÂY LÀ CÁC LỆNH ĐẦU TIÊN DÙNG TRÊN MYSQL
1. Tạo database:
a. Dùng: mysqladmin create Tên_CSDL
b. Đăng nhập vào mysql: mysql -u root (hoặc user khác có quyền tạo database) -p --> enter, sau đó nhập mật khẩu.
mysql>create database tasks;
Query OK, 1 row affected (0.00 sec)
2. Sửa mật khẩu user: xem trang này đầy đủ hơn.
===================================================================
Tham khảo:
Install MySQL Server 5 on Ubuntu :: the How-To Geek
http://webdevcodex.com/tutorial-installing-apache2-php5-mysql5-phpmyadmin3-windows-7-vista/#configapache
http://webdevcodex.com/tutorial-installing-apache2-php5-mysql5-phpmyadmin3-windows-7-vista/#configapache
Shared via AddThis
Friday, September 25, 2009
Thursday, September 24, 2009
References to do report
Graph Editor - a brief discussion about node, edge, selection and move tools.
Tutorials - Raw J3D - discusses on the principal 3D graphics in Java
Tutorials - Raw J3D - discusses on the principal 3D graphics in Java
Interaction with Mouse in OpenGL (Part 2)
In fact, transformations are relative to the object. You need to keep track of your transforms and move things as appropriate for the current state of the model view matrix. Everything is relative, so it doesn't really make sense to talk about absolute position in this way. You can try glPushMatrix(), glLoadIdentity(), glTranslatef(0.1f0, 0.2f0, 0.0f0), draw-gl-scene, and glPopMatrix(), which may or may not be what you actually want to do.
Moving selected objects in OpenGL
What you need to do is check whenever the mouse is moved AND if the player is holding the button you use to move objects. You also need to check if the user has already clicked on an object to move and is then holding the mouse to move it.
Here's the steps:
1. User mouse clicks down on object
2. Call function with mouse down
3. User keeps mouse held down and moves mouse
4. Call function with mouse motion
5. User stops holding mouse down
6. Call function with mouse up
void reshape(int w, int h) {
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( h==0 )
gluPerspective(45, (GLdouble)w, 1.0, 2000.0);
else
gluPerspective(45, (GLdouble)w/ (GLdouble)h, 1.0, 2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse ( int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
moving = 1;
startx = x;
starty = y;
}
if ( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
moving = 0;
if ( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN )
{
moving = 2;
starty = y;
}
if ( button == GLUT_RIGHT_BUTTON && state == GLUT_UP )
moving = 0;
}
void motion ( int x, int y )
{
if ( moving == 1 )
{
angle = angle + ( x - startx );
angle2 = angle2 + ( y - starty );
startx = x;
starty = y;
glutPostRedisplay ( );
}
if ( moving == 2 )
{
zoom = zoom + ( y - starty );
starty = y;
glutPostRedisplay ( );
}
}
And make sure you call
glutMouseFunc ( mouse );
glutMotionFunc ( motion );
after init() in your main loop
And needed global variables
float angle, angle2, cloud_rot;
float zoom = -25.50;
int moving, startx, starty;
See more here
Drag Mouse to move Objects
According to the docs, the mouse state has to be checkd like this:
Uint8 ms;
ms = SDL_GetMouseState(&x, &y);
if(ms & SDL_BUTTON(SDL_BUTTON_LEFT))
{
MouseButtonUp(x,y,LEFT);
}
else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT))
{
MouseButtonUp(x,y,RIGHT);
}
else if (ms & SDL_BUTTON(SDL_BUTTON_MIDDLE))
{
MouseButtonUp(x,y,MIDDLE);
}
// my mouse event code cut from my game engine.
// All the game events go thru here
while ( SDL_PollEvent(&event) )
{
// Send Keyboard events to the keyboard handler
done = HandleKeys(event);
// Mouse events
int x,y;
switch (event.type)
{
// A button on the mouse was pressed
case SDL_MOUSEBUTTONDOWN:
switch(SDL_GetMouseState(&x,&y))
{
case SDL_BUTTON(SDL_BUTTON_LEFT):
MouseButtonDown(x, y, LEFT);
break;
case SDL_BUTTON(SDL_BUTTON_RIGHT):
MouseButtonDown(x, y, RIGHT);
break;
case SDL_BUTTON(SDL_BUTTON_MIDDLE):
MouseButtonDown(x, y, MIDDLE);
break;
default:
break;
}
break;
// It was realeased
case SDL_MOUSEBUTTONUP:
switch(SDL_GetMouseState(&x, &y))
{
case SDL_BUTTON(SDL_BUTTON_LEFT):
MouseButtonUp(x, y, LEFT);
break;
case SDL_BUTTON(SDL_BUTTON_RIGHT):
MouseButtonUp(x, y, RIGHT);
break;
case SDL_BUTTON(SDL_BUTTON_MIDDLE):
MouseButtonUp(x, y, MIDDLE);
break;
default:
break;
}
break;
// Mouse is on the move.
case SDL_MOUSEMOTION:
SDL_GetMouseState(&x, &y);
MouseMove(x, y);
break;
}
http://www.gamedev.net/community/forums/topic.asp?topic_id=400975
Getting mouse button and/or keyboard events
Hi all,
I have a Windows program I am using for an experiment - I am recording people's reaction times in various situations, and to control the duration of the displays people see, I increase the priority of the current process and the current thread using the Windows functions SetPriorityClass(hProcess,
HIGH_PRIORITY_CLASS) and SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST),
respectively. Raising the priority of the current thread locks out other
Windows processes (so they don't affect the timing of my displays), but it also
appears to lock out the keyboard and mouse, so I can't use SDL_PollEvent() to
get mouse button presses or key presses. I'm wondering if there is another
function that will allow me to directly poll the mouse or check for specific key
presses that would not be affected by changing the priority of the thread. I
realize that this might be beyond the scope of the forum, but any information
would be helpful and appreciated. (I also realize that recording reaction times
with a mouse or keyboard event is likely to have some built-in variability; I'm
just trying to minimize that variability as much as possible). Thank you in
advance.
Chris Dickinson
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2008-October/066952.html
Maybe:
Uint8* keystates = SDL_GetKeyState(0);
...
if(keystates[SDLK_SPACE])
{
// do stuff
}
and... (from docs)
SDL_PumpEvents();
if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
printf("Mouse Button 1(left) is pressed.\n");
Jonny D
basically, if you're just wanting a ray in the direction of the mouse click, then its pretty simple using gluUnProject.
below is a simple usage to get the ray
GLdouble ray_x, ray_y, ray_z;
GLint viewport[4];
GLdouble proj[16];
GLdouble modelview[16];
// we query OpenGL for the necessary matrices etc.
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
// assuming you have mouse coordinates as mouseX and mouseY
// gluUnproject assumes coordinates are measured from bottom of screen
// so we invert the mouseY you got from glut or SDL or watever
GLdouble _mouseY = viewport[3] - mouseY;
// using 1.0 for winZ gives u a ray
gluUnProject(mouseX, _mouseY, 1.0f, modelview, proj, viewport, &ray_x, &ray_y, &ray_z);
and there you have the ray direction coords... it isn't normalized tho fyi.
i think you can actually get the z coordinate of the object you clicked.. but i haven't needed that yet... then you'd pass in something else as winZ, getting it from the Z-buffer... but not too sure.
hope that helped.
----------------
If you just want the 3d coordinates of the point in space the mouse is over, the following code will give you just that:
GLdouble model_view[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);
GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
double dx; double dy; double dz;
GLfloat depth[2];
glReadPixels (x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
gluUnProject(x, y, depth[0], model_view, projection, viewport, &dx, &dy, &dz);
x3d = float(dx);
y3d = float(dy);
z3d = float(dz);
Zoom in and out a large surface
There are 2 common ways to zoom in 3D:
The correct way to zoom is to modify the projection matrix. If you are using an orthographic projection, just scale the width and height arguments to glOrtho. If you are using a perspective projection, try modifying the field of view (narrow field of view is more zoomed).
glTranslate is not a very good way to zoom. You are basically moving the object closer of further away from the camera, which will sort of work in perspective projection, but eventually you will translate past the a clipping plane.
I was recently doing this by changing glViewPort function and increasing the number (from both sides)
See more here
Moving selected objects in OpenGL
What you need to do is check whenever the mouse is moved AND if the player is holding the button you use to move objects. You also need to check if the user has already clicked on an object to move and is then holding the mouse to move it.
Here's the steps:
1. User mouse clicks down on object
2. Call function with mouse down
3. User keeps mouse held down and moves mouse
4. Call function with mouse motion
5. User stops holding mouse down
6. Call function with mouse up
void reshape(int w, int h) {
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if ( h==0 )
gluPerspective(45, (GLdouble)w, 1.0, 2000.0);
else
gluPerspective(45, (GLdouble)w/ (GLdouble)h, 1.0, 2000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse ( int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
moving = 1;
startx = x;
starty = y;
}
if ( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
moving = 0;
if ( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN )
{
moving = 2;
starty = y;
}
if ( button == GLUT_RIGHT_BUTTON && state == GLUT_UP )
moving = 0;
}
void motion ( int x, int y )
{
if ( moving == 1 )
{
angle = angle + ( x - startx );
angle2 = angle2 + ( y - starty );
startx = x;
starty = y;
glutPostRedisplay ( );
}
if ( moving == 2 )
{
zoom = zoom + ( y - starty );
starty = y;
glutPostRedisplay ( );
}
}
And make sure you call
glutMouseFunc ( mouse );
glutMotionFunc ( motion );
after init() in your main loop
And needed global variables
float angle, angle2, cloud_rot;
float zoom = -25.50;
int moving, startx, starty;
See more here
Drag Mouse to move Objects
According to the docs, the mouse state has to be checkd like this:
Uint8 ms;
ms = SDL_GetMouseState(&x, &y);
if(ms & SDL_BUTTON(SDL_BUTTON_LEFT))
{
MouseButtonUp(x,y,LEFT);
}
else if (ms & SDL_BUTTON(SDL_BUTTON_RIGHT))
{
MouseButtonUp(x,y,RIGHT);
}
else if (ms & SDL_BUTTON(SDL_BUTTON_MIDDLE))
{
MouseButtonUp(x,y,MIDDLE);
}
// my mouse event code cut from my game engine.
// All the game events go thru here
while ( SDL_PollEvent(&event) )
{
// Send Keyboard events to the keyboard handler
done = HandleKeys(event);
// Mouse events
int x,y;
switch (event.type)
{
// A button on the mouse was pressed
case SDL_MOUSEBUTTONDOWN:
switch(SDL_GetMouseState(&x,&y))
{
case SDL_BUTTON(SDL_BUTTON_LEFT):
MouseButtonDown(x, y, LEFT);
break;
case SDL_BUTTON(SDL_BUTTON_RIGHT):
MouseButtonDown(x, y, RIGHT);
break;
case SDL_BUTTON(SDL_BUTTON_MIDDLE):
MouseButtonDown(x, y, MIDDLE);
break;
default:
break;
}
break;
// It was realeased
case SDL_MOUSEBUTTONUP:
switch(SDL_GetMouseState(&x, &y))
{
case SDL_BUTTON(SDL_BUTTON_LEFT):
MouseButtonUp(x, y, LEFT);
break;
case SDL_BUTTON(SDL_BUTTON_RIGHT):
MouseButtonUp(x, y, RIGHT);
break;
case SDL_BUTTON(SDL_BUTTON_MIDDLE):
MouseButtonUp(x, y, MIDDLE);
break;
default:
break;
}
break;
// Mouse is on the move.
case SDL_MOUSEMOTION:
SDL_GetMouseState(&x, &y);
MouseMove(x, y);
break;
}
http://www.gamedev.net/community/forums/topic.asp?topic_id=400975
Getting mouse button and/or keyboard events
Hi all,
I have a Windows program I am using for an experiment - I am recording people's reaction times in various situations, and to control the duration of the displays people see, I increase the priority of the current process and the current thread using the Windows functions SetPriorityClass(hProcess,
HIGH_PRIORITY_CLASS) and SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST),
respectively. Raising the priority of the current thread locks out other
Windows processes (so they don't affect the timing of my displays), but it also
appears to lock out the keyboard and mouse, so I can't use SDL_PollEvent() to
get mouse button presses or key presses. I'm wondering if there is another
function that will allow me to directly poll the mouse or check for specific key
presses that would not be affected by changing the priority of the thread. I
realize that this might be beyond the scope of the forum, but any information
would be helpful and appreciated. (I also realize that recording reaction times
with a mouse or keyboard event is likely to have some built-in variability; I'm
just trying to minimize that variability as much as possible). Thank you in
advance.
Chris Dickinson
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2008-October/066952.html
Maybe:
Uint8* keystates = SDL_GetKeyState(0);
...
if(keystates[SDLK_SPACE])
{
// do stuff
}
and... (from docs)
SDL_PumpEvents();
if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))
printf("Mouse Button 1(left) is pressed.\n");
Jonny D
basically, if you're just wanting a ray in the direction of the mouse click, then its pretty simple using gluUnProject.
below is a simple usage to get the ray
GLdouble ray_x, ray_y, ray_z;
GLint viewport[4];
GLdouble proj[16];
GLdouble modelview[16];
// we query OpenGL for the necessary matrices etc.
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
// assuming you have mouse coordinates as mouseX and mouseY
// gluUnproject assumes coordinates are measured from bottom of screen
// so we invert the mouseY you got from glut or SDL or watever
GLdouble _mouseY = viewport[3] - mouseY;
// using 1.0 for winZ gives u a ray
gluUnProject(mouseX, _mouseY, 1.0f, modelview, proj, viewport, &ray_x, &ray_y, &ray_z);
and there you have the ray direction coords... it isn't normalized tho fyi.
i think you can actually get the z coordinate of the object you clicked.. but i haven't needed that yet... then you'd pass in something else as winZ, getting it from the Z-buffer... but not too sure.
hope that helped.
----------------
If you just want the 3d coordinates of the point in space the mouse is over, the following code will give you just that:
GLdouble model_view[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);
GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
double dx; double dy; double dz;
GLfloat depth[2];
glReadPixels (x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
gluUnProject(x, y, depth[0], model_view, projection, viewport, &dx, &dy, &dz);
x3d = float(dx);
y3d = float(dy);
z3d = float(dz);
Zoom in and out a large surface
There are 2 common ways to zoom in 3D:
- by scaling
- by manipulating the projection matrix
The correct way to zoom is to modify the projection matrix. If you are using an orthographic projection, just scale the width and height arguments to glOrtho. If you are using a perspective projection, try modifying the field of view (narrow field of view is more zoomed).
glTranslate is not a very good way to zoom. You are basically moving the object closer of further away from the camera, which will sort of work in perspective projection, but eventually you will translate past the a clipping plane.
I was recently doing this by changing glViewPort function and increasing the number (from both sides)
See more here
Labels:
Drag Mouse,
Interaction,
move objectsobjects,
OpenGL
Friday, September 11, 2009
Some notes working with Common Lisp
1. When using multiple-value-bind, there are some values that we don't need. We can ignore the warning "The variable x, y,... is never used...". Below is an example:
(defun my-round (x)
(round (+ x 0.5)))
(defun next-power-of-two (x)
(let ((log-base2 (/ (log x) (log 2))))
(multiple-value-bind (y z)
(my-round (expt 2 (ceiling log-base2)))
(declare (ignorable z))
y)))
Because the my-round functions returns two values, but I only use the first one. When I apply this function inside the next-power-of-two function, I also need the first.
2. In order to use the hexadecimal values in Common Lisp, we can use "#x" or "x16r" to represent them.
(defun my-round (x)
(round (+ x 0.5)))
(defun next-power-of-two (x)
(let ((log-base2 (/ (log x) (log 2))))
(multiple-value-bind (y z)
(my-round (expt 2 (ceiling log-base2)))
(declare (ignorable z))
y)))
Because the my-round functions returns two values, but I only use the first one. When I apply this function inside the next-power-of-two function, I also need the first.
2. In order to use the hexadecimal values in Common Lisp, we can use "#x" or "x16r" to represent them.
Subscribe to:
Posts (Atom)